mirror of
https://github.com/golang/go
synced 2024-11-22 16:25:07 -07:00
os/signal: check int type of signal using reflection to fix windows notification
This commit is contained in:
parent
f99f5da18f
commit
3a8a7cac38
@ -8,6 +8,7 @@ package signal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,8 +42,25 @@ func signum(sig os.Signal) int {
|
|||||||
}
|
}
|
||||||
return i
|
return i
|
||||||
default:
|
default:
|
||||||
|
// Use reflection to determine if sig has an underlying integer type.
|
||||||
|
// In some systems like Windows, os.Signal may have implementations
|
||||||
|
// with underlying integer types that are not directly accessible,
|
||||||
|
// as they might be defined in external packages like golang.org/x/sys.
|
||||||
|
// Since we cannot import those platform-specific signal types,
|
||||||
|
// reflection allows us to handle them in a generic way.
|
||||||
|
kind := reflect.TypeOf(sig).Kind()
|
||||||
|
switch kind {
|
||||||
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
// Extract the integer value from sig and validate it.
|
||||||
|
i := int(reflect.ValueOf(sig).Int())
|
||||||
|
if i < 0 || i >= numSig {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
return i
|
||||||
|
default:
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func enableSignal(sig int) {
|
func enableSignal(sig int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user