diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-26 16:08:02 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-26 16:08:02 +0000 |
| commit | 04bb2d2d06a87b08743ee997fcd8465bfed809d1 (patch) | |
| tree | 6429a4149946aade820c3b1ce8a667cfb83fb8f1 /debianutils | |
| parent | d4f0b9476af1dc9dc20a1c2ca0bbcf9a16288851 (diff) | |
| download | busybox-w32-04bb2d2d06a87b08743ee997fcd8465bfed809d1.tar.gz busybox-w32-04bb2d2d06a87b08743ee997fcd8465bfed809d1.tar.bz2 busybox-w32-04bb2d2d06a87b08743ee997fcd8465bfed809d1.zip | |
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.c | 49 |
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 @@ | |||
| 18 | #define WANT_PIDFILE 1 | 18 | #define WANT_PIDFILE 1 |
| 19 | #include "libbb.h" | 19 | #include "libbb.h" |
| 20 | 20 | ||
| 21 | static int signal_nr = 15; | ||
| 22 | static int user_id = -1; | ||
| 23 | static char *userspec; | ||
| 24 | static char *cmdname; | ||
| 25 | static char *execname; | ||
| 26 | static char *pidfile; | ||
| 27 | static smallint quiet; | ||
| 28 | |||
| 29 | struct pid_list { | 21 | struct pid_list { |
| 30 | struct pid_list *next; | 22 | struct pid_list *next; |
| 31 | pid_t pid; | 23 | pid_t pid; |
| 32 | }; | 24 | }; |
| 33 | 25 | ||
| 34 | static struct pid_list *found; | 26 | |
| 27 | struct globals { | ||
| 28 | struct pid_list *found; | ||
| 29 | char *userspec; | ||
| 30 | char *cmdname; | ||
| 31 | char *execname; | ||
| 32 | char *pidfile; | ||
| 33 | int user_id; | ||
| 34 | smallint quiet; | ||
| 35 | smallint signal_nr; | ||
| 36 | }; | ||
| 37 | #define G (*(struct globals*)&bb_common_bufsiz1) | ||
| 38 | #define found (G.found ) | ||
| 39 | #define userspec (G.userspec ) | ||
| 40 | #define cmdname (G.cmdname ) | ||
| 41 | #define execname (G.execname ) | ||
| 42 | #define pidfile (G.pidfile ) | ||
| 43 | #define user_id (G.user_id ) | ||
| 44 | #define quiet (G.quiet ) | ||
| 45 | #define signal_nr (G.signal_nr ) | ||
| 46 | #define INIT_G() \ | ||
| 47 | do { \ | ||
| 48 | user_id = -1; \ | ||
| 49 | signal_nr = 15; \ | ||
| 50 | } while (0) | ||
| 51 | |||
| 35 | 52 | ||
| 36 | static int pid_is_exec(pid_t pid, const char *name) | 53 | static int pid_is_exec(pid_t pid, const char *name) |
| 37 | { | 54 | { |
| @@ -43,8 +60,8 @@ static int pid_is_exec(pid_t pid, const char *name) | |||
| 43 | n = strlen(name) + 1; | 60 | n = strlen(name) + 1; |
| 44 | execbuf = xzalloc(n + 1); | 61 | execbuf = xzalloc(n + 1); |
| 45 | readlink(buf, execbuf, n); | 62 | readlink(buf, execbuf, n); |
| 46 | 63 | /* if readlink fails because link target is longer than strlen(name), | |
| 47 | /* if readlink fails, execbuf still contains "" */ | 64 | * execbuf still contains "", and strcmp will return !0. */ |
| 48 | n = strcmp(execbuf, name); | 65 | n = strcmp(execbuf, name); |
| 49 | if (ENABLE_FEATURE_CLEAN_UP) | 66 | if (ENABLE_FEATURE_CLEAN_UP) |
| 50 | free(execbuf); | 67 | free(execbuf); |
| @@ -121,7 +138,7 @@ static void do_procinit(void) | |||
| 121 | { | 138 | { |
| 122 | DIR *procdir; | 139 | DIR *procdir; |
| 123 | struct dirent *entry; | 140 | struct dirent *entry; |
| 124 | int foundany, pid; | 141 | int pid; |
| 125 | 142 | ||
| 126 | if (pidfile) { | 143 | if (pidfile) { |
| 127 | do_pidfile(); | 144 | do_pidfile(); |
| @@ -130,16 +147,15 @@ static void do_procinit(void) | |||
| 130 | 147 | ||
| 131 | procdir = xopendir("/proc"); | 148 | procdir = xopendir("/proc"); |
| 132 | 149 | ||
| 133 | foundany = 0; | 150 | pid = 0; |
| 134 | while ((entry = readdir(procdir)) != NULL) { | 151 | while ((entry = readdir(procdir)) != NULL) { |
| 135 | pid = bb_strtou(entry->d_name, NULL, 10); | 152 | pid = bb_strtou(entry->d_name, NULL, 10); |
| 136 | if (errno) | 153 | if (errno) |
| 137 | continue; | 154 | continue; |
| 138 | foundany++; | ||
| 139 | check(pid); | 155 | check(pid); |
| 140 | } | 156 | } |
| 141 | closedir(procdir); | 157 | closedir(procdir); |
| 142 | if (!foundany) | 158 | if (!pid) |
| 143 | bb_error_msg_and_die("nothing in /proc - not mounted?"); | 159 | bb_error_msg_and_die("nothing in /proc - not mounted?"); |
| 144 | } | 160 | } |
| 145 | 161 | ||
| @@ -246,6 +262,9 @@ int start_stop_daemon_main(int argc, char **argv) | |||
| 246 | // int retries = -1; | 262 | // int retries = -1; |
| 247 | char *opt_N; | 263 | char *opt_N; |
| 248 | #endif | 264 | #endif |
| 265 | |||
| 266 | INIT_G(); | ||
| 267 | |||
| 249 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS | 268 | #if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS |
| 250 | applet_long_options = start_stop_daemon_longopts; | 269 | applet_long_options = start_stop_daemon_longopts; |
| 251 | #endif | 270 | #endif |
