1 |
commit: a2447dfb420cbd97a65cc085404c031d42cb3dfb |
2 |
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com> |
3 |
AuthorDate: Mon Dec 4 23:17:17 2017 +0000 |
4 |
Commit: William Hubbs <williamh <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Dec 4 23:17:17 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a2447dfb |
7 |
|
8 |
rc-service: add --ifcrashed option |
9 |
|
10 |
This works like the other --if options. If the service is crashed, run |
11 |
the command. |
12 |
|
13 |
This fixes #154. |
14 |
|
15 |
man/rc-service.8 | 4 ++++ |
16 |
src/rc/rc-service.c | 10 +++++++++- |
17 |
2 files changed, 13 insertions(+), 1 deletion(-) |
18 |
|
19 |
diff --git a/man/rc-service.8 b/man/rc-service.8 |
20 |
index 80deb5eb..8f075de4 100644 |
21 |
--- a/man/rc-service.8 |
22 |
+++ b/man/rc-service.8 |
23 |
@@ -16,6 +16,10 @@ |
24 |
.Nd locate and run an OpenRC service with the given arguments |
25 |
.Sh SYNOPSIS |
26 |
.Nm |
27 |
+.Op Fl c , -ifcrashed |
28 |
+.Ar service cmd |
29 |
+.Op Ar ... |
30 |
+.Nm |
31 |
.Op Fl i , -ifexists |
32 |
.Ar service cmd |
33 |
.Op Ar ... |
34 |
|
35 |
diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c |
36 |
index d0a64999..8e7b00dc 100644 |
37 |
--- a/src/rc/rc-service.c |
38 |
+++ b/src/rc/rc-service.c |
39 |
@@ -29,9 +29,10 @@ |
40 |
|
41 |
const char *applet = NULL; |
42 |
const char *extraopts = NULL; |
43 |
-const char *getoptstring = "e:ilr:IN" getoptstring_COMMON; |
44 |
+const char *getoptstring = "ce:ilr:IN" getoptstring_COMMON; |
45 |
const struct option longopts[] = { |
46 |
{ "exists", 1, NULL, 'e' }, |
47 |
+ { "ifcrashed", 0, NULL, 'c' }, |
48 |
{ "ifexists", 0, NULL, 'i' }, |
49 |
{ "ifinactive", 0, NULL, 'I' }, |
50 |
{ "ifnotstarted", 0, NULL, 'N' }, |
51 |
@@ -41,6 +42,7 @@ const struct option longopts[] = { |
52 |
}; |
53 |
const char * const longopts_help[] = { |
54 |
"tests if the service exists or not", |
55 |
+ "if the service is crashed then run the command", |
56 |
"if the service exists then run the command", |
57 |
"if the service is inactive then run the command", |
58 |
"if the service is not started then run the command", |
59 |
@@ -61,6 +63,7 @@ int main(int argc, char **argv) |
60 |
RC_STRINGLIST *list; |
61 |
RC_STRING *s; |
62 |
RC_SERVICE state; |
63 |
+ bool if_crashed = false; |
64 |
bool if_exists = false; |
65 |
bool if_inactive = false; |
66 |
bool if_notstarted = false; |
67 |
@@ -79,6 +82,9 @@ int main(int argc, char **argv) |
68 |
free(service); |
69 |
return opt; |
70 |
/* NOTREACHED */ |
71 |
+ case 'c': |
72 |
+ if_crashed = true; |
73 |
+ break; |
74 |
case 'i': |
75 |
if_exists = true; |
76 |
break; |
77 |
@@ -121,6 +127,8 @@ int main(int argc, char **argv) |
78 |
eerrorx("%s: service `%s' does not exist", applet, *argv); |
79 |
} |
80 |
state = rc_service_state(*argv); |
81 |
+ if (if_crashed && ! (rc_service_daemons_crashed(*argv) && errno != EACCES)) |
82 |
+ return 0; |
83 |
if (if_inactive && ! (state & RC_SERVICE_INACTIVE)) |
84 |
return 0; |
85 |
if (if_notstarted && (state & RC_SERVICE_STARTED)) |