aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'sys-apps/openrc/files/0.4.3/0002-support-custom-status.patch')
-rw-r--r--sys-apps/openrc/files/0.4.3/0002-support-custom-status.patch204
1 files changed, 204 insertions, 0 deletions
diff --git a/sys-apps/openrc/files/0.4.3/0002-support-custom-status.patch b/sys-apps/openrc/files/0.4.3/0002-support-custom-status.patch
new file mode 100644
index 0000000..7459eac
--- /dev/null
+++ b/sys-apps/openrc/files/0.4.3/0002-support-custom-status.patch
@@ -0,0 +1,204 @@
+Index: openrc-0.4.3/sh/runscript.sh.in
+===================================================================
+--- openrc-0.4.3.orig/sh/runscript.sh.in
++++ openrc-0.4.3/sh/runscript.sh.in
+@@ -45,7 +45,32 @@ describe()
+ done
+ }
+
+-# Template start / stop functions
++# Report status
++_status()
++{
++ if service_stopping; then
++ ewarn "status: stopping"
++ return 4
++ elif service_starting; then
++ ewarn "status: starting"
++ return 8
++ elif service_inactive; then
++ ewarn "status: inactive"
++ return 16
++ elif service_started; then
++ if service_crashed; then
++ eerror "status: crashed"
++ return 32
++ fi
++ einfo "status: started"
++ return 0
++ else
++ einfo "status: stopped"
++ return 1
++ fi
++}
++
++# Template start / stop / status functions
+ start()
+ {
+ [ -n "${command}" ] || return 0
+@@ -85,6 +110,11 @@ stop()
+ eend $? "Failed to stop ${RC_SVCNAME}"
+ }
+
++status()
++{
++ _status
++}
++
+ yesno ${RC_DEBUG} && set -x
+
+ _conf_d=${RC_SERVICE%/*}/../conf.d
+@@ -134,7 +164,7 @@ unset _f
+
+ while [ -n "$1" ]; do
+ # See if we have the required function and run it
+- for _cmd in describe start stop ${extra_commands:-${opts}} \
++ for _cmd in describe start stop status ${extra_commands:-${opts}} \
+ ${extra_started_commands}; do
+ if [ "${_cmd}" = "$1" ]; then
+ if [ "$(command -v "$1")" = "$1" ]; then
+Index: openrc-0.4.3/src/rc/Makefile
+===================================================================
+--- openrc-0.4.3.orig/src/rc/Makefile
++++ openrc-0.4.3/src/rc/Makefile
+@@ -18,7 +18,7 @@ RC_BINLINKS= einfon einfo ewarnn ewarn e
+ service_starting service_started \
+ service_stopping service_stopped \
+ service_inactive service_wasinactive \
+- service_hotplugged service_started_daemon \
++ service_hotplugged service_started_daemon service_crashed \
+ checkpath fstabinfo mountinfo rc-depend \
+ service_get_value service_set_value get_options save_options \
+ shell_var is_newer_than is_older_than
+Index: openrc-0.4.3/src/rc/rc-applets.c
+===================================================================
+--- openrc-0.4.3.orig/src/rc/rc-applets.c
++++ openrc-0.4.3/src/rc/rc-applets.c
+@@ -295,6 +295,10 @@ static int do_service(int argc, char **a
+ }
+ ok = rc_service_started_daemon(service, exec, NULL, idx);
+
++ } else if (strcmp(applet, "service_crashed") == 0) {
++ ok = (_rc_can_find_pids() &&
++ rc_service_daemons_crashed(service) &&
++ errno != EACCES);
+ } else
+ eerrorx("%s: unknown applet", applet);
+
+Index: openrc-0.4.3/src/rc/runscript.c
+===================================================================
+--- openrc-0.4.3.orig/src/rc/runscript.c
++++ openrc-0.4.3/src/rc/runscript.c
+@@ -34,6 +34,7 @@
+ #include <sys/file.h>
+ #include <sys/param.h>
+ #include <sys/stat.h>
++#include <sys/wait.h>
+
+ #include <ctype.h>
+ #include <dlfcn.h>
+@@ -412,11 +413,10 @@ write_prefix(const char *buffer, size_t
+ return ret;
+ }
+
+-static bool
++static int
+ svc_exec(const char *arg1, const char *arg2)
+ {
+- bool execok;
+- int fdout = fileno(stdout);
++ int ret, fdout = fileno(stdout);
+ struct termios tt;
+ struct winsize ws;
+ int i;
+@@ -527,13 +527,13 @@ svc_exec(const char *arg1, const char *a
+ master_tty = -1;
+ }
+
+- execok = rc_waitpid(service_pid) == 0 ? true : false;
+- if (!execok && errno == ECHILD)
++ ret = WEXITSTATUS(rc_waitpid(service_pid));
++ if (ret != 0 && errno == ECHILD)
+ /* killall5 -9 could cause this */
+- execok = true;
++ ret = 0;
+ service_pid = 0;
+
+- return execok;
++ return ret;
+ }
+
+ static bool
+@@ -584,39 +584,6 @@ svc_wait(const char *svc)
+ return retval;
+ }
+
+-static RC_SERVICE
+-svc_status(void)
+-{
+- char status[10];
+- int (*e) (const char *fmt, ...) EINFO_PRINTF(1, 2) = einfo;
+- RC_SERVICE state = rc_service_state(service);
+-
+- if (state & RC_SERVICE_STOPPING) {
+- snprintf(status, sizeof(status), "stopping");
+- e = ewarn;
+- } else if (state & RC_SERVICE_STARTING) {
+- snprintf(status, sizeof(status), "starting");
+- e = ewarn;
+- } else if (state & RC_SERVICE_INACTIVE) {
+- snprintf(status, sizeof(status), "inactive");
+- e = ewarn;
+- } else if (state & RC_SERVICE_STARTED) {
+- errno = 0;
+- if (_rc_can_find_pids() &&
+- rc_service_daemons_crashed(service) &&
+- errno != EACCES)
+- {
+- snprintf(status, sizeof(status), "crashed");
+- e = eerror;
+- } else
+- snprintf(status, sizeof(status), "started");
+- } else
+- snprintf(status, sizeof(status), "stopped");
+-
+- e("status: %s", status);
+- return state;
+-}
+-
+ static void
+ make_exclusive(void)
+ {
+@@ -881,7 +848,7 @@ svc_start(bool deps)
+ setenv("IN_BACKGROUND", ibsave, 1);
+ hook_out = RC_HOOK_SERVICE_START_DONE;
+ rc_plugin_run(RC_HOOK_SERVICE_START_NOW, applet);
+- started = svc_exec("start", NULL);
++ started = (svc_exec("start", NULL) == 0);
+ if (ibsave)
+ unsetenv("IN_BACKGROUND");
+
+@@ -1058,7 +1025,7 @@ svc_stop(bool deps)
+ setenv("IN_BACKGROUND", ibsave, 1);
+ hook_out = RC_HOOK_SERVICE_STOP_DONE;
+ rc_plugin_run(RC_HOOK_SERVICE_STOP_NOW, applet);
+- stopped = svc_exec("stop", NULL);
++ stopped = (svc_exec("stop", NULL) == 0);
+ if (ibsave)
+ unsetenv("IN_BACKGROUND");
+
+@@ -1383,10 +1350,10 @@ runscript(int argc, char **argv)
+ rc_stringlist_free(services);
+ services = NULL;
+ } else if (strcmp (optarg, "status") == 0) {
+- RC_SERVICE r = svc_status();
+- retval = (int) r;
+- if (retval & RC_SERVICE_STARTED)
+- retval = 0;
++ save = prefix;
++ eprefix(NULL);
++ prefix = NULL;
++ retval = svc_exec("status", NULL);
+ } else {
+ if (strcmp(optarg, "conditionalrestart") == 0 ||
+ strcmp(optarg, "condrestart") == 0)