[gentoo-commits] proj/openrc:master commit in: sh/, src/rc/
commit: 913b2ca53771742385d5c69164aefcaab634f012 Author: William Hubbs gmail com> AuthorDate: Sat Oct 28 00:22:09 2017 + Commit: William Hubbs gentoo org> CommitDate: Sat Oct 28 00:22:09 2017 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=913b2ca5 supervise-daemon: use RC_SVCNAME as the first argument to the daemon This makes ps show which service the supervisor is monitoring. sh/supervise-daemon.sh| 4 ++-- src/rc/supervise-daemon.c | 24 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh index e5d8d461..f6e599d5 100644 --- a/sh/supervise-daemon.sh +++ b/sh/supervise-daemon.sh @@ -22,7 +22,7 @@ supervise_start() # The eval call is necessary for cases like: # command_args="this \"is a\" test" # to work properly. - eval supervise-daemon --start \ + eval supervise-daemon "${RC_SVCNAME}" --start \ ${retry:+--retry} $retry \ ${chroot:+--chroot} $chroot \ ${pidfile:+--pidfile} $pidfile \ @@ -49,7 +49,7 @@ supervise_stop() pidfile="${startpidfile:-$pidfile}" [ -n "$pidfile" ] || return 0 ebegin "Stopping ${name:-$RC_SVCNAME}" - supervise-daemon --stop \ + supervise-daemon "${RC_SVCNAME}" --stop \ ${pidfile:+--pidfile} $chroot$pidfile \ ${stopsig:+--signal} $stopsig diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c index 1d0c3407..3989cbc7 100644 --- a/src/rc/supervise-daemon.c +++ b/src/rc/supervise-daemon.c @@ -561,8 +561,13 @@ int main(int argc, char **argv) applet = basename_c(argv[0]); atexit(cleanup); svcname = getenv("RC_SVCNAME"); + if (!svcname) + eerrorx("%s: The RC_SVCNAME environment variable is not set", applet); openlog(applet, LOG_PID, LOG_DAEMON); + if (argc >= 1 && svcname && strcmp(argv[1], svcname)) + eerrorx("%s: the first argument must be %s", applet, svcname); + if ((tmp = getenv("SSD_NICELEVEL"))) if (sscanf(tmp, "%d", ) != 1) eerror("%s: invalid nice level `%s' (SSD_NICELEVEL)", @@ -583,6 +588,17 @@ int main(int argc, char **argv) } } + *cmdline = '\0'; + c = argv; + while (c && *c) { + strcat(cmdline, *c); + strcat(cmdline, " "); + c++; + } + if (svcname) { + argc--; + argv++; + } while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1) switch (opt) { @@ -721,14 +737,6 @@ int main(int argc, char **argv) if (!pidfile && !reexec) eerrorx("%s: --pidfile must be specified", applet); - - *cmdline = '\0'; - c = argv; - while (c && *c) { - strcat(cmdline, *c); - strcat(cmdline, " "); - c++; - } endpwent(); argc -= optind; argv += optind;
[gentoo-commits] proj/openrc:master commit in: sh/, src/rc/
commit: 82da844b42ff83b2ebf944198e56ac2d81851897 Author: William Hubbs gmail com> AuthorDate: Thu Oct 26 18:11:12 2017 + Commit: William Hubbs gentoo org> CommitDate: Thu Oct 26 18:11:12 2017 + URL:https://gitweb.gentoo.org/proj/openrc.git/commit/?id=82da844b implement "unsupervised" status The unsupervised status is to be used when a supervisor of a supervised service dies but leaves the service daemon itself running. sh/supervise-daemon.sh | 21 + src/rc/rc-status.c | 11 ++- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh index d2cfe932..e5d8d461 100644 --- a/sh/supervise-daemon.sh +++ b/sh/supervise-daemon.sh @@ -58,22 +58,11 @@ supervise_stop() _check_supervised() { - [ "$RC_UNAME" != Linux ] && return 0 - local child_pid="$(service_get_value "child_pid")" - local pid="$(cat ${pidfile})" - if [ -n "${child_pid}" ]; then - if ! [ -e "/proc/${pid}" ] && [ -e "/proc/${child_pid}" ]; then - if [ -e "/proc/self/ns/pid" ] && [ -e "/proc/${child_pid}/ns/pid" ]; then - local n1 n2 - n1=$(readlink "/proc/self/ns/pid") - n2=$(readlink "/proc/${child_pid}/ns/pid") - if [ "${n1}" = "${n2}" ]; then - return 1 - fi - else - return 1 - fi - fi + local child_pid start_time + child_pid="$(service_get_value "child_pid")" + start_time="$(service_get_value "start_time")" + if [ -n "${child_pid}" ] && [ -n "${start_time}" ]; then + return 1 fi return 0 } diff --git a/src/rc/rc-status.c b/src/rc/rc-status.c index 9a094d47..d29f876a 100644 --- a/src/rc/rc-status.c +++ b/src/rc/rc-status.c @@ -128,6 +128,8 @@ print_service(const char *service) { char status[60]; char uptime [40]; + char *child_pid = NULL; + char *start_time = NULL; int cols = printf(" %s", service); const char *c = ecolor(ECOLOR_GOOD); RC_SERVICE state = rc_service_state(service); @@ -147,7 +149,14 @@ print_service(const char *service) rc_service_daemons_crashed(service) && errno != EACCES) { - snprintf(status, sizeof(status), " crashed "); + child_pid = rc_service_value_get(service, "child_pid"); + start_time = rc_service_value_get(service, "start_time"); + if (start_time && child_pid) + snprintf(status, sizeof(status), " unsupervised "); + else + snprintf(status, sizeof(status), " crashed "); + free(child_pid); + free(start_time); } else { get_uptime(service, uptime, 40); snprintf(status, sizeof(status), " started %s", uptime);