Linux Standard Base[1] states that for init scripts: * status command for a stopped service should have a return code of 3 * starting an already started service or stopping an already stopped service should be considered as successful The trivial patch below makes openrc comply with LSB. I am not aware of any service depending on the changed behaviour. Use case: One can use Gentoo init scripts with cluster management software - such as sys-cluster/pacemaker - instead of writing a resource agent or trying to work around their limitations for each managed service. [1] http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html Signed-off-by: Eray Aslan <eras@gentoo.org> --- sh/runscript.sh.in | 2 +- src/rc/runscript.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index 3d7252a..ea40573 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -89,7 +89,7 @@ _status() return 0 else einfo "status: stopped" - return 1 + return 3 fi } diff --git a/src/rc/runscript.c b/src/rc/runscript.c index f3f0517..a264535 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -596,8 +596,10 @@ svc_start_check(void) fcntl(exclusive_fd, F_SETFD, fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC); - if (state & RC_SERVICE_STARTED) - ewarnx("WARNING: %s has already been started", applet); + if (state & RC_SERVICE_STARTED) { + einfo("%s has already been started", applet); + exit(EXIT_SUCCESS); + } else if (state & RC_SERVICE_INACTIVE && !in_background) ewarnx("WARNING: %s has already started, but is inactive", applet); @@ -845,8 +847,10 @@ svc_stop_check(RC_SERVICE *state) fcntl(exclusive_fd, F_SETFD, fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC); - if (*state & RC_SERVICE_STOPPED) - ewarnx("WARNING: %s is already stopped", applet); + if (*state & RC_SERVICE_STOPPED) { + einfo("%s is already stopped", applet); + exit(EXIT_SUCCESS); + } rc_service_mark(service, RC_SERVICE_STOPPING); hook_out = RC_HOOK_SERVICE_STOP_OUT; -- 1.7.3.4 Reproducible: Always
Why does this patch also downgrade some ewarn calls to einfo? Thanks, William
patches need to be attached and pretty much never inlined in the comment field. bugzilla corrupts it and makes it useless to us to apply. we rely on the status return being zero/non-zero, but that's about it. so other than William's feedback, the exit status changes are fine.
Created attachment 259350 [details, diff] Makes openrc exit codes comply with LSB Patch attached. (In reply to comment #1) > Why does this patch also downgrade some ewarn calls to einfo? I find the return code of zero and a yellow dot with a big fat WARNING sign inconsistent. Hence, the change to einfo. We are just informing the user that the service is already {started,stopped}. But I have no problems if you want to keep it as ewarn.
i think the ewarn makes sense in terms of output
Created attachment 259445 [details, diff] Makes openrc exit codes comply with LSB Patch to modify the following exit codes: * status on a stopped service now has a return code of 3 (was 1) * starting an already started service now has a return code of 0 (was 1) * stopping an already stopped service now has a return code of 0 (was 1) Visual output stays the same, i.e. we keep the ewarn.
Is there a reason you change some calls from ewarnx() to ewarn() in the portion of this patch that modifies runscript.c? Thanks, William
ewarnx exits with EXIT_FAILURE and therefore cannot be used for an exit code of EXIT_SUCCESS. x is for exit, n for no newline and v is for printing if verbose in this function family: ewarn(), ewarnx(), ewarnn(), ewarnv(), eerror(), eerrorx() etc. Check src/libeinfo/libeinfo.c
This is now in git, commit 66abbe. Thanks for the report and the patch.