diff options
| author | Eric Andersen <andersen@codepoet.org> | 2001-10-31 09:55:39 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2001-10-31 09:55:39 +0000 |
| commit | 950d8b496f39c8474ef1944f18de4e52ca7b412a (patch) | |
| tree | 7d2cc6a9357fbd6398e65535867cb72f9eb8cfcd /debianutils | |
| parent | 2c669dd108cacb64054a57afb84d2d81e1872c97 (diff) | |
| download | busybox-w32-950d8b496f39c8474ef1944f18de4e52ca7b412a.tar.gz busybox-w32-950d8b496f39c8474ef1944f18de4e52ca7b412a.tar.bz2 busybox-w32-950d8b496f39c8474ef1944f18de4e52ca7b412a.zip | |
patch from vodz:
I reduce 148 bytes from start_stop_daemon.c code. Also reduced
memory allocated.
Diffstat (limited to 'debianutils')
| -rw-r--r-- | debianutils/start_stop_daemon.c | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index f8b2d936c..c6b704329 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
| @@ -28,25 +28,23 @@ static const char *userspec = NULL; | |||
| 28 | static const char *cmdname = NULL; | 28 | static const char *cmdname = NULL; |
| 29 | static char *execname = NULL; | 29 | static char *execname = NULL; |
| 30 | static char *startas = NULL; | 30 | static char *startas = NULL; |
| 31 | static const char *progname = ""; | ||
| 32 | 31 | ||
| 33 | struct pid_list { | 32 | typedef struct pid_list { |
| 34 | struct pid_list *next; | 33 | struct pid_list *next; |
| 35 | int pid; | 34 | int pid; |
| 36 | }; | 35 | } pid_list; |
| 37 | 36 | ||
| 38 | static struct pid_list *found = NULL; | 37 | static pid_list *found = NULL; |
| 39 | static struct pid_list *killed = NULL; | ||
| 40 | 38 | ||
| 41 | static void | 39 | static inline void |
| 42 | push(struct pid_list **list, int pid) | 40 | push(int pid) |
| 43 | { | 41 | { |
| 44 | struct pid_list *p; | 42 | pid_list *p; |
| 45 | 43 | ||
| 46 | p = xmalloc(sizeof(*p)); | 44 | p = xmalloc(sizeof(*p)); |
| 47 | p->next = *list; | 45 | p->next = found; |
| 48 | p->pid = pid; | 46 | p->pid = pid; |
| 49 | *list = p; | 47 | found = p; |
| 50 | } | 48 | } |
| 51 | 49 | ||
| 52 | 50 | ||
| @@ -85,7 +83,6 @@ parse_options(int argc, char * const *argv) | |||
| 85 | break; | 83 | break; |
| 86 | default: | 84 | default: |
| 87 | show_usage(); | 85 | show_usage(); |
| 88 | exit(1); | ||
| 89 | } | 86 | } |
| 90 | } | 87 | } |
| 91 | 88 | ||
| @@ -169,7 +166,7 @@ check(int pid) | |||
| 169 | if (cmdname && !pid_is_cmd(pid, cmdname)) { | 166 | if (cmdname && !pid_is_cmd(pid, cmdname)) { |
| 170 | return; | 167 | return; |
| 171 | } | 168 | } |
| 172 | push(&found, pid); | 169 | push(pid); |
| 173 | } | 170 | } |
| 174 | 171 | ||
| 175 | 172 | ||
| @@ -202,7 +199,8 @@ static void | |||
| 202 | do_stop(void) | 199 | do_stop(void) |
| 203 | { | 200 | { |
| 204 | char what[1024]; | 201 | char what[1024]; |
| 205 | struct pid_list *p; | 202 | pid_list *p; |
| 203 | int killed = 0; | ||
| 206 | 204 | ||
| 207 | if (cmdname) | 205 | if (cmdname) |
| 208 | strcpy(what, cmdname); | 206 | strcpy(what, cmdname); |
| @@ -215,19 +213,21 @@ do_stop(void) | |||
| 215 | 213 | ||
| 216 | if (!found) { | 214 | if (!found) { |
| 217 | printf("no %s found; none killed.\n", what); | 215 | printf("no %s found; none killed.\n", what); |
| 218 | exit(0); | 216 | return; |
| 219 | } | 217 | } |
| 220 | for (p = found; p; p = p->next) { | 218 | for (p = found; p; p = p->next) { |
| 221 | if (kill(p->pid, signal_nr) == 0) | 219 | if (kill(p->pid, signal_nr) == 0) { |
| 222 | push(&killed, p->pid); | 220 | p->pid = -p->pid; |
| 223 | else | 221 | killed++; |
| 224 | printf("%s: warning: failed to kill %d: %s\n", | 222 | } else { |
| 225 | progname, p->pid, strerror(errno)); | 223 | perror_msg("warning: failed to kill %d:", p->pid); |
| 224 | } | ||
| 226 | } | 225 | } |
| 227 | if (killed) { | 226 | if (killed) { |
| 228 | printf("stopped %s (pid", what); | 227 | printf("stopped %s (pid", what); |
| 229 | for (p = killed; p; p = p->next) | 228 | for (p = found; p; p = p->next) |
| 230 | printf(" %d", p->pid); | 229 | if(p->pid < 0) |
| 230 | printf(" %d", -p->pid); | ||
| 231 | printf(").\n"); | 231 | printf(").\n"); |
| 232 | } | 232 | } |
| 233 | } | 233 | } |
| @@ -236,33 +236,23 @@ do_stop(void) | |||
| 236 | int | 236 | int |
| 237 | start_stop_daemon_main(int argc, char **argv) | 237 | start_stop_daemon_main(int argc, char **argv) |
| 238 | { | 238 | { |
| 239 | progname = argv[0]; | ||
| 240 | |||
| 241 | parse_options(argc, argv); | 239 | parse_options(argc, argv); |
| 242 | argc -= optind; | 240 | argc -= optind; |
| 243 | argv += optind; | 241 | argv += optind; |
| 244 | 242 | ||
| 245 | if (userspec && sscanf(userspec, "%d", &user_id) != 1) { | 243 | if (userspec && sscanf(userspec, "%d", &user_id) != 1) |
| 246 | struct passwd *pw; | 244 | user_id = my_getpwnam(userspec); |
| 247 | |||
| 248 | pw = getpwnam(userspec); | ||
| 249 | if (!pw) | ||
| 250 | error_msg_and_die ("user `%s' not found\n", userspec); | ||
| 251 | |||
| 252 | user_id = pw->pw_uid; | ||
| 253 | } | ||
| 254 | 245 | ||
| 255 | do_procfs(); | 246 | do_procfs(); |
| 256 | 247 | ||
| 257 | if (stop) { | 248 | if (stop) { |
| 258 | do_stop(); | 249 | do_stop(); |
| 259 | exit(0); | 250 | return EXIT_SUCCESS; |
| 260 | } | 251 | } |
| 261 | 252 | ||
| 262 | if (found) { | 253 | if (found) { |
| 263 | printf("%s already running.\n", execname); | 254 | printf("%s already running.\n%d\n", execname ,found->pid); |
| 264 | printf("%d\n",found->pid); | 255 | return EXIT_SUCCESS; |
| 265 | exit(0); | ||
| 266 | } | 256 | } |
| 267 | *--argv = startas; | 257 | *--argv = startas; |
| 268 | execv(startas, argv); | 258 | execv(startas, argv); |
