richardphibel / rpms / systemd

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