]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/exit-status.c
util: introduce memcmp_safe()
[thirdparty/systemd.git] / src / basic / exit-status.c
index 3827f254fac9577238152202de4319be70a8f4f9..21af8c4c7194ec5881f5e71f5995b0369c366fc9 100644 (file)
@@ -1,12 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2010 Lennart Poettering
-***/
 
 #include <signal.h>
 #include <stdlib.h>
+#include <sysexits.h>
 
 #include "exit-status.h"
 #include "macro.h"
 
 const char* exit_status_to_string(int status, ExitStatusLevel level) {
 
-        /* We cast to int here, so that -Wenum doesn't complain that
-         * EXIT_SUCCESS/EXIT_FAILURE aren't in the enum */
-
-        switch (status) {
+        /* Exit status ranges:
+         *
+         *   0…1   │ ISO C, EXIT_SUCCESS + EXIT_FAILURE
+         *   2…7   │ LSB exit codes for init scripts
+         *   8…63  │ (Currently unmapped)
+         *  64…78  │ BSD defined exit codes
+         *  79…199 │ (Currently unmapped)
+         * 200…241 │ systemd's private error codes (might be extended to 254 in future development)
+         * 242…254 │ (Currently unmapped, but see above)
+         *   255   │ (We should probably stay away from that one, it's frequently used by applications to indicate an
+         *         │ exit reason that cannot really be expressed in a single exit status value — such as a propagated
+         *         │ signal or such)
+         */
+
+        switch (status) {  /* We always cover the ISO C ones */
 
         case EXIT_SUCCESS:
                 return "SUCCESS";
@@ -26,8 +33,8 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
                 return "FAILURE";
         }
 
-        if (IN_SET(level, EXIT_STATUS_SYSTEMD, EXIT_STATUS_LSB)) {
-                switch (status) {
+        if (IN_SET(level, EXIT_STATUS_SYSTEMD, EXIT_STATUS_LSB, EXIT_STATUS_FULL)) {
+                switch (status) { /* Optionally we cover our own ones */
 
                 case EXIT_CHDIR:
                         return "CHDIR";
@@ -151,8 +158,8 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
                 }
         }
 
-        if (level == EXIT_STATUS_LSB) {
-                switch (status) {
+        if (IN_SET(level, EXIT_STATUS_LSB, EXIT_STATUS_FULL)) {
+                switch (status) { /* Optionally we support LSB ones */
 
                 case EXIT_INVALIDARGUMENT:
                         return "INVALIDARGUMENT";
@@ -174,6 +181,56 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
                 }
         }
 
+        if (level == EXIT_STATUS_FULL) {
+                switch (status) { /* Optionally, we support BSD exit statusses */
+
+                case EX_USAGE:
+                        return "USAGE";
+
+                case EX_DATAERR:
+                        return "DATAERR";
+
+                case EX_NOINPUT:
+                        return "NOINPUT";
+
+                case EX_NOUSER:
+                        return "NOUSER";
+
+                case EX_NOHOST:
+                        return "NOHOST";
+
+                case EX_UNAVAILABLE:
+                        return "UNAVAILABLE";
+
+                case EX_SOFTWARE:
+                        return "SOFTWARE";
+
+                case EX_OSERR:
+                        return "OSERR";
+
+                case EX_OSFILE:
+                        return "OSFILE";
+
+                case EX_CANTCREAT:
+                        return "CANTCREAT";
+
+                case EX_IOERR:
+                        return "IOERR";
+
+                case EX_TEMPFAIL:
+                        return "TEMPFAIL";
+
+                case EX_PROTOCOL:
+                        return "PROTOCOL";
+
+                case EX_NOPERM:
+                        return "NOPERM";
+
+                case EX_CONFIG:
+                        return "CONFIG";
+                }
+        }
+
         return NULL;
 }