From: Pádraig Brady Date: Fri, 8 Jul 2011 13:49:05 +0000 (+0100) Subject: timeout: handle signals more transparently X-Git-Tag: v8.13~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=v8.12-117-g5a647a0;p=thirdparty%2Fcoreutils.git timeout: handle signals more transparently * m4/jm-macros.m4: Define HAVE_SETRLIMIT. * src/timeout.c: If the child exited with a signal, raise that signal to the timeout process itself, so that callers may also see the signal status. Use setrlimit to disable core dumps for the timeout process, which would be generated by some signals. --- diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4 index ec553105fb..9bb6fa4256 100644 --- a/m4/jm-macros.m4 +++ b/m4/jm-macros.m4 @@ -65,6 +65,8 @@ AC_DEFUN([coreutils_MACROS], # Used by sort.c. AC_CHECK_FUNCS_ONCE([nl_langinfo]) + # Used by timeout.c + AC_CHECK_FUNCS_ONCE([setrlimit]) # Used by tail.c. AC_CHECK_FUNCS([inotify_init], diff --git a/src/timeout.c b/src/timeout.c index ab54ed675d..ef660a717a 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -58,6 +58,12 @@ #include "error.h" #include "quote.h" +#if HAVE_SETRLIMIT +/* FreeBSD 5.0 at least needs and included + before . Currently "system.h" includes . */ +# include +#endif + #define PROGRAM_NAME "timeout" #define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady") @@ -370,7 +376,23 @@ main (int argc, char **argv) if (WIFEXITED (status)) status = WEXITSTATUS (status); else if (WIFSIGNALED (status)) - status = WTERMSIG (status) + 128; /* what sh does at least. */ + { + int sig = WTERMSIG (status); +#if HAVE_SETRLIMIT && defined RLIMIT_CORE + if (!timed_out) + { + /* exit with the signal flag set, but avoid core files. */ + if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0,0}) == 0) + { + signal (sig, SIG_DFL); + raise (sig); + } + else + error (0, errno, _("warning: disabling core dumps failed")); + } +#endif + status = sig + 128; /* what sh returns for signaled processes. */ + } else { /* shouldn't happen. */