[systemd-devel] [PATCH] nspawn: When exiting with an error, make the error code meaningful.

Luke Shumaker LukeShu at sbcglobal.net
Sat Jun 28 09:09:55 PDT 2014


This is accomplished by having the return value of wait_for_container be
interpreted as a negative version of the exit status code.
---
 src/nspawn/nspawn.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 0a8dc0c..0c89c40 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -2662,7 +2662,7 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
 
         switch (status.si_code) {
         case CLD_EXITED:
-                r = status.si_status;
+                r = -status.si_status;
                 if (r == 0) {
                         if (!arg_quiet)
                                 log_debug("Container %s exited successfully.",
@@ -2672,7 +2672,6 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
                 } else {
                         log_error("Container %s failed with error code %i.",
                                   arg_machine, status.si_status);
-                        r = -1;
                 }
                 break;
 
@@ -2699,13 +2698,13 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
         case CLD_DUMPED:
                 log_error("Container %s terminated by signal %s.",
                           arg_machine, signal_to_string(status.si_status));
-                r = -1;
+                r = -EXIT_FAILURE;
                 break;
 
         default:
                 log_error("Container %s failed due to unknown reason.",
                           arg_machine);
-                r = -1;
+                r = -EXIT_FAILURE;
                 break;
         }
 
@@ -3296,11 +3295,10 @@ check_container_status:
                 /* Redundant, but better safe than sorry */
                 kill(pid, SIGKILL);
 
-                r = wait_for_container(pid, &container_status);
+                r = -wait_for_container(pid, &container_status);
                 pid = 0;
 
-                if (r < 0) {
-                        r = EXIT_FAILURE;
+                if (r > 0) {
                         break;
                 } else if (container_status == CONTAINER_TERMINATED)
                         break;
-- 
2.0.1



More information about the systemd-devel mailing list