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-w32-aa820dbc00860a2ddcb7a0205345ffe39c7d18d7.tar.gz
busybox-w32-aa820dbc00860a2ddcb7a0205345ffe39c7d18d7.tar.bz2
busybox-w32-aa820dbc00860a2ddcb7a0205345ffe39c7d18d7.zip
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 @@
16#include <sys/stat.h> 16#include <sys/stat.h>
17#include <dirent.h> 17#include <dirent.h>
18#include <unistd.h> 18#include <unistd.h>
19#include <getopt.h>
19 20
20#include "busybox.h" 21#include "busybox.h"
21#include "pwd_.h" 22#include "pwd_.h"
@@ -25,8 +26,8 @@ static int stop = 0;
25static int fork_before_exec = 0; 26static int fork_before_exec = 0;
26static int signal_nr = 15; 27static int signal_nr = 15;
27static int user_id = -1; 28static int user_id = -1;
28static const char *userspec = NULL; 29static char *userspec = NULL;
29static const char *cmdname = NULL; 30static char *cmdname = NULL;
30static char *execname = NULL; 31static char *execname = NULL;
31static char *startas = NULL; 32static char *startas = NULL;
32 33
@@ -48,62 +49,6 @@ push(int pid)
48 found = p; 49 found = p;
49} 50}
50 51
51
52static void
53parse_options(int argc, char * const *argv)
54{
55
56 int c;
57
58 for (;;) {
59 c = getopt (argc, argv, "a:n:s:u:x:KSb");
60 if (c == EOF)
61 break;
62 switch (c) {
63 case 'K':
64 stop = 1;
65 break;
66 case 'S':
67 start = 1;
68 break;
69 case 'a':
70 startas = optarg;
71 break;
72 case 'n':
73 cmdname = optarg;
74 break;
75 case 's':
76 if (sscanf(optarg, "%d", &signal_nr) != 1)
77 bb_error_msg_and_die ("-s takes a numeric argument");
78 break;
79 case 'u':
80 userspec = optarg;
81 break;
82 case 'x':
83 execname = optarg;
84 break;
85 case 'b':
86 fork_before_exec = 1;
87 break;
88 default:
89 bb_show_usage();
90 }
91 }
92
93 if (start == stop)
94 bb_error_msg_and_die ("need one of -S or -K");
95
96 if (!execname && !userspec)
97 bb_error_msg_and_die ("need at least one of -x or -u");
98
99 if (!startas)
100 startas = execname;
101
102 if (start && !startas)
103 bb_error_msg_and_die ("-S needs -x or -a");
104}
105
106
107static int 52static int
108pid_is_exec(int pid, const char *exec) 53pid_is_exec(int pid, const char *exec)
109{ 54{
@@ -238,10 +183,47 @@ do_stop(void)
238} 183}
239 184
240 185
186static const struct option ssd_long_options[] = {
187 { "stop", 0, NULL, 'K' },
188 { "start", 0, NULL, 'S' },
189 { "background", 0, NULL, 'b' },
190 { "startas", 1, NULL, 'a' },
191 { "name", 1, NULL, 'n' },
192 { "signal", 1, NULL, 's' },
193 { "user", 1, NULL, 'u' },
194 { "exec", 1, NULL, 'x' },
195 { 0, 0, 0, 0 }
196};
197
241int 198int
242start_stop_daemon_main(int argc, char **argv) 199start_stop_daemon_main(int argc, char **argv)
243{ 200{
244 parse_options(argc, argv); 201 int flags;
202 char *signame;
203 bb_applet_long_options = ssd_long_options;
204
205 flags = bb_getopt_ulflags(argc, argv, "KSba:n:s:u:x:",
206 &startas, &cmdname, &signame, &userspec, &execname);
207
208 /* Be sneaky and avoid branching */
209 stop = (flags & 1);
210 start = (flags & 2);
211 fork_before_exec = (flags & 4);
212
213 signal_nr = bb_xgetlarg(signame, 10, 0, NSIG);
214
215 if (start == stop)
216 bb_error_msg_and_die ("need exactly one of -S or -K");
217
218 if (!execname && !userspec)
219 bb_error_msg_and_die ("need at least one of -x or -u");
220
221 if (!startas)
222 startas = execname;
223
224 if (start && !startas)
225 bb_error_msg_and_die ("-S needs -x or -a");
226
245 argc -= optind; 227 argc -= optind;
246 argv += optind; 228 argv += optind;
247 229