Skip to content

Commit 67c6c82

Browse files
committed
WIP
1 parent aaf37b8 commit 67c6c82

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

src/os/signal/signal.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ func Notify(c chan<- os.Signal, sig ...os.Signal) {
168168
}
169169
}
170170

171-
// Reset undoes the effect of any prior calls to [Notify] for the provided
172-
// signals.
171+
// Reset undoes the effect of any prior calls to [Notify] or [Ignore] for the
172+
// provided signals.
173173
// If no signals are provided, all signal handlers will be reset.
174174
func Reset(sig ...os.Signal) {
175175
cancel(sig, disableSignal)

src/os/signal/signal_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ func TestStop(t *testing.T) {
347347
for _, sig := range sigs {
348348
sig := sig
349349
t.Run(fmt.Sprint(sig), func(t *testing.T) {
350+
defer Reset(sig)
351+
350352
// When calling Notify with a specific signal,
351353
// independent signals should not interfere with each other,
352354
// and we end up needing to wait for signals to quiesce a lot.

src/runtime/os3_plan9.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ Exit:
149149
func sigenable(sig uint32) {
150150
}
151151

152-
func sigdisable(sig uint32) {
152+
func sigdisable(sig uint32) bool {
153+
return false
153154
}
154155

155156
func sigignore(sig uint32) {

src/runtime/os_wasm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func getfp() uintptr { return 0 }
142142

143143
func setProcessCPUProfiler(hz int32) {}
144144
func setThreadCPUProfiler(hz int32) {}
145-
func sigdisable(uint32) {}
145+
func sigdisable(uint32) bool { return false }
146146
func sigenable(uint32) {}
147147
func sigignore(uint32) {}
148148

src/runtime/signal_unix.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,14 @@ func sigenable(sig uint32) {
211211
// sigdisable disables the Go signal handler for the signal sig.
212212
// It is only called while holding the os/signal.handlers lock,
213213
// via os/signal.disableSignal and signal_disable.
214-
func sigdisable(sig uint32) {
214+
func sigdisable(sig uint32) bool {
215215
if sig >= uint32(len(sigtable)) {
216-
return
216+
return false
217217
}
218218

219219
// SIGPROF is handled specially for profiling.
220220
if sig == _SIGPROF {
221-
return
221+
return false
222222
}
223223

224224
t := &sigtable[sig]
@@ -230,11 +230,20 @@ func sigdisable(sig uint32) {
230230
// If initsig does not install a signal handler for a
231231
// signal, then to go back to the state before Notify
232232
// we should remove the one we installed.
233-
if !sigInstallGoHandler(sig) {
233+
if sigInstallGoHandler(sig) {
234+
if atomic.Cas(&handlingSig[sig], 0, 1) {
235+
atomic.Storeuintptr(&fwdSig[sig], getsig(sig))
236+
setsig(sig, abi.FuncPCABIInternal(sighandler))
237+
}
238+
return false
239+
} else {
234240
atomic.Store(&handlingSig[sig], 0)
235-
setsig(sig, atomic.Loaduintptr(&fwdSig[sig]))
241+
fs := atomic.Loaduintptr(&fwdSig[sig])
242+
setsig(sig, fs)
243+
return fs == _SIG_IGN
236244
}
237245
}
246+
return false
238247
}
239248

240249
// sigignore ignores the signal sig.

src/runtime/signal_windows.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ func initsig(preinit bool) {
434434
func sigenable(sig uint32) {
435435
}
436436

437-
func sigdisable(sig uint32) {
437+
func sigdisable(sig uint32) bool {
438+
return false
438439
}
439440

440441
func sigignore(sig uint32) {

src/runtime/sigqueue.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,19 @@ func signal_disable(s uint32) {
230230
if s >= uint32(len(sig.wanted)*32) {
231231
return
232232
}
233-
sigdisable(s)
233+
ignored := sigdisable(s)
234234

235235
w := sig.wanted[s/32]
236236
w &^= 1 << (s & 31)
237237
atomic.Store(&sig.wanted[s/32], w)
238+
239+
i := sig.ignored[s/32]
240+
if ignored {
241+
i |= 1 << (s & 31)
242+
} else {
243+
i &^= 1 << (s & 31)
244+
}
245+
atomic.Store(&sig.ignored[s/32], i)
238246
}
239247

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

0 commit comments

Comments
 (0)