#include "bsdcat_platform.h"
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
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;
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
pid_t child;
#endif
int exit_status;
- int waitpid_return;
+ pid_t waitpid_return;
int child_stdin, child_stdout;
char *out_buf;
state->waitpid_return
= waitpid(state->child, &state->exit_status, 0);
} while (state->waitpid_return == -1 && errno == EINTR);
-#if defined(_WIN32) && !defined(__CYGWIN__)
- CloseHandle(state->child);
-#endif
state->child = 0;
}
if (state->waitpid_return < 0) {
/* waitpid() failed? This is ugly. */
archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
- "Child process exited badly");
+ "Error closing child process");
return (ARCHIVE_WARN);
}
(void)option;/* UNUSED */
do {
if (GetExitCodeProcess(child, &cs) == 0) {
- CloseHandle(child);
la_dosmaperr(GetLastError());
+ CloseHandle(child);
*status = 0;
return (-1);
}
} while (cs == STILL_ACTIVE);
+ CloseHandle(child);
*status = (int)(cs & 0xff);
return (0);
}
struct archive_write_program_data *data)
{
int ret, status;
+ pid_t pid;
ssize_t bytes_read;
if (data->child == 0)
close(data->child_stdin);
if (data->child_stdout != -1)
close(data->child_stdout);
- while (waitpid(data->child, &status, 0) == -1 && errno == EINTR)
- continue;
-#if defined(_WIN32) && !defined(__CYGWIN__)
- CloseHandle(data->child);
-#endif
+ do {
+ pid = waitpid(data->child, &status, 0);
+ } while (pid == -1 && errno == EINTR);
data->child = 0;
- if (status != 0) {
+ if (pid < 0 || status != 0) {
archive_set_error(f->archive, EIO,
"Error closing program: %s", data->program_name);
ret = ARCHIVE_FATAL;
/* 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
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
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