Page MenuHomeFreeBSD

D62082.1795753087.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D62082.1795753087.diff

diff --git a/bin/sh/main.c b/bin/sh/main.c
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -99,9 +99,20 @@
volatile int state;
char *shinit;
int login;
+ sigset_t sigs;
(void) setlocale(LC_ALL, "");
initcharset();
+
+ /*
+ * We rely on SIGCHLD to wait for children, so unblock it in case
+ * we were started with it blocked. As in other shells, this also
+ * means that the commands we run never inherit it blocked.
+ */
+ sigemptyset(&sigs);
+ sigaddset(&sigs, SIGCHLD);
+ sigprocmask(SIG_UNBLOCK, &sigs, NULL);
+
state = 0;
if (setjmp(main_handler.loc)) {
if (state == 0 || iflag == 0 || ! rootshell ||
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile
--- a/bin/sh/tests/builtins/Makefile
+++ b/bin/sh/tests/builtins/Makefile
@@ -191,5 +191,6 @@
${PACKAGE}FILES+= wait9.127
${PACKAGE}FILES+= wait10.0
${PACKAGE}FILES+= wait11.0
+${PACKAGE}FILES+= wait12.0
.include <bsd.test.mk>
diff --git a/bin/sh/tests/builtins/wait12.0 b/bin/sh/tests/builtins/wait12.0
new file mode 100644
--- /dev/null
+++ b/bin/sh/tests/builtins/wait12.0
@@ -0,0 +1,5 @@
+# The wait builtin must not hang if the shell was started with SIGCHLD
+# blocked.
+
+env --block-signal=CHLD ${SH} -c '{ sleep 1; exit 42; } & wait $!'
+[ "$?" = 42 ]
diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile
--- a/bin/sh/tests/execution/Makefile
+++ b/bin/sh/tests/execution/Makefile
@@ -63,6 +63,7 @@
${PACKAGE}FILES+= shellproc5.0
${PACKAGE}FILES+= shellproc6.0
${PACKAGE}FILES+= shellproc7.0
+${PACKAGE}FILES+= sigchld1.0
${PACKAGE}FILES+= subshell1.0 subshell1.0.stdout
${PACKAGE}FILES+= subshell2.0
${PACKAGE}FILES+= subshell3.0
diff --git a/bin/sh/tests/execution/sigchld1.0 b/bin/sh/tests/execution/sigchld1.0
new file mode 100644
--- /dev/null
+++ b/bin/sh/tests/execution/sigchld1.0
@@ -0,0 +1,13 @@
+# A shell started with SIGCHLD blocked unblocks it, so that SIGCHLD traps
+# work and the commands it runs do not inherit it blocked.
+
+out=$(env --block-signal=CHLD ${SH} -c '
+ trap "echo trapped" CHLD
+ /usr/bin/true
+ env --list-signal-handling true 2>&1
+ :')
+case $out in
+*CHLD*) exit 1 ;;
+*trapped*) ;;
+*) exit 2 ;;
+esac

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 27, 4:18 AM (19 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42035038
Default Alt Text
D62082.1795753087.diff (2 KB)

Event Timeline