Package: debianutils
Version: 4.4+b1
Severity: wishlist

Dear Maintainer,

I'm trying to use run-parts to perform some checks via nagios/nrpe.
These scripts exit with 0 (OK), 1 (Warning), 2 (Crititcal). The
run-parts executable itself always exits with 1 (if 1 script fails), so
no matter the exitscode of the checkscripts, nagios shows a warning.

I'd prefer run-parts to return the highest exitcode of the scripts it
ran. Diff below works for me (it it against 4.4 in stable, but source of
4.8 is no different in this regards).

Testing scripts: 

$ ./run-parts -v --exit-on-error /tmp/t/ ; echo $?
run-parts: executing /tmp/t//000_exit0
0
run-parts: executing /tmp/t//001_exit1
1
run-parts: /tmp/t//001_exit1 exited with return code 1
1
$ ./run-parts -v  /tmp/t/ ; echo $?
run-parts: executing /tmp/t//000_exit0
0
run-parts: executing /tmp/t//001_exit1
1
run-parts: /tmp/t//001_exit1 exited with return code 1
run-parts: executing /tmp/t//002_exit2
2
run-parts: /tmp/t//002_exit2 exited with return code 2
2
$ mv /tmp/t/001_exit1 /tmp/t/010_exit1
$ ./run-parts -v --exit-on-error /tmp/t/ ; echo $?
run-parts: executing /tmp/t//000_exit0
0
run-parts: executing /tmp/t//002_exit2
2
run-parts: /tmp/t//002_exit2 exited with return code 2
2
$ ./run-parts -v  /tmp/t/ ; echo $?
run-parts: executing /tmp/t//000_exit0
0
run-parts: executing /tmp/t//002_exit2
2
run-parts: /tmp/t//002_exit2 exited with return code 2
run-parts: executing /tmp/t//010_exit1
1
run-parts: /tmp/t//010_exit1 exited with return code 1
2
$


Diff:

--- run-parts.c.orig    2016-10-10 10:58:21.653739605 +0200
+++ run-parts.c 2016-10-10 11:00:42.575258682 +0200
@@ -331,12 +331,18 @@
 
   if (WIFEXITED(result) && WEXITSTATUS(result)) {
     error("%s exited with return code %d", progname, WEXITSTATUS(result));
-    exitstatus = 1;
+
+    if(WEXITSTATUS(result) > exitstatus) {
+        exitstatus = WEXITSTATUS(result);
+        }
   }
   else if (WIFSIGNALED(result)) {
     error("%s exited because of uncaught signal %d", progname,
          WTERMSIG(result));
-    exitstatus = 1;
+
+    if(exitstatus < 1) {
+        exitstatus = 1;
+    }
   }
 }
 
@@ -456,7 +462,9 @@
       else if (S_ISLNK(st.st_mode)) {
        if (!list_mode) {
          error("run-parts: component %s is a broken symbolic link\n",filename);
-         exitstatus = 1;
+     if(exitstatus < 1) {
+          exitstatus = 1;
+     }
        }
       }
     }
@@ -464,8 +472,10 @@
       if (!list_mode) {
        error("run-parts: component %s is not an executable plain file\n",
               filename);
-       exitstatus = 1;
-      }
+        if(exitstatus < 1) {
+          exitstatus = 1;
+        }
+               }
     }
 
     free(namelist[i]);

-- System Information:
Debian Release: 8.5
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16.0-4-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages debianutils depends on:
ii  libc6           2.19-18+deb8u4
ii  sensible-utils  0.0.9

debianutils recommends no packages.

debianutils suggests no packages.

-- no debconf information

Reply via email to