]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
tools: Enforce default handling of SIGCHLD 2659/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Jun 2025 21:29:49 +0000 (23:29 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Jun 2025 21:29:49 +0000 (23:29 +0200)
Ignoring SIGCHLD gets passed to child processes. Doing that has
influence on waitpid, namely that zombie processes won't be
created. This means that a status can never be read.

We can't enforce this in library, but libarchive's tools can be
protected against this by enforcing default handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
cat/bsdcat.c
cpio/cpio.c
tar/bsdtar.c
unzip/bsdunzip.c

index 731621fa9b75a6b788a8199671381d056da618b2..40fdd04363e51bee2d0e0a68706a3373f1a26471 100644 (file)
@@ -7,6 +7,9 @@
 
 #include "bsdcat_platform.h"
 
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 #include <stdio.h>
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
@@ -105,6 +108,16 @@ main(int argc, char **argv)
        bsdcat = &bsdcat_storage;
        memset(bsdcat, 0, sizeof(*bsdcat));
 
+#if defined(HAVE_SIGACTION) && defined(SIGCHLD)
+       { /* Do not ignore SIGCHLD. */
+               struct sigaction sa;
+               sa.sa_handler = SIG_DFL;
+               sigemptyset(&sa.sa_mask);
+               sa.sa_flags = 0;
+               sigaction(SIGCHLD, &sa, NULL);
+       }
+#endif
+
        lafe_setprogname(*argv, "bsdcat");
 
        bsdcat->argv = argv;
index 2bf1bfa2985a2c25bd071b6ae55bb340d2228dfb..cd88d416e861d06712348a916f726a917e6c9f95 100644 (file)
@@ -124,13 +124,21 @@ main(int argc, char *argv[])
        cpio->buff_size = sizeof(buff);
 
 
-#if defined(HAVE_SIGACTION) && defined(SIGPIPE)
-       { /* Ignore SIGPIPE signals. */
+#if defined(HAVE_SIGACTION)
+       {
                struct sigaction sa;
                sigemptyset(&sa.sa_mask);
                sa.sa_flags = 0;
+#ifdef SIGPIPE
+               /* Ignore SIGPIPE signals. */
                sa.sa_handler = SIG_IGN;
                sigaction(SIGPIPE, &sa, NULL);
+#endif
+#ifdef SIGCHLD
+               /* Do not ignore SIGCHLD. */
+               sa.sa_handler = SIG_DFL;
+               sigaction(SIGCHLD, &sa, NULL);
+#endif
        }
 #endif
 
index 53ac135f01296fe028e6ca022a50140774763a43..c80c1a1b68896b8573b7031e8b1c35f3cbe98820 100644 (file)
@@ -182,6 +182,11 @@ main(int argc, char **argv)
                /* Ignore SIGPIPE signals. */
                sa.sa_handler = SIG_IGN;
                sigaction(SIGPIPE, &sa, NULL);
+#endif
+#ifdef SIGCHLD
+               /* Do not ignore SIGCHLD. */
+               sa.sa_handler = SIG_DFL;
+               sigaction(SIGCHLD, &sa, NULL);
 #endif
        }
 #endif
index 621afbeb9d6a56d9407dc0e701afc17765693a3f..0559a0ddce8b34466075f766eb6a23f98c481b21 100644 (file)
@@ -29,6 +29,9 @@
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
 #endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 #ifdef HAVE_STDARG_H
 #include <stdarg.h>
 #endif
@@ -1187,6 +1190,16 @@ main(int argc, char *argv[])
        const char *zipfile;
        int nopts;
 
+#if defined(HAVE_SIGACTION) && defined(SIGCHLD)
+       { /* Do not ignore SIGCHLD. */
+               struct sigaction sa;
+               sa.sa_handler = SIG_DFL;
+               sigemptyset(&sa.sa_mask);
+               sa.sa_flags = 0;
+               sigaction(SIGCHLD, &sa, NULL);
+       }
+#endif
+
        lafe_setprogname(*argv, "bsdunzip");
 
 #if HAVE_SETLOCALE