aboutsummaryrefslogtreecommitdiff
path: root/debianutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-26 16:08:02 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-26 16:08:02 +0000
commit04bb2d2d06a87b08743ee997fcd8465bfed809d1 (patch)
tree6429a4149946aade820c3b1ce8a667cfb83fb8f1 /debianutils
parentd4f0b9476af1dc9dc20a1c2ca0bbcf9a16288851 (diff)
downloadbusybox-04bb2d2d06a87b08743ee997fcd8465bfed809d1.tar.gz
start_stop_daemon: stop using data/bss
function old new delta start_stop_daemon_main 749 770 +21 do_procinit 184 185 +1 quiet 1 - -1 userspec 4 - -4 user_id 4 - -4 signal_nr 4 - -4 pidfile 4 - -4 found 4 - -4 execname 4 - -4 cmdname 4 - -4 ------------------------------------------------------------------------------ (add/remove: 0/8 grow/shrink: 2/0 up/down: 22/-29) Total: -7 bytes
Diffstat (limited to 'debianutils')
-rw-r--r--debianutils/start_stop_daemon.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 6860bab6b..6f4b6b2bb 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -18,20 +18,37 @@
#define WANT_PIDFILE 1
#include "libbb.h"
-static int signal_nr = 15;
-static int user_id = -1;
-static char *userspec;
-static char *cmdname;
-static char *execname;
-static char *pidfile;
-static smallint quiet;
-
struct pid_list {
struct pid_list *next;
pid_t pid;
};
-static struct pid_list *found;
+
+struct globals {
+ struct pid_list *found;
+ char *userspec;
+ char *cmdname;
+ char *execname;
+ char *pidfile;
+ int user_id;
+ smallint quiet;
+ smallint signal_nr;
+};
+#define G (*(struct globals*)&bb_common_bufsiz1)
+#define found (G.found )
+#define userspec (G.userspec )
+#define cmdname (G.cmdname )
+#define execname (G.execname )
+#define pidfile (G.pidfile )
+#define user_id (G.user_id )
+#define quiet (G.quiet )
+#define signal_nr (G.signal_nr )
+#define INIT_G() \
+ do { \
+ user_id = -1; \
+ signal_nr = 15; \
+ } while (0)
+
static int pid_is_exec(pid_t pid, const char *name)
{
@@ -43,8 +60,8 @@ static int pid_is_exec(pid_t pid, const char *name)
n = strlen(name) + 1;
execbuf = xzalloc(n + 1);
readlink(buf, execbuf, n);
-
- /* if readlink fails, execbuf still contains "" */
+ /* if readlink fails because link target is longer than strlen(name),
+ * execbuf still contains "", and strcmp will return !0. */
n = strcmp(execbuf, name);
if (ENABLE_FEATURE_CLEAN_UP)
free(execbuf);
@@ -121,7 +138,7 @@ static void do_procinit(void)
{
DIR *procdir;
struct dirent *entry;
- int foundany, pid;
+ int pid;
if (pidfile) {
do_pidfile();
@@ -130,16 +147,15 @@ static void do_procinit(void)
procdir = xopendir("/proc");
- foundany = 0;
+ pid = 0;
while ((entry = readdir(procdir)) != NULL) {
pid = bb_strtou(entry->d_name, NULL, 10);
if (errno)
continue;
- foundany++;
check(pid);
}
closedir(procdir);
- if (!foundany)
+ if (!pid)
bb_error_msg_and_die("nothing in /proc - not mounted?");
}
@@ -246,6 +262,9 @@ int start_stop_daemon_main(int argc, char **argv)
// int retries = -1;
char *opt_N;
#endif
+
+ INIT_G();
+
#if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS
applet_long_options = start_stop_daemon_longopts;
#endif