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