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 678BC139083 for ; Mon, 4 Dec 2017 23:31:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 726B7E0DF9; Mon, 4 Dec 2017 23:31:36 +0000 (UTC) Received: from smtp.gentoo.org (mail.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 502D9E0DF9 for ; Mon, 4 Dec 2017 23:31:36 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (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 09FEE33BF05 for ; Mon, 4 Dec 2017 23:31:35 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C1EB9AC4C for ; Mon, 4 Dec 2017 23:31:33 +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: <1512429437.a2447dfb420cbd97a65cc085404c031d42cb3dfb.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: man/ src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: a2447dfb420cbd97a65cc085404c031d42cb3dfb X-VCS-Branch: master Date: Mon, 4 Dec 2017 23:31:33 +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: d3e253a6-f6b3-46be-88ac-3ccb2959c3ec X-Archives-Hash: 7610b4b0c4ef2f479914cc64613fc5da commit: a2447dfb420cbd97a65cc085404c031d42cb3dfb Author: William Hubbs gmail com> AuthorDate: Mon Dec 4 23:17:17 2017 +0000 Commit: William Hubbs gentoo 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))