@@ -923,8 +923,8 @@ func TestResetIgnore(t *testing.T) {
923
923
}
924
924
925
925
sigs := []syscall.Signal {
926
- syscall .SIGINT ,
927
926
syscall .SIGHUP ,
927
+ syscall .SIGINT ,
928
928
syscall .SIGUSR1 ,
929
929
syscall .SIGTERM ,
930
930
syscall .SIGCHLD ,
@@ -934,6 +934,10 @@ func TestResetIgnore(t *testing.T) {
934
934
for _ , notify := range []bool {false , true } {
935
935
for _ , sig := range sigs {
936
936
t .Run (fmt .Sprintf ("%s[notify=%t]" , sig , notify ), func (t * testing.T ) {
937
+ if Ignored (sig ) {
938
+ t .Fatalf ("expected %q to not be ignored initially" , sig )
939
+ }
940
+
937
941
Ignore (sig )
938
942
if notify {
939
943
c := make (chan os.Signal , 1 )
@@ -948,9 +952,7 @@ func TestResetIgnore(t *testing.T) {
948
952
949
953
// Child processes inherit the ignored status of signals, so verify that it
950
954
// is indeed not ignored.
951
- testenv .MustHaveExec (t )
952
-
953
- cmd := testenv .Command (t , os .Args [0 ], "-test.run=^TestResetIgnore$" )
955
+ cmd := testenv .Command (t , testenv .Executable (t ), "-test.run=^TestResetIgnore$" )
954
956
cmd .Env = append (os .Environ (), "GO_TEST_RESET_IGNORE=" + strconv .Itoa (int (sig )))
955
957
err := cmd .Run ()
956
958
if _ , ok := err .(* exec.ExitError ); ok {
@@ -969,3 +971,54 @@ func resetIgnoreTestProgram(t *testing.T, sig os.Signal) {
969
971
}
970
972
os .Exit (0 )
971
973
}
974
+
975
+ // #46321 test Reset correctly undoes the effect of Ignore when the child
976
+ // process is started with a signal ignored.
977
+ func TestInitiallyIgnoredResetIgnore (t * testing.T ) {
978
+ testenv .MustHaveExec (t )
979
+
980
+ if os .Getenv ("GO_TEST_INITIALLY_IGNORED_RESET_IGNORE" ) != "" {
981
+ s , err := strconv .Atoi (os .Getenv ("GO_TEST_INITIALLY_IGNORED_RESET_IGNORE" ))
982
+ if err != nil {
983
+ t .Fatalf ("failed to parse signal: %v" , err )
984
+ }
985
+ initiallyIgnoredResetIgnoreTestProgram (t , syscall .Signal (s ))
986
+ }
987
+
988
+ sigs := []syscall.Signal {
989
+ syscall .SIGINT ,
990
+ syscall .SIGHUP ,
991
+ }
992
+
993
+ for _ , sig := range sigs {
994
+ t .Run (fmt .Sprint (sig ), func (t * testing.T ) {
995
+ Ignore (sig )
996
+ defer Reset (sig )
997
+
998
+ cmd := testenv .Command (t , testenv .Executable (t ), "-test.run=^TestInitiallyIgnoredResetIgnore$" )
999
+ cmd .Env = append (os .Environ (), "GO_TEST_INITIALLY_IGNORED_RESET_IGNORE=" + strconv .Itoa (int (sig )))
1000
+ err := cmd .Run ()
1001
+ if _ , ok := err .(* exec.ExitError ); ok {
1002
+ t .Fatalf ("expected %q to be ignored in child process" , sig )
1003
+ } else if err != nil {
1004
+ t .Fatalf ("child process failed to launch: %v" , err )
1005
+ }
1006
+ })
1007
+ }
1008
+ }
1009
+
1010
+ func initiallyIgnoredResetIgnoreTestProgram (t * testing.T , sig os.Signal ) {
1011
+ if ! Ignored (sig ) {
1012
+ os .Exit (1 )
1013
+ }
1014
+ Reset (sig )
1015
+ if ! Ignored (sig ) {
1016
+ os .Exit (1 )
1017
+ }
1018
+ Ignore (sig )
1019
+ Reset (sig )
1020
+ if ! Ignored (sig ) {
1021
+ os .Exit (1 )
1022
+ }
1023
+ os .Exit (0 )
1024
+ }
0 commit comments