Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Feb 14, 2025
1 parent 6eaaa73 commit 453c2ae
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/os/signal/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func Notify(c chan<- os.Signal, sig ...os.Signal) {
}
}

// Reset undoes the effect of any prior calls to [Notify] for the provided
// signals.
// Reset undoes the effect of any prior calls to [Notify] or [Ignore] for the
// provided signals.
// If no signals are provided, all signal handlers will be reset.
func Reset(sig ...os.Signal) {
cancel(sig, disableSignal)
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/os3_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ Exit:
func sigenable(sig uint32) {
}

func sigdisable(sig uint32) {
func sigdisable(sig uint32) bool {
return false
}

func sigignore(sig uint32) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/os_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func getfp() uintptr { return 0 }

func setProcessCPUProfiler(hz int32) {}
func setThreadCPUProfiler(hz int32) {}
func sigdisable(uint32) {}
func sigdisable(uint32) bool { return false }
func sigenable(uint32) {}
func sigignore(uint32) {}

Expand Down
27 changes: 21 additions & 6 deletions src/runtime/signal_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ func sigenable(sig uint32) {
enableSigChan <- sig
<-maskUpdatedChan
if atomic.Cas(&handlingSig[sig], 0, 1) {
atomic.Storeuintptr(&fwdSig[sig], getsig(sig))
h := getsig(sig)
if h != _SIG_IGN {
atomic.Storeuintptr(&fwdSig[sig], h)
}
setsig(sig, abi.FuncPCABIInternal(sighandler))
}
}
Expand All @@ -211,14 +214,14 @@ func sigenable(sig uint32) {
// sigdisable disables the Go signal handler for the signal sig.
// It is only called while holding the os/signal.handlers lock,
// via os/signal.disableSignal and signal_disable.
func sigdisable(sig uint32) {
func sigdisable(sig uint32) bool {
if sig >= uint32(len(sigtable)) {
return
return false
}

// SIGPROF is handled specially for profiling.
if sig == _SIGPROF {
return
return false
}

t := &sigtable[sig]
Expand All @@ -230,11 +233,23 @@ func sigdisable(sig uint32) {
// If initsig does not install a signal handler for a
// signal, then to go back to the state before Notify
// we should remove the one we installed.
if !sigInstallGoHandler(sig) {
if sigInstallGoHandler(sig) {
if atomic.Cas(&handlingSig[sig], 0, 1) {
h := getsig(sig)
if h != _SIG_IGN {
atomic.Storeuintptr(&fwdSig[sig], h)
}
setsig(sig, abi.FuncPCABIInternal(sighandler))
}
return false
} else {
atomic.Store(&handlingSig[sig], 0)
setsig(sig, atomic.Loaduintptr(&fwdSig[sig]))
fs := atomic.Loaduintptr(&fwdSig[sig])
setsig(sig, fs)
return fs == _SIG_IGN
}
}
return false
}

// sigignore ignores the signal sig.
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/signal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ func initsig(preinit bool) {
func sigenable(sig uint32) {
}

func sigdisable(sig uint32) {
func sigdisable(sig uint32) bool {
return false
}

func sigignore(sig uint32) {
Expand Down
10 changes: 9 additions & 1 deletion src/runtime/sigqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,19 @@ func signal_disable(s uint32) {
if s >= uint32(len(sig.wanted)*32) {
return
}
sigdisable(s)
ignored := sigdisable(s)

w := sig.wanted[s/32]
w &^= 1 << (s & 31)
atomic.Store(&sig.wanted[s/32], w)

i := sig.ignored[s/32]
if ignored {
i |= 1 << (s & 31)
} else {
i &^= 1 << (s & 31)
}
atomic.Store(&sig.ignored[s/32], i)
}

// Must only be called from a single goroutine at a time.
Expand Down

0 comments on commit 453c2ae

Please sign in to comment.