anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0342-systemctl-Replace-init-script-error-codes-with-enum-.patch

803fb7
From 20a914f752898aae11708d7bf901e7dc1e81a28e Mon Sep 17 00:00:00 2001
803fb7
From: Susant Sahani <ssahani@users.noreply.github.com>
803fb7
Date: Tue, 31 May 2016 19:06:58 +0530
803fb7
Subject: [PATCH] systemctl: Replace init script error codes with enum (#3400)
803fb7
803fb7
Now we just using constants for the init script exit status codes.
803fb7
Replace those error codes with enum so that it's more meaningful
803fb7
and readable.
803fb7
803fb7
(cherry picked from commit b613907ea988e2994c68be686b5e92cdc7d3fb68)
803fb7
Related: #1047466
803fb7
---
803fb7
 src/systemctl/systemctl.c | 29 ++++++++++++++++++++++++-----
803fb7
 1 file changed, 24 insertions(+), 5 deletions(-)
803fb7
803fb7
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
803fb7
index 6079d60db..fdda174ae 100644
803fb7
--- a/src/systemctl/systemctl.c
803fb7
+++ b/src/systemctl/systemctl.c
803fb7
@@ -75,6 +75,25 @@
803fb7
 #include "mkdir.h"
803fb7
 #include "dropin.h"
803fb7
 
803fb7
+/* The init script exit status codes
803fb7
+   0       program is running or service is OK
803fb7
+   1       program is dead and /var/run pid file exists
803fb7
+   2       program is dead and /var/lock lock file exists
803fb7
+   3       program is not running
803fb7
+   4       program or service status is unknown
803fb7
+   5-99    reserved for future LSB use
803fb7
+   100-149 reserved for distribution use
803fb7
+   150-199 reserved for application use
803fb7
+   200-254 reserved
803fb7
+*/
803fb7
+enum {
803fb7
+        EXIT_PROGRAM_RUNNING_OR_SERVICE_OK        = 0,
803fb7
+        EXIT_PROGRAM_DEAD_AND_PID_EXISTS          = 1,
803fb7
+        EXIT_PROGRAM_DEAD_AND_LOCK_FILE_EXISTS    = 2,
803fb7
+        EXIT_PROGRAM_NOT_RUNNING                  = 3,
803fb7
+        EXIT_PROGRAM_OR_SERVICES_STATUS_UNKNOWN   = 4,
803fb7
+};
803fb7
+
803fb7
 static char **arg_types = NULL;
803fb7
 static char **arg_states = NULL;
803fb7
 static char **arg_properties = NULL;
803fb7
@@ -3028,11 +3047,11 @@ static int check_unit_generic(sd_bus *bus, int code, const char *good_states, ch
803fb7
 
803fb7
 static int check_unit_active(sd_bus *bus, char **args) {
803fb7
         /* According to LSB: 3, "program is not running" */
803fb7
-        return check_unit_generic(bus, 3, "active\0reloading\0", args + 1);
803fb7
+        return check_unit_generic(bus, EXIT_PROGRAM_NOT_RUNNING, "active\0reloading\0", args + 1);
803fb7
 }
803fb7
 
803fb7
 static int check_unit_failed(sd_bus *bus, char **args) {
803fb7
-        return check_unit_generic(bus, 1, "failed\0", args + 1);
803fb7
+        return check_unit_generic(bus, EXIT_PROGRAM_DEAD_AND_PID_EXISTS, "failed\0", args + 1);
803fb7
 }
803fb7
 
803fb7
 static int kill_unit(sd_bus *bus, char **args) {
803fb7
@@ -4294,11 +4313,11 @@ static int show_one(
803fb7
                  * 4: program or service status is unknown
803fb7
                  */
803fb7
                 if (info.pid_file && access(info.pid_file, F_OK) == 0)
803fb7
-                        r = 1;
803fb7
+                        r = EXIT_PROGRAM_DEAD_AND_PID_EXISTS;
803fb7
                 else if (streq_ptr(info.load_state, "not-found") && streq_ptr(info.active_state, "inactive"))
803fb7
-                        r = 4;
803fb7
+                        r = EXIT_PROGRAM_OR_SERVICES_STATUS_UNKNOWN;
803fb7
                 else
803fb7
-                        r = 3;
803fb7
+                        r = EXIT_PROGRAM_NOT_RUNNING;
803fb7
         }
803fb7
 
803fb7
         while ((p = info.exec)) {