Gentoo Archives: gentoo-dev

From: Eray Aslan <eras@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH] openrc: make exit codes comply with Linux Standard Base
Date: Sat, 08 Jan 2011 22:32:12
Message-Id: 20110108235136.GA1517@zptr-nb18
1 Linux Standard Base[1] states that for init scripts:
2
3 * status command for a stopped service should have a return code of 3
4 * starting an already started service or stopping an already stopped
5 service should be considered as successful
6
7 The trivial patch below makes openrc comply with LSB. I am not aware of
8 any service depending on the changed behaviour.
9
10 Use case: One can use Gentoo init scripts with cluster management
11 software - such as sys-cluster/pacemaker - instead of writing a resource
12 agent or trying to work around their limitations for each managed
13 service.
14
15 [1]
16 http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
17
18
19 Signed-off-by: Eray Aslan <eras@g.o>
20 ---
21 sh/runscript.sh.in | 2 +-
22 src/rc/runscript.c | 12 ++++++++----
23 2 files changed, 9 insertions(+), 5 deletions(-)
24
25 diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
26 index 3d7252a..ea40573 100644
27 --- a/sh/runscript.sh.in
28 +++ b/sh/runscript.sh.in
29 @@ -89,7 +89,7 @@ _status()
30 return 0
31 else
32 einfo "status: stopped"
33 - return 1
34 + return 3
35 fi
36 }
37
38 diff --git a/src/rc/runscript.c b/src/rc/runscript.c
39 index f3f0517..a264535 100644
40 --- a/src/rc/runscript.c
41 +++ b/src/rc/runscript.c
42 @@ -596,8 +596,10 @@ svc_start_check(void)
43 fcntl(exclusive_fd, F_SETFD,
44 fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
45
46 - if (state & RC_SERVICE_STARTED)
47 - ewarnx("WARNING: %s has already been started", applet);
48 + if (state & RC_SERVICE_STARTED) {
49 + einfo("%s has already been started", applet);
50 + exit(EXIT_SUCCESS);
51 + }
52 else if (state & RC_SERVICE_INACTIVE && !in_background)
53 ewarnx("WARNING: %s has already started, but is inactive",
54 applet);
55 @@ -845,8 +847,10 @@ svc_stop_check(RC_SERVICE *state)
56 fcntl(exclusive_fd, F_SETFD,
57 fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
58
59 - if (*state & RC_SERVICE_STOPPED)
60 - ewarnx("WARNING: %s is already stopped", applet);
61 + if (*state & RC_SERVICE_STOPPED) {
62 + einfo("%s is already stopped", applet);
63 + exit(EXIT_SUCCESS);
64 + }
65
66 rc_service_mark(service, RC_SERVICE_STOPPING);
67 hook_out = RC_HOOK_SERVICE_STOP_OUT;
68 --
69 1.7.3.4

Replies