aboutsummaryrefslogtreecommitdiff
path: root/debianutils
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-07-26 09:10:35 +0000
committerEric Andersen <andersen@codepoet.org>2003-07-26 09:10:35 +0000
commitaa820dbc00860a2ddcb7a0205345ffe39c7d18d7 (patch)
treeafcf51f2d16340d0cf2b61ef5b7ec2a9b0ac798f /debianutils
parent480f1533f3f0355089c4e5abc9038d3097d06ab8 (diff)
downloadbusybox-aa820dbc00860a2ddcb7a0205345ffe39c7d18d7.tar.gz
cleanup and add long options
Diffstat (limited to 'debianutils')
-rw-r--r--debianutils/start_stop_daemon.c100
1 files changed, 41 insertions, 59 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index a1c2c21c2..482078e6e 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -16,6 +16,7 @@
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
+#include <getopt.h>
#include "busybox.h"
#include "pwd_.h"
@@ -25,8 +26,8 @@ static int stop = 0;
static int fork_before_exec = 0;
static int signal_nr = 15;
static int user_id = -1;
-static const char *userspec = NULL;
-static const char *cmdname = NULL;
+static char *userspec = NULL;
+static char *cmdname = NULL;
static char *execname = NULL;
static char *startas = NULL;
@@ -48,62 +49,6 @@ push(int pid)
found = p;
}
-
-static void
-parse_options(int argc, char * const *argv)
-{
-
- int c;
-
- for (;;) {
- c = getopt (argc, argv, "a:n:s:u:x:KSb");
- if (c == EOF)
- break;
- switch (c) {
- case 'K':
- stop = 1;
- break;
- case 'S':
- start = 1;
- break;
- case 'a':
- startas = optarg;
- break;
- case 'n':
- cmdname = optarg;
- break;
- case 's':
- if (sscanf(optarg, "%d", &signal_nr) != 1)
- bb_error_msg_and_die ("-s takes a numeric argument");
- break;
- case 'u':
- userspec = optarg;
- break;
- case 'x':
- execname = optarg;
- break;
- case 'b':
- fork_before_exec = 1;
- break;
- default:
- bb_show_usage();
- }
- }
-
- if (start == stop)
- bb_error_msg_and_die ("need one of -S or -K");
-
- if (!execname && !userspec)
- bb_error_msg_and_die ("need at least one of -x or -u");
-
- if (!startas)
- startas = execname;
-
- if (start && !startas)
- bb_error_msg_and_die ("-S needs -x or -a");
-}
-
-
static int
pid_is_exec(int pid, const char *exec)
{
@@ -238,10 +183,47 @@ do_stop(void)
}
+static const struct option ssd_long_options[] = {
+ { "stop", 0, NULL, 'K' },
+ { "start", 0, NULL, 'S' },
+ { "background", 0, NULL, 'b' },
+ { "startas", 1, NULL, 'a' },
+ { "name", 1, NULL, 'n' },
+ { "signal", 1, NULL, 's' },
+ { "user", 1, NULL, 'u' },
+ { "exec", 1, NULL, 'x' },
+ { 0, 0, 0, 0 }
+};
+
int
start_stop_daemon_main(int argc, char **argv)
{
- parse_options(argc, argv);
+ int flags;
+ char *signame;
+ bb_applet_long_options = ssd_long_options;
+
+ flags = bb_getopt_ulflags(argc, argv, "KSba:n:s:u:x:",
+ &startas, &cmdname, &signame, &userspec, &execname);
+
+ /* Be sneaky and avoid branching */
+ stop = (flags & 1);
+ start = (flags & 2);
+ fork_before_exec = (flags & 4);
+
+ signal_nr = bb_xgetlarg(signame, 10, 0, NSIG);
+
+ if (start == stop)
+ bb_error_msg_and_die ("need exactly one of -S or -K");
+
+ if (!execname && !userspec)
+ bb_error_msg_and_die ("need at least one of -x or -u");
+
+ if (!startas)
+ startas = execname;
+
+ if (start && !startas)
+ bb_error_msg_and_die ("-S needs -x or -a");
+
argc -= optind;
argv += optind;