On 08/25/2011 11:35 AM, Pádraig Brady wrote:
I'm committing this revert now...

From d00c73cf4d6402dbacc7cd587127a16a0e93724c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?=<[email protected]>
Date: Thu, 25 Aug 2011 11:25:30 +0100
Subject: [PATCH] timeout: revert signal propagation enhancement

This effectively reverts the unreleased commit 5a647a05

* src/timeout.c (main): Don't propagate signals from the monitored
process, as on Linux /proc/sys/kernel/core_pattern could still
handle them and cause false reports against `timeout`
---
  src/timeout.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/timeout.c b/src/timeout.c
index 6a37508..ae89942 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -424,7 +424,9 @@ main (int argc, char **argv)
            else if (WIFSIGNALED (status))
              {
                int sig = WTERMSIG (status);
-#if HAVE_SETRLIMIT&&  defined RLIMIT_CORE
+/* The following is not used as one cannot disable processing
+   by a filter in /proc/sys/kernel/core_pattern on Linux.  */
+#if 0&&  HAVE_SETRLIMIT&&  defined RLIMIT_CORE
                if (!timed_out)
                  {
                    /* exit with the signal flag set, but avoid core files.  */

I found a more reliable way to disable core dumps,
so another attempt at this is attached.

cheers,
Pádraig.
>From 80df464f17502e8ec06d4473d48fdf0b3bfad71f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Wed, 12 Sep 2012 03:21:11 +0100
Subject: [PATCH] timeout: handle signals more transparently

This was originally attempted in commit v8.12-117-g5a647a0,
but reverted before release because of the unreliability
of disabling core dumps using setrlimit() on Linux kernels.
This new version instead uses prctl() where available to
more reliably disable core dumps for the timeout process.

* m4/jm-macros.m4: Define HAVE_SETRLIMIT and HAVE_PRCTL.
* src/timeout.c (main): 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 or prctl to disable core dumps for the timeout
process, which would be generated by some signals.
Also print a message indicating when the monitored command
dumped core, as that information is lost in the signal
propagation through timeout.
---
 m4/jm-macros.m4 |    2 +-
 src/timeout.c   |   23 +++++++++++++++++------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4
index 016172f..ff89aa3 100644
--- a/m4/jm-macros.m4
+++ b/m4/jm-macros.m4
@@ -64,7 +64,7 @@ AC_DEFUN([coreutils_MACROS],
   # Used by sort.c.
   AC_CHECK_FUNCS_ONCE([nl_langinfo])
   # Used by timeout.c
-  AC_CHECK_FUNCS_ONCE([setrlimit])
+  AC_CHECK_FUNCS_ONCE([setrlimit prctl])
 
   # Used by tail.c.
   AC_CHECK_FUNCS([inotify_init],
diff --git a/src/timeout.c b/src/timeout.c
index c0a2527..317c78f 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -49,6 +49,9 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <signal.h>
+#if HAVE_PRCTL
+# include <sys/prctl.h>
+#endif
 #include <sys/wait.h>
 
 #include "system.h"
@@ -426,21 +429,29 @@ main (int argc, char **argv)
           else if (WIFSIGNALED (status))
             {
               int sig = WTERMSIG (status);
-/* The following is not used as one cannot disable processing
-   by a filter in /proc/sys/kernel/core_pattern on Linux.  */
-#if 0 && HAVE_SETRLIMIT && defined RLIMIT_CORE
+              if (WCOREDUMP (status))
+                error (0, 0, _("command dumped core"));
               if (!timed_out)
                 {
-                  /* exit with the signal flag set, but avoid core files.  */
+                  bool set_signal_flag = true;
+#if HAVE_PRCTL && defined PR_SET_DUMPABLE
+                  if (prctl (PR_SET_DUMPABLE, 0) == 0)
+#elif HAVE_SETRLIMIT && defined RLIMIT_CORE
+                  /* Note this doesn't disable processing by a filter in
+                     /proc/sys/kernel/core_pattern on Linux.  */
                   if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0,0}) == 0)
+#else
+                  set_signal_flag = false;
+                  if (0)
+#endif
                     {
+                      /* exit with the signal flag set.  */
                       signal (sig, SIG_DFL);
                       raise (sig);
                     }
-                  else
+                  else if (set_signal_flag)
                     error (0, errno, _("warning: disabling core dumps 
failed"));
                 }
-#endif
               status = sig + 128; /* what sh returns for signaled processes.  
*/
             }
           else
-- 
1.7.6.4

Reply via email to