public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "William Hubbs" <williamh@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/, man/
Date: Wed, 16 May 2018 18:27:06 +0000 (UTC)	[thread overview]
Message-ID: <1526495122.08da36149c0b41c64a09369c3eef5e2f5a6fa39c.williamh@OpenRC> (raw)

commit:     08da36149c0b41c64a09369c3eef5e2f5a6fa39c
Author:     William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Wed May 16 18:25:22 2018 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Wed May 16 18:25:22 2018 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=08da3614

rc-service: add --ifstarted and --ifstopped options

 man/rc-service.8    |  8 ++++++++
 src/rc/rc-service.c | 16 +++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/man/rc-service.8 b/man/rc-service.8
index 2834f361..72d5a559 100644
--- a/man/rc-service.8
+++ b/man/rc-service.8
@@ -40,6 +40,14 @@
 .Ar service cmd
 .Op Ar ...
 .Nm
+.Op Fl s , -ifstarted
+.Ar service cmd
+.Op Ar ...
+.Nm
+.Op Fl S , -ifstopped
+.Ar service cmd
+.Op Ar ...
+.Nm
 .Fl e , -exists
 .Ar service
 .Nm

diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index ea69dab5..8b01fa0d 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -29,7 +29,7 @@
 
 const char *applet = NULL;
 const char *extraopts = NULL;
-const char *getoptstring = "cdDe:ilr:INZ" getoptstring_COMMON;
+const char *getoptstring = "cdDe:ilr:INsSZ" getoptstring_COMMON;
 const struct option longopts[] = {
 	{ "debug",     0, NULL, 'd' },
 	{ "nodeps",     0, NULL, 'D' },
@@ -38,6 +38,8 @@ const struct option longopts[] = {
 	{ "ifexists", 0, NULL, 'i' },
 	{ "ifinactive", 0, NULL, 'I' },
 	{ "ifnotstarted", 0, NULL, 'N' },
+	{ "ifstarted", 0, NULL, 's' },
+	{ "ifstopped", 0, NULL, 'S' },
 	{ "list",     0, NULL, 'l' },
 	{ "resolve",  1, NULL, 'r' },
 	{ "dry-run",     0, NULL, 'Z' },
@@ -73,6 +75,8 @@ int main(int argc, char **argv)
 	bool if_exists = false;
 	bool if_inactive = false;
 	bool if_notstarted = false;
+	bool if_started = false;
+	bool if_stopped = false;
 
 	applet = basename_c(argv[0]);
 	/* Ensure that we are only quiet when explicitly told to be */
@@ -124,6 +128,12 @@ int main(int argc, char **argv)
 			free(service);
 			return EXIT_SUCCESS;
 			/* NOTREACHED */
+		case 's':
+			if_started = true;
+			break;
+		case 'S':
+			if_stopped = true;
+			break;
 		case 'Z':
 			setenv("IN_DRYRUN", "yes", 1);
 			break;
@@ -148,6 +158,10 @@ int main(int argc, char **argv)
 		return 0;
 	if (if_notstarted && (state & RC_SERVICE_STARTED))
 		return 0;
+	if (if_started && ! (state & RC_SERVICE_STARTED))
+		return 0;
+	if (if_stopped && ! (state & RC_SERVICE_STOPPED))
+		return 0;
 	*argv = service;
 	execv(*argv, argv);
 	eerrorx("%s: %s", applet, strerror(errno));


             reply	other threads:[~2018-05-16 18:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16 18:27 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
2017-12-04 23:31 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=1526495122.08da36149c0b41c64a09369c3eef5e2f5a6fa39c.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