aboutsummaryrefslogtreecommitdiff
path: root/debianutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-04-30 13:58:31 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-04-30 13:58:31 +0000
commite06122666841ab4a6fc3bbea7ca9a94686f2fd88 (patch)
tree123c7168a582b8fb8606d0ab701761b019714b5d /debianutils
parent812870a2e7a00211b0658ebe05e3cee2154c9790 (diff)
downloadbusybox-w32-e06122666841ab4a6fc3bbea7ca9a94686f2fd88.tar.gz
busybox-w32-e06122666841ab4a6fc3bbea7ca9a94686f2fd88.tar.bz2
busybox-w32-e06122666841ab4a6fc3bbea7ca9a94686f2fd88.zip
start_stop_daemon: use existing global variable
start_stop_daemon_main 976 959 -17
Diffstat (limited to 'debianutils')
-rw-r--r--debianutils/start_stop_daemon.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 4e816bd19..6919fe2a7 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -22,6 +22,24 @@ struct pid_list {
22 pid_t pid; 22 pid_t pid;
23}; 23};
24 24
25enum {
26 CTX_STOP = (1 << 0),
27 CTX_START = (1 << 1),
28 OPT_BACKGROUND = (1 << 2), // -b
29 OPT_QUIET = (1 << 3), // -q
30 OPT_MAKEPID = (1 << 4), // -m
31 OPT_a = (1 << 5), // -a
32 OPT_n = (1 << 6), // -n
33 OPT_s = (1 << 7), // -s
34 OPT_u = (1 << 8), // -u
35 OPT_c = (1 << 9), // -c
36 OPT_x = (1 << 10), // -x
37 OPT_p = (1 << 11), // -p
38 OPT_OKNODO = (1 << 12) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -o
39 OPT_VERBOSE = (1 << 13) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -v
40 OPT_NICELEVEL = (1 << 14) * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -N
41};
42#define QUIET (option_mask32 & OPT_QUIET)
25 43
26struct globals { 44struct globals {
27 struct pid_list *found; 45 struct pid_list *found;
@@ -30,7 +48,6 @@ struct globals {
30 char *execname; 48 char *execname;
31 char *pidfile; 49 char *pidfile;
32 int user_id; 50 int user_id;
33 smallint quiet;
34 smallint signal_nr; 51 smallint signal_nr;
35 struct stat execstat; 52 struct stat execstat;
36}; 53};
@@ -41,7 +58,6 @@ struct globals {
41#define execname (G.execname ) 58#define execname (G.execname )
42#define pidfile (G.pidfile ) 59#define pidfile (G.pidfile )
43#define user_id (G.user_id ) 60#define user_id (G.user_id )
44#define quiet (G.quiet )
45#define signal_nr (G.signal_nr ) 61#define signal_nr (G.signal_nr )
46#define execstat (G.execstat ) 62#define execstat (G.execstat )
47#define INIT_G() \ 63#define INIT_G() \
@@ -180,7 +196,7 @@ static int do_stop(void)
180 bb_error_msg_and_die("internal error, please report"); 196 bb_error_msg_and_die("internal error, please report");
181 197
182 if (!found) { 198 if (!found) {
183 if (!quiet) 199 if (!QUIET)
184 printf("no %s found; none killed\n", what); 200 printf("no %s found; none killed\n", what);
185 killed = -1; 201 killed = -1;
186 goto ret; 202 goto ret;
@@ -193,7 +209,7 @@ static int do_stop(void)
193 bb_perror_msg("warning: killing process %u", p->pid); 209 bb_perror_msg("warning: killing process %u", p->pid);
194 } 210 }
195 } 211 }
196 if (!quiet && killed) { 212 if (!QUIET && killed) {
197 printf("stopped %s (pid", what); 213 printf("stopped %s (pid", what);
198 for (p = found; p; p = p->next) 214 for (p = found; p; p = p->next)
199 if (p->pid < 0) 215 if (p->pid < 0)
@@ -231,24 +247,6 @@ static const char start_stop_daemon_longopts[] ALIGN1 =
231 ; 247 ;
232#endif 248#endif
233 249
234enum {
235 CTX_STOP = 0x1,
236 CTX_START = 0x2,
237 OPT_BACKGROUND = 0x4, // -b
238 OPT_QUIET = 0x8, // -q
239 OPT_MAKEPID = 0x10, // -m
240 OPT_a = 0x20, // -a
241 OPT_n = 0x40, // -n
242 OPT_s = 0x80, // -s
243 OPT_u = 0x100, // -u
244 OPT_c = 0x200, // -c
245 OPT_x = 0x400, // -x
246 OPT_p = 0x800, // -p
247 OPT_OKNODO = 0x1000 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -o
248 OPT_VERBOSE = 0x2000 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -v
249 OPT_NICELEVEL = 0x4000 * ENABLE_FEATURE_START_STOP_DAEMON_FANCY, // -N
250};
251
252int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 250int start_stop_daemon_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
253int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv) 251int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
254{ 252{
@@ -268,8 +266,13 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
268 applet_long_options = start_stop_daemon_longopts; 266 applet_long_options = start_stop_daemon_longopts;
269#endif 267#endif
270 268
271 /* Check required one context option was given */ 269 /* -K or -S is required; they are mutually exclusive */
272 opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa"; 270 /* -p is required if -m is given */
271 /* -xpun (at least one) is required if -K is given */
272 /* -xa (at least one) is required if -S is given */
273 /* -q turns off -v */
274 opt_complementary = "K:S:K--S:S--K:m?p:K?xpun:S?xa"
275 USE_FEATURE_START_STOP_DAEMON_FANCY("q-v");
273 opt = getopt32(argv, "KSbqma:n:s:u:c:x:p:" 276 opt = getopt32(argv, "KSbqma:n:s:u:c:x:p:"
274 USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:"), 277 USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:"),
275// USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"), 278// USE_FEATURE_START_STOP_DAEMON_FANCY("ovN:R:"),
@@ -278,8 +281,6 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
278// USE_FEATURE_START_STOP_DAEMON_FANCY(,&retry_arg) 281// USE_FEATURE_START_STOP_DAEMON_FANCY(,&retry_arg)
279 ); 282 );
280 283
281 quiet = (opt & OPT_QUIET) && !(opt & OPT_VERBOSE);
282
283 if (opt & OPT_s) { 284 if (opt & OPT_s) {
284 signal_nr = get_signum(signame); 285 signal_nr = get_signum(signame);
285 if (signal_nr < 0) bb_show_usage(); 286 if (signal_nr < 0) bb_show_usage();
@@ -311,7 +312,7 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
311 } 312 }
312 313
313 if (found) { 314 if (found) {
314 if (!quiet) 315 if (!QUIET)
315 printf("%s already running\n%d\n", execname, found->pid); 316 printf("%s already running\n%d\n", execname, found->pid);
316 return !(opt & OPT_OKNODO); 317 return !(opt & OPT_OKNODO);
317 } 318 }