From: "William Hubbs" <williamh@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/, man/
Date: Mon, 4 Dec 2017 23:31:33 +0000 (UTC) [thread overview]
Message-ID: <1512429437.a2447dfb420cbd97a65cc085404c031d42cb3dfb.williamh@OpenRC> (raw)
commit: a2447dfb420cbd97a65cc085404c031d42cb3dfb
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Mon Dec 4 23:17:17 2017 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Mon Dec 4 23:17:17 2017 +0000
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=a2447dfb
rc-service: add --ifcrashed option
This works like the other --if options. If the service is crashed, run
the command.
This fixes #154.
man/rc-service.8 | 4 ++++
src/rc/rc-service.c | 10 +++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/man/rc-service.8 b/man/rc-service.8
index 80deb5eb..8f075de4 100644
--- a/man/rc-service.8
+++ b/man/rc-service.8
@@ -16,6 +16,10 @@
.Nd locate and run an OpenRC service with the given arguments
.Sh SYNOPSIS
.Nm
+.Op Fl c , -ifcrashed
+.Ar service cmd
+.Op Ar ...
+.Nm
.Op Fl i , -ifexists
.Ar service cmd
.Op Ar ...
diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index d0a64999..8e7b00dc 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -29,9 +29,10 @@
const char *applet = NULL;
const char *extraopts = NULL;
-const char *getoptstring = "e:ilr:IN" getoptstring_COMMON;
+const char *getoptstring = "ce:ilr:IN" getoptstring_COMMON;
const struct option longopts[] = {
{ "exists", 1, NULL, 'e' },
+ { "ifcrashed", 0, NULL, 'c' },
{ "ifexists", 0, NULL, 'i' },
{ "ifinactive", 0, NULL, 'I' },
{ "ifnotstarted", 0, NULL, 'N' },
@@ -41,6 +42,7 @@ const struct option longopts[] = {
};
const char * const longopts_help[] = {
"tests if the service exists or not",
+ "if the service is crashed then run the command",
"if the service exists then run the command",
"if the service is inactive then run the command",
"if the service is not started then run the command",
@@ -61,6 +63,7 @@ int main(int argc, char **argv)
RC_STRINGLIST *list;
RC_STRING *s;
RC_SERVICE state;
+ bool if_crashed = false;
bool if_exists = false;
bool if_inactive = false;
bool if_notstarted = false;
@@ -79,6 +82,9 @@ int main(int argc, char **argv)
free(service);
return opt;
/* NOTREACHED */
+ case 'c':
+ if_crashed = true;
+ break;
case 'i':
if_exists = true;
break;
@@ -121,6 +127,8 @@ int main(int argc, char **argv)
eerrorx("%s: service `%s' does not exist", applet, *argv);
}
state = rc_service_state(*argv);
+ if (if_crashed && ! (rc_service_daemons_crashed(*argv) && errno != EACCES))
+ return 0;
if (if_inactive && ! (state & RC_SERVICE_INACTIVE))
return 0;
if (if_notstarted && (state & RC_SERVICE_STARTED))
next reply other threads:[~2017-12-04 23:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-04 23:31 William Hubbs [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-10-18 23:01 [gentoo-commits] proj/openrc:master commit in: src/rc/, man/ William Hubbs
2018-05-16 18:27 William Hubbs
2016-07-18 19:12 William Hubbs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1512429437.a2447dfb420cbd97a65cc085404c031d42cb3dfb.williamh@OpenRC \
--to=williamh@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox