summaryrefslogtreecommitdiff
path: root/debianutils/start_stop_daemon.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-01-22 09:04:58 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-01-22 09:04:58 +0000
commit8d441783817d909b7ba3c0148d7deb121e9791c8 (patch)
tree87e739be605dfb6660cb5e25124728c95f37eb63 /debianutils/start_stop_daemon.c
parent85c5152cb874fdac2e59072b6d958af18965182a (diff)
downloadbusybox-w32-8d441783817d909b7ba3c0148d7deb121e9791c8.tar.gz
busybox-w32-8d441783817d909b7ba3c0148d7deb121e9791c8.tar.bz2
busybox-w32-8d441783817d909b7ba3c0148d7deb121e9791c8.zip
Check one and only one of start, stop are given.
Remove some global variables. #define some getopt values.
Diffstat (limited to 'debianutils/start_stop_daemon.c')
-rw-r--r--debianutils/start_stop_daemon.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index c31bba6dd..082fe6070 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -21,15 +21,11 @@
21#include "busybox.h" 21#include "busybox.h"
22#include "pwd_.h" 22#include "pwd_.h"
23 23
24static int start = 0;
25static int stop = 0;
26static int fork_before_exec = 0;
27static int signal_nr = 15; 24static int signal_nr = 15;
28static int user_id = -1; 25static int user_id = -1;
29static char *userspec = NULL; 26static char *userspec = NULL;
30static char *cmdname = NULL; 27static char *cmdname = NULL;
31static char *execname = NULL; 28static char *execname = NULL;
32static char *startas = NULL;
33 29
34typedef struct pid_list { 30typedef struct pid_list {
35 struct pid_list *next; 31 struct pid_list *next;
@@ -195,35 +191,40 @@ static const struct option ssd_long_options[] = {
195 { 0, 0, 0, 0 } 191 { 0, 0, 0, 0 }
196}; 192};
197 193
194#define SSD_CTX_STOP 1
195#define SSD_CTX_START 2
196#define SSD_OPT_BACKGROUND 4
197
198int 198int
199start_stop_daemon_main(int argc, char **argv) 199start_stop_daemon_main(int argc, char **argv)
200{ 200{
201 int flags; 201 unsigned long opt;
202 char *signame = NULL; 202 char *signame = NULL;
203 char *startas = NULL;
204
203 bb_applet_long_options = ssd_long_options; 205 bb_applet_long_options = ssd_long_options;
204 206
205 flags = bb_getopt_ulflags(argc, argv, "KSba:n:s:u:x:", 207 bb_opt_complementaly = "K~S";
208 opt = bb_getopt_ulflags(argc, argv, "KSba:n:s:u:x:",
206 &startas, &cmdname, &signame, &userspec, &execname); 209 &startas, &cmdname, &signame, &userspec, &execname);
207 210
208 /* Be sneaky and avoid branching */ 211 /* Check one and only one context option was given */
209 stop = (flags & 1); 212 if ((opt & 0x80000000UL) ||
210 start = (flags & 2); 213 (opt & (SSD_CTX_STOP | SSD_CTX_START)) == 0) {
211 fork_before_exec = (flags & 4); 214 bb_show_usage();
215 }
212 216
213 if (signame) { 217 if (signame) {
214 signal_nr = bb_xgetlarg(signame, 10, 0, NSIG); 218 signal_nr = bb_xgetlarg(signame, 10, 0, NSIG);
215 } 219 }
216 220
217 if (start == stop)
218 bb_error_msg_and_die ("need exactly one of -S or -K");
219
220 if (!execname && !userspec) 221 if (!execname && !userspec)
221 bb_error_msg_and_die ("need at least one of -x or -u"); 222 bb_error_msg_and_die ("need at least one of -x or -u");
222 223
223 if (!startas) 224 if (!startas)
224 startas = execname; 225 startas = execname;
225 226
226 if (start && !startas) 227 if ((opt & SSD_CTX_START) && !startas)
227 bb_error_msg_and_die ("-S needs -x or -a"); 228 bb_error_msg_and_die ("-S needs -x or -a");
228 229
229 argc -= optind; 230 argc -= optind;
@@ -234,7 +235,7 @@ start_stop_daemon_main(int argc, char **argv)
234 235
235 do_procfs(); 236 do_procfs();
236 237
237 if (stop) { 238 if (opt & SSD_CTX_STOP) {
238 do_stop(); 239 do_stop();
239 return EXIT_SUCCESS; 240 return EXIT_SUCCESS;
240 } 241 }
@@ -244,7 +245,7 @@ start_stop_daemon_main(int argc, char **argv)
244 return EXIT_SUCCESS; 245 return EXIT_SUCCESS;
245 } 246 }
246 *--argv = startas; 247 *--argv = startas;
247 if (fork_before_exec) { 248 if (opt & SSD_OPT_BACKGROUND) {
248 if (daemon(0, 0) == -1) 249 if (daemon(0, 0) == -1)
249 bb_perror_msg_and_die ("unable to fork"); 250 bb_perror_msg_and_die ("unable to fork");
250 } 251 }
@@ -252,4 +253,3 @@ start_stop_daemon_main(int argc, char **argv)
252 execv(startas, argv); 253 execv(startas, argv);
253 bb_perror_msg_and_die ("unable to start %s", startas); 254 bb_perror_msg_and_die ("unable to start %s", startas);
254} 255}
255