Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 351160 - sys-apps/openrc: make exit codes comply with LSB
Summary: sys-apps/openrc: make exit codes comply with LSB
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-08 22:16 UTC by Eray Aslan
Modified: 2011-01-13 02:09 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Makes openrc exit codes comply with LSB (0001-Makes-exit-codes-comply-with-LSB.patch,1.62 KB, patch)
2011-01-09 05:25 UTC, Eray Aslan
Details | Diff
Makes openrc exit codes comply with LSB (0001-Makes-exit-codes-comply-with-LSB.patch,1.53 KB, patch)
2011-01-10 06:49 UTC, Eray Aslan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eray Aslan gentoo-dev 2011-01-08 22:16:46 UTC
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
Comment 1 William Hubbs gentoo-dev 2011-01-08 22:27:39 UTC
Why does this patch also downgrade some ewarn calls to einfo?

Thanks,

William

Comment 2 SpanKY gentoo-dev 2011-01-08 22:48:28 UTC
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.
Comment 3 Eray Aslan gentoo-dev 2011-01-09 05:25:00 UTC
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.
Comment 4 SpanKY gentoo-dev 2011-01-10 01:17:06 UTC
i think the ewarn makes sense in terms of output
Comment 5 Eray Aslan gentoo-dev 2011-01-10 06:49:38 UTC
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.
Comment 6 William Hubbs gentoo-dev 2011-01-10 16:26:42 UTC
Is there a reason you change some calls from ewarnx() to ewarn() in the
portion of this patch that modifies runscript.c?

Thanks,

William

Comment 7 Eray Aslan gentoo-dev 2011-01-11 07:12:42 UTC
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
Comment 8 William Hubbs gentoo-dev 2011-01-13 02:09:19 UTC
This is now in git, commit 66abbe.
Thanks for the report and the patch.