From 5f8dac68690e92f0be220f8f8d9f797a2aedc806 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 1 Mar 2018 11:18:33 +0000 Subject: Remove fake signal-handling code Microsoft Windows has only limited support for signals. busybox-w32 initially papered over this fact by adding definitions for unsupported signals and signal-handling functions. Remove this fake code and deal with the consequences by excluding anything that fails to compile as a result. --- archival/tar.c | 2 ++ coreutils/tee.c | 2 ++ include/libbb.h | 18 ++++++++++++++++++ include/mingw.h | 28 ---------------------------- libbb/Kbuild.src | 2 +- networking/nc.c | 4 ++++ procps/kill.c | 2 ++ shell/ash.c | 13 ++++++++++--- 8 files changed, 39 insertions(+), 32 deletions(-) diff --git a/archival/tar.c b/archival/tar.c index 990755429..fbe5e3be8 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -1117,7 +1117,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_2COMMAND) { putenv((char*)"TAR_FILETYPE=f"); +#ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); +#endif tar_handle->action_data = data_extract_to_command; IF_FEATURE_TAR_TO_COMMAND(tar_handle->tar__to_command_shell = xstrdup(get_shell_name());) } diff --git a/coreutils/tee.c b/coreutils/tee.c index f0ec791bb..d0ded58c4 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c @@ -69,9 +69,11 @@ int tee_main(int argc, char **argv) signal(SIGINT, SIG_IGN); /* TODO - switch to sigaction. (why?) */ } retval = EXIT_SUCCESS; +#ifdef SIGPIPE /* gnu tee ignores SIGPIPE in case one of the output files is a pipe * that doesn't consume all its input. Good idea... */ signal(SIGPIPE, SIG_IGN); +#endif /* Allocate an array of FILE *'s, with one extra for a sentinel. */ fp = files = xzalloc(sizeof(FILE *) * (argc + 2)); diff --git a/include/libbb.h b/include/libbb.h index 761370111..4a59ee7d8 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -526,18 +526,36 @@ enum { * Dance around with long long to guard against that... */ BB_FATAL_SIGS = (int)(0 +#ifdef SIGHUP + (1LL << SIGHUP) +#endif + (1LL << SIGINT) + (1LL << SIGTERM) +#ifdef SIGPIPE + (1LL << SIGPIPE) // Write to pipe with no readers +#endif +#ifdef SIGQUIT + (1LL << SIGQUIT) // Quit from keyboard +#endif + (1LL << SIGABRT) // Abort signal from abort(3) +#ifdef SIGALRM + (1LL << SIGALRM) // Timer signal from alarm(2) +#endif +#ifdef SIGVTALRM + (1LL << SIGVTALRM) // Virtual alarm clock +#endif +#ifdef SIGXCPU + (1LL << SIGXCPU) // CPU time limit exceeded +#endif +#ifdef SIGXFSZ + (1LL << SIGXFSZ) // File size limit exceeded +#endif +#ifdef SIGUSR1 + (1LL << SIGUSR1) // Yes kids, these are also fatal! +#endif +#ifdef SIGUSR1 + (1LL << SIGUSR2) +#endif + 0), }; #if !ENABLE_PLATFORM_MINGW32 diff --git a/include/mingw.h b/include/mingw.h index c662f4baf..1bb2032cd 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -90,39 +90,11 @@ IMPL(getpwent,struct passwd *,NULL,void) /* * signal.h */ -#define SIGHUP 1 -#define SIGQUIT 3 #define SIGKILL 9 -#define SIGUSR1 10 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGWINCH 28 #define SIG_UNBLOCK 1 -typedef void (__cdecl *sighandler_t)(int); -struct sigaction { - sighandler_t sa_handler; - unsigned sa_flags; - int sa_mask; -}; -#define sigemptyset(x) (void)0 -#define SA_RESTART 0 - -NOIMPL(sigaction,int sig UNUSED_PARAM, struct sigaction *in UNUSED_PARAM, struct sigaction *out UNUSED_PARAM); -NOIMPL(sigfillset,int *mask UNUSED_PARAM); NOIMPL(FAST_FUNC sigprocmask_allsigs, int how UNUSED_PARAM); -NOIMPL(FAST_FUNC sigaction_set,int signo UNUSED_PARAM, const struct sigaction *sa UNUSED_PARAM); /* * stdio.h diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index c0cc2baf5..4b838ab7a 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src @@ -12,7 +12,6 @@ INSERT lib-y += appletlib.o lib-y += ask_confirmation.o -lib-y += bb_askpass.o lib-y += bb_bswap_64.o lib-y += bb_do_delay.o lib-y += bb_pwd.o @@ -105,6 +104,7 @@ lib-y += xgetcwd.o lib-y += xreadlink.o lib-y += xrealloc_vector.o +lib-$(CONFIG_PLATFORM_POSIX) += bb_askpass.o lib-$(CONFIG_PLATFORM_POSIX) += get_console.o lib-$(CONFIG_PLATFORM_POSIX) += getpty.o lib-$(CONFIG_PLATFORM_POSIX) += inet_common.o diff --git a/networking/nc.c b/networking/nc.c index de02ccc9d..3e122b787 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -110,10 +110,12 @@ * when compared to "standard" nc */ +#if ENABLE_NC_EXTRA static void timeout(int signum UNUSED_PARAM) { bb_error_msg_and_die("timed out"); } +#endif int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int nc_main(int argc, char **argv) @@ -187,10 +189,12 @@ int nc_main(int argc, char **argv) argv++; } +#if ENABLE_NC_EXTRA if (wsecs) { signal(SIGALRM, timeout); alarm(wsecs); } +#endif if (!cfd) { if (do_listen) { diff --git a/procps/kill.c b/procps/kill.c index c95afb8b3..4477dedb7 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -207,6 +207,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv) do_it_now: pid = getpid(); +#if ENABLE_KILLALL5 if (is_killall5) { pid_t sid; procps_status_t* p = NULL; @@ -264,6 +265,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv) kill(-1, SIGCONT); return errors; } +#endif #if ENABLE_KILL || ENABLE_KILLALL /* Pid or name is required for kill/killall */ diff --git a/shell/ash.c b/shell/ash.c index fa71bd84d..88834f49a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -3747,6 +3747,7 @@ static smallint doing_jobctl; //references:8 static void setjobctl(int); #endif +#if !ENABLE_PLATFORM_MINGW32 /* * Ignore a signal. */ @@ -3761,7 +3762,6 @@ ignoresig(int signo) sigmode[signo - 1] = S_HARD_IGN; } -#if !ENABLE_PLATFORM_MINGW32 /* * Only one usage site - in setsignal() */ @@ -3896,6 +3896,7 @@ setsignal(int signo) } #else #define setsignal(s) +#define ignoresig(s) #endif /* mode flags for set_curjob */ @@ -4372,7 +4373,11 @@ sprint_status48(char *s, int status, int sigonly) #endif st = WTERMSIG(status); if (sigonly) { +#ifdef SIGPIPE if (st == SIGINT || st == SIGPIPE) +#else + if (st == SIGINT) +#endif goto out; #if JOBS if (WIFSTOPPED(status)) @@ -10633,7 +10638,7 @@ evalcommand(union node *cmd, int flags) * we can just exec it. */ #if ENABLE_PLATFORM_MINGW32 - if (!(flags & EV_EXIT) || trap[0]) { + if (!(flags & EV_EXIT) || may_have_traps) { /* No, forking off a child is necessary */ struct forkshell fs; @@ -14394,6 +14399,7 @@ init(void) basepf.next_to_pgetc = basepf.buf = ckmalloc(IBUFSIZ); basepf.linno = 1; +#if !ENABLE_PLATFORM_MINGW32 sigmode[SIGCHLD - 1] = S_DFL; /* ensure we install handler even if it is SIG_IGNed */ setsignal(SIGCHLD); @@ -14401,6 +14407,7 @@ init(void) * Try: "trap '' HUP; bash; echo RET" and type "kill -HUP $$" */ signal(SIGHUP, SIG_DFL); +#endif { char **envp; @@ -14838,7 +14845,7 @@ forkshell_openhere(struct forkshell *fs) ignoresig(SIGQUIT); //signal(SIGQUIT, SIG_IGN); ignoresig(SIGHUP); //signal(SIGHUP, SIG_IGN); ignoresig(SIGTSTP); //signal(SIGTSTP, SIG_IGN); - signal(SIGPIPE, SIG_DFL); + //signal(SIGPIPE, SIG_DFL); if (redir->type == NHERE) { size_t len = strlen(redir->nhere.doc->narg.text); full_write(pip[1], redir->nhere.doc->narg.text, len); -- cgit v1.2.3-55-g6feb