diff options
author | Roy Marples <roy@marples.name> | 2007-12-18 18:01:05 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-12-18 18:01:05 +0000 |
commit | 47887ac7c340639c9c6b7bf4379a1940f3e01b6c (patch) | |
tree | c5febe0cf89b4088aa5ce3b648b153cb85752a8b /src/runscript.c | |
parent | 437363a3449423173bc94746a122fbf3b4cf254c (diff) |
usage now requires a global applet var instead of a define, don't prefix describe output and use generic usage for runscript.
Diffstat (limited to 'src/runscript.c')
-rw-r--r-- | src/runscript.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/runscript.c b/src/runscript.c index 108512ae..c52b33ea 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -1024,6 +1024,7 @@ static void svc_restart (bool deps) #include "_usage.h" #define getoptstring "dDsv" getoptstring_COMMON +#define extraopts "stop | start | restart | describe | zap" static struct option longopts[] = { { "debug", 0, NULL, 'd'}, { "ifstarted", 0, NULL, 's'}, @@ -1031,15 +1032,11 @@ static struct option longopts[] = { longopts_COMMON }; static const char * const longopts_help[] = { - "", - "", - "", + "set xtrace when running the script", + "only run commands when started", + "ignore dependencies", longopts_help_COMMON }; -#undef case_RC_COMMON_getopt_case_h -#define case_RC_COMMON_getopt_case_h \ - execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); \ -eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", applet, strerror (errno)); #include "_usage.c" int runscript (int argc, char **argv) @@ -1053,13 +1050,15 @@ int runscript (int argc, char **argv) char *svc; /* Show help if insufficient args */ - if (argc < 2) { - execl (RCSCRIPT_HELP, RCSCRIPT_HELP, (char *) NULL); - eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", argv[0], - strerror (errno)); + if (argc < 2 || ! exists (argv[1])) { + fprintf (stderr, "runscript is not meant to be to run directly\n"); + exit (EXIT_FAILURE); } applet = xstrdup (basename (argv[1])); + if (argc < 3) + usage (EXIT_FAILURE); + if (*argv[1] == '/') service = xstrdup (argv[1]); else { @@ -1075,14 +1074,6 @@ int runscript (int argc, char **argv) /* Change dir to / to ensure all init scripts don't use stuff in pwd */ chdir ("/"); - /* Show help if insufficient args */ - if (argc < 3) { - setenv ("SVCNAME", applet, 1); - execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); - eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", - applet, strerror (errno)); - } - #ifdef __linux__ /* coldplug events can trigger init scripts, but we don't want to run them until after rc sysinit has completed so we punt them to the boot runlevel */ @@ -1240,7 +1231,12 @@ int runscript (int argc, char **argv) doneone = true; if (strcmp (optarg, "describe") == 0) { + char *save = prefix; + + eprefix (NULL); + prefix = NULL; svc_exec (optarg, NULL); + eprefix (save); } else if (strcmp (optarg, "help") == 0) { execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, "help", (char *) NULL); eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", |