From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-860195-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 105CD58973 for <garchives@archives.gentoo.org>; Thu, 28 Jan 2016 23:55:06 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 941CF21C050; Thu, 28 Jan 2016 23:55:05 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 16DEB21C050 for <gentoo-commits@lists.gentoo.org>; Thu, 28 Jan 2016 23:55:05 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1ABF8340AF2 for <gentoo-commits@lists.gentoo.org>; Thu, 28 Jan 2016 19:08:29 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 614EE842 for <gentoo-commits@lists.gentoo.org>; Thu, 28 Jan 2016 19:08:27 +0000 (UTC) From: "William Hubbs" <williamh@gentoo.org> 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" <williamh@gentoo.org> Message-ID: <1454007431.8a7e4d38a74c714e1a532e1b7a53fd2a5c528b63.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: man/, src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: man/rc-service.8 src/rc/rc-service.c X-VCS-Directories: man/ src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: 8a7e4d38a74c714e1a532e1b7a53fd2a5c528b63 X-VCS-Branch: master Date: Thu, 28 Jan 2016 19:08:27 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 0f408325-8c23-4045-be26-825628a3b019 X-Archives-Hash: 62f0a5d74abffd8df582bd435e98c527 commit: 8a7e4d38a74c714e1a532e1b7a53fd2a5c528b63 Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com> AuthorDate: Sun Sep 21 18:54:51 2014 +0000 Commit: William Hubbs <williamh <AT> gentoo <DOT> org> CommitDate: Thu Jan 28 18:57:11 2016 +0000 URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8a7e4d38 rc-service: add --ifinactive and --ifnotstarted flags X-Gentoo-Bug: 523174 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=523174 man/rc-service.8 | 15 +++++++++++++++ src/rc/rc-service.c | 20 +++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/man/rc-service.8 b/man/rc-service.8 index 9260329..80deb5e 100644 --- a/man/rc-service.8 +++ b/man/rc-service.8 @@ -20,6 +20,14 @@ .Ar service cmd .Op Ar ... .Nm +.Op Fl I , -ifinactive +.Ar service cmd +.Op Ar ... +.Nm +.Op Fl N , -ifnotstarted +.Ar service cmd +.Op Ar ... +.Nm .Fl e , -exists .Ar service .Nm @@ -36,6 +44,13 @@ If is given then .Nm returns 0 even if the service does not exist. +If +.Fl I , -ifinactive +or +.Fl N , -ifnotstarted +is given then +.Nm +returns 0 if the service exists but is in the wrong state. .Pp If given the .Fl l , -list diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c index 8e9da44..3fd94b2 100644 --- a/src/rc/rc-service.c +++ b/src/rc/rc-service.c @@ -29,10 +29,12 @@ const char *applet = NULL; const char *extraopts = NULL; -const char *getoptstring = "e:ilr:" getoptstring_COMMON; +const char *getoptstring = "e:ilr:IN" getoptstring_COMMON; const struct option longopts[] = { { "exists", 1, NULL, 'e' }, { "ifexists", 0, NULL, 'i' }, + { "ifinactive", 0, NULL, 'I' }, + { "ifnotstarted", 0, NULL, 'N' }, { "list", 0, NULL, 'l' }, { "resolve", 1, NULL, 'r' }, longopts_COMMON @@ -40,6 +42,8 @@ const struct option longopts[] = { const char * const longopts_help[] = { "tests if the service exists or not", "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", "list all available services", "resolve the service name to an init script", longopts_help_COMMON @@ -56,7 +60,10 @@ int main(int argc, char **argv) char *service; RC_STRINGLIST *list; RC_STRING *s; + RC_SERVICE state; bool if_exists = false; + bool if_inactive = false; + bool if_notstarted = false; applet = basename_c(argv[0]); /* Ensure that we are only quiet when explicitly told to be */ @@ -77,6 +84,12 @@ int main(int argc, char **argv) case 'i': if_exists = true; break; + case 'I': + if_inactive = true; + break; + case 'N': + if_notstarted = true; + break; case 'l': list = rc_services_in_runlevel(NULL); if (TAILQ_FIRST(list) == NULL) @@ -113,6 +126,11 @@ int main(int argc, char **argv) return 0; eerrorx("%s: service `%s' does not exist", applet, *argv); } + state = rc_service_state(*argv); + if (if_inactive && ! (state & RC_SERVICE_INACTIVE)) + return 0; + if (if_notstarted && (state & RC_SERVICE_STARTED)) + return 0; *argv = service; execv(*argv, argv); eerrorx("%s: %s", applet, strerror(errno));