From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 970F51382C5 for ; Wed, 16 May 2018 18:27:12 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BA450E0814; Wed, 16 May 2018 18:27:10 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 93470E0814 for ; Wed, 16 May 2018 18:27:10 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D697B335C49 for ; Wed, 16 May 2018 18:27:08 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D6B7443 for ; Wed, 16 May 2018 18:27:06 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1526495122.08da36149c0b41c64a09369c3eef5e2f5a6fa39c.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/, man/ X-VCS-Repository: proj/openrc X-VCS-Files: man/rc-service.8 src/rc/rc-service.c X-VCS-Directories: src/rc/ man/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: 08da36149c0b41c64a09369c3eef5e2f5a6fa39c X-VCS-Branch: master Date: Wed, 16 May 2018 18:27:06 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 6acda4bf-068a-41c2-96f6-a8f5a1bcf39f X-Archives-Hash: ba0a2bf584bf97cdc765438dd5bf44b7 commit: 08da36149c0b41c64a09369c3eef5e2f5a6fa39c Author: William Hubbs gmail com> AuthorDate: Wed May 16 18:25:22 2018 +0000 Commit: William Hubbs gentoo 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));