Skip to content

Commit ffd7d31

Browse files
runtime: unblock special glibc signals on each thread
Glibc uses some special signals for special thread operations. These signals will be used in programs that use cgo and invoke certain glibc functions, such as setgid. In order for this to work, these signals need to not be masked by any thread. Before this change, they were being masked by programs that used os/signal.Notify, because it carefully masks all non-thread-specific signals in all threads so that a dedicated thread will collect and report those signals (see ensureSigM in signal1_unix.go). This change adds the two glibc special signals to the set of signals that are unmasked in each thread. Fixes #12498. Change-Id: I797d71a099a2169c186f024185d44a2e1972d4ad Reviewed-on: https://go-review.googlesource.com/14297 Reviewed-by: David Crawshaw <[email protected]>
1 parent 4ac4085 commit ffd7d31

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

misc/cgo/test/setgid_linux.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,36 @@ package cgotest
1414
import "C"
1515

1616
import (
17+
"os"
18+
"os/signal"
19+
"syscall"
1720
"testing"
1821
"time"
1922
)
2023

21-
func testSetgid(t *testing.T) {
24+
func runTestSetgid() bool {
2225
c := make(chan bool)
2326
go func() {
2427
C.setgid(0)
2528
c <- true
2629
}()
2730
select {
2831
case <-c:
32+
return true
2933
case <-time.After(5 * time.Second):
34+
return false
35+
}
36+
37+
}
38+
39+
func testSetgid(t *testing.T) {
40+
if !runTestSetgid() {
3041
t.Error("setgid hung")
3142
}
43+
44+
// Now try it again after using signal.Notify.
45+
signal.Notify(make(chan os.Signal, 1), syscall.SIGINT)
46+
if !runTestSetgid() {
47+
t.Error("setgid hung after signal.Notify")
48+
}
3249
}

src/runtime/signal_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ var sigtable = [...]sigTabT{
4444
/* 29 */ {_SigNotify, "SIGIO: i/o now possible"},
4545
/* 30 */ {_SigNotify, "SIGPWR: power failure restart"},
4646
/* 31 */ {_SigNotify, "SIGSYS: bad system call"},
47-
/* 32 */ {_SigSetStack, "signal 32"}, /* SIGCANCEL; see issue 6997 */
48-
/* 33 */ {_SigSetStack, "signal 33"}, /* SIGSETXID; see issue 3871, 9400 */
47+
/* 32 */ {_SigSetStack + _SigUnblock, "signal 32"}, /* SIGCANCEL; see issue 6997 */
48+
/* 33 */ {_SigSetStack + _SigUnblock, "signal 33"}, /* SIGSETXID; see issues 3871, 9400, 12498 */
4949
/* 34 */ {_SigNotify, "signal 34"},
5050
/* 35 */ {_SigNotify, "signal 35"},
5151
/* 36 */ {_SigNotify, "signal 36"},

0 commit comments

Comments
 (0)