aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-05-01 08:38:57 +0100
committerRoy Marples <roy@marples.name>2009-05-01 08:38:57 +0100
commitfb051bf81ac698d0618b611abc7120c32da467c3 (patch)
tree26ec8023cd3c4e4f463fc710848c21e9f864473d /src
parentcaf29a6480e56399d1fa18c5d7bfe32f47f1c1f4 (diff)
Add -i, --ifexists so that we can do this
rc-sercice -i foo -- restart instead of this rc-service -e foo && rc-service foo -- restart
Diffstat (limited to 'src')
-rw-r--r--src/rc/rc-service.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/rc/rc-service.c b/src/rc/rc-service.c
index 82d4cf22..84789f3c 100644
--- a/src/rc/rc-service.c
+++ b/src/rc/rc-service.c
@@ -43,15 +43,17 @@
extern char *applet;
#include "_usage.h"
-#define getoptstring "e:lr:" getoptstring_COMMON
+#define getoptstring "e:ilr:" getoptstring_COMMON
static const struct option longopts[] = {
- { "exists", 1, NULL, 'e' },
- { "list", 0, NULL, 'l' },
- { "resolve", 1, NULL, 'r' },
+ { "exists", 1, NULL, 'e' },
+ { "ifexists", 0, NULL, 'i' },
+ { "list", 0, NULL, 'l' },
+ { "resolve", 1, NULL, 'r' },
longopts_COMMON
};
static const char * const longopts_help[] = {
"tests if the service exists or not",
+ "if the service exsits then run the command",
"list all available services",
"resolve the service name to an init script",
longopts_help_COMMON
@@ -65,6 +67,7 @@ rc_service(int argc, char **argv)
char *service;
RC_STRINGLIST *list;
RC_STRING *s;
+ bool if_exists = false;
/* Ensure that we are only quiet when explicitly told to be */
unsetenv("EINFO_QUIET");
@@ -81,9 +84,12 @@ rc_service(int argc, char **argv)
#endif
return opt;
/* NOTREACHED */
+ case 'i':
+ if_exists = true;
+ break;
case 'l':
list = rc_services_in_runlevel(NULL);
- if (!TAILQ_FIRST(list))
+ if (TAILQ_FIRST(list) == NULL)
return EXIT_FAILURE;
rc_stringlist_sort(&list);
TAILQ_FOREACH(s, list, entries)
@@ -95,7 +101,7 @@ rc_service(int argc, char **argv)
/* NOTREACHED */
case 'r':
service = rc_service_resolve(optarg);
- if (!service)
+ if (service == NULL)
return EXIT_FAILURE;
printf("%s\n", service);
#ifdef DEBUG_MEMORY
@@ -110,10 +116,13 @@ rc_service(int argc, char **argv)
argc -= optind;
argv += optind;
- if (!*argv)
+ if (*argv == NULL)
eerrorx("%s: you need to specify a service", applet);
- if (!(service = rc_service_resolve(*argv)))
+ if ((service = rc_service_resolve(*argv)) == NULL) {
+ if (if_exists)
+ return 0;
eerrorx("%s: service `%s' does not exist", applet, *argv);
+ }
*argv = service;
execv(*argv, argv);
eerrorx("%s: %s", applet, strerror(errno));