Blob Blame History Raw
From 4b1505597c1df43a20108fd1f17699ad04c20c4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Sat, 29 Nov 2014 10:28:01 -0500
Subject: [PATCH] delta: diff returns 1 when files differ, ignore this

https://bugs.debian/org/771397
(cherry picked from commit 820d3acfe924e58965d14b4711d5df31c5db199a)

Conflicts:
	src/quotacheck/quotacheck.c
---
 src/core/shutdown.c           |  2 +-
 src/delta/delta.c             |  2 +-
 src/login/inhibit.c           |  2 +-
 src/nspawn/nspawn.c           |  4 ++--
 src/quotacheck/quotacheck.c   |  5 ++++-
 src/shared/util.c             | 22 ++++++++++++----------
 src/shared/util.h             |  2 +-
 src/vconsole/vconsole-setup.c |  4 ++--
 8 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/src/core/shutdown.c b/src/core/shutdown.c
index 03cfddc543..7add89f6e9 100644
--- a/src/core/shutdown.c
+++ b/src/core/shutdown.c
@@ -371,7 +371,7 @@ int main(int argc, char *argv[]) {
                                 execv(args[0], (char * const *) args);
                                 _exit(EXIT_FAILURE);
                         } else
-                                wait_for_terminate_and_warn("kexec", pid);
+                                wait_for_terminate_and_warn("kexec", pid, true);
                 }
 
                 cmd = RB_AUTOBOOT;
diff --git a/src/delta/delta.c b/src/delta/delta.c
index 25c4a0bcfc..9a2f17c58a 100644
--- a/src/delta/delta.c
+++ b/src/delta/delta.c
@@ -194,7 +194,7 @@ static int found_override(const char *top, const char *bottom) {
                 _exit(1);
         }
 
-        wait_for_terminate_and_warn("diff", pid);
+        wait_for_terminate_and_warn("diff", pid, false);
         putchar('\n');
 
         return k;
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index 122c69d7a1..e2222ea69c 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -280,7 +280,7 @@ int main(int argc, char *argv[]) {
                         _exit(EXIT_FAILURE);
                 }
 
-                r = wait_for_terminate_and_warn(argv[optind], pid);
+                r = wait_for_terminate_and_warn(argv[optind], pid, true);
                 return r < 0 ? EXIT_FAILURE : r;
         }
 
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 712c0ea332..4e0fbb610e 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -2757,7 +2757,7 @@ static int change_uid_gid(char **_home) {
 
         truncate_nl(line);
 
-        wait_for_terminate_and_warn("getent passwd", pid);
+        wait_for_terminate_and_warn("getent passwd", pid, true);
 
         x = strchr(line, ':');
         if (!x) {
@@ -2841,7 +2841,7 @@ static int change_uid_gid(char **_home) {
 
         truncate_nl(line);
 
-        wait_for_terminate_and_warn("getent initgroups", pid);
+        wait_for_terminate_and_warn("getent initgroups", pid, true);
 
         /* Skip over the username and subsequent separator whitespace */
         x = line;
diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c
index ed95b48c63..a45285722f 100644
--- a/src/quotacheck/quotacheck.c
+++ b/src/quotacheck/quotacheck.c
@@ -74,6 +74,7 @@ int main(int argc, char *argv[]) {
         };
 
         pid_t pid;
+        int r;
 
         if (argc > 1) {
                 log_error("This program takes no arguments.");
@@ -107,5 +108,7 @@ int main(int argc, char *argv[]) {
                 _exit(1); /* Operational error */
         }
 
-        return wait_for_terminate_and_warn("quotacheck", pid) >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+        r = wait_for_terminate_and_warn("quotacheck", pid, true);
+
+        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }
diff --git a/src/shared/util.c b/src/shared/util.c
index 4143f6d643..927bca4ec4 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3599,8 +3599,11 @@ int wait_for_terminate(pid_t pid, siginfo_t *status) {
  *
  * That is, success is indicated by a return value of zero, and an
  * error is indicated by a non-zero value.
+ *
+ * A warning is emitted if the process terminates abnormally,
+ * and also if it returns non-zero unless check_exit_code is true.
  */
-int wait_for_terminate_and_warn(const char *name, pid_t pid) {
+int wait_for_terminate_and_warn(const char *name, pid_t pid, bool check_exit_code) {
         int r;
         siginfo_t status;
 
@@ -3614,14 +3617,13 @@ int wait_for_terminate_and_warn(const char *name, pid_t pid) {
         }
 
         if (status.si_code == CLD_EXITED) {
-                if (status.si_status != 0) {
-                        log_warning("%s failed with error code %i.", name, status.si_status);
-                        return status.si_status;
-                }
-
-                log_debug("%s succeeded.", name);
-                return 0;
+                if (status.si_status != 0)
+                        log_full(check_exit_code ? LOG_WARNING : LOG_DEBUG,
+                                 "%s failed with error code %i.", name, status.si_status);
+                else
+                        log_debug("%s succeeded.", name);
 
+                return status.si_status;
         } else if (status.si_code == CLD_KILLED ||
                    status.si_code == CLD_DUMPED) {
 
@@ -3976,13 +3978,13 @@ void execute_directory(const char *directory, DIR *d, usec_t timeout, char *argv
                         path = hashmap_remove(pids, UINT_TO_PTR(pid));
                         assert(path);
 
-                        wait_for_terminate_and_warn(path, pid);
+                        wait_for_terminate_and_warn(path, pid, true);
                 }
 
                 _exit(EXIT_SUCCESS);
         }
 
-        wait_for_terminate_and_warn(directory, executor_pid);
+        wait_for_terminate_and_warn(directory, executor_pid, true);
 }
 
 int kill_and_sigcont(pid_t pid, int sig) {
diff --git a/src/shared/util.h b/src/shared/util.h
index 35584467c1..cde38a5559 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -505,7 +505,7 @@ char *unquote(const char *s, const char *quotes);
 char *normalize_env_assignment(const char *s);
 
 int wait_for_terminate(pid_t pid, siginfo_t *status);
-int wait_for_terminate_and_warn(const char *name, pid_t pid);
+int wait_for_terminate_and_warn(const char *name, pid_t pid, bool check_exit_code);
 
 noreturn void freeze(void);
 
diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c
index 0db97f88bc..4f29caab2a 100644
--- a/src/vconsole/vconsole-setup.c
+++ b/src/vconsole/vconsole-setup.c
@@ -310,7 +310,7 @@ int main(int argc, char **argv) {
         }
 
         if (font_pid > 0)
-                wait_for_terminate_and_warn(KBD_SETFONT, font_pid);
+                wait_for_terminate_and_warn(KBD_SETFONT, font_pid, true);
 
         r = keymap_load(vc, vc_keymap, vc_keymap_toggle, utf8, &keymap_pid);
         if (r < 0) {
@@ -319,7 +319,7 @@ int main(int argc, char **argv) {
         }
 
         if (keymap_pid > 0)
-                wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid);
+                wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid, true);
 
         /* Only copy the font when we started setfont successfully */
         if (font_copy && font_pid > 0)