diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-18 22:44:00 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-18 22:44:00 +0100 |
| commit | 8531d76a15890c2c535908ce888b2e2aed35b172 (patch) | |
| tree | 2035bb9eb9feec14d80487a313729192bb0e875c | |
| parent | c5c006c10c060e7f1a97250d039051b93ed390b2 (diff) | |
| download | busybox-w32-8531d76a15890c2c535908ce888b2e2aed35b172.tar.gz busybox-w32-8531d76a15890c2c535908ce888b2e2aed35b172.tar.bz2 busybox-w32-8531d76a15890c2c535908ce888b2e2aed35b172.zip | |
*: code shrink and better "died from signal" reporting from wait4pid
function old new delta
parse 964 967 +3
udhcp_run_script 670 665 -5
singlemount 911 906 -5
mount_it_now 360 355 -5
inotifyd_main 521 516 -5
xspawn 21 - -21
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/4 up/down: 3/-41) Total: -38 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | debianutils/run_parts.c | 4 | ||||
| -rw-r--r-- | findutils/xargs.c | 11 | ||||
| -rw-r--r-- | include/libbb.h | 11 | ||||
| -rw-r--r-- | libbb/vfork_daemon_rexec.c | 2 | ||||
| -rw-r--r-- | mailutils/mime.c | 2 | ||||
| -rw-r--r-- | miscutils/devfsd.c | 4 | ||||
| -rw-r--r-- | miscutils/inotifyd.c | 2 | ||||
| -rw-r--r-- | networking/ifplugd.c | 6 | ||||
| -rw-r--r-- | networking/ntpd.c | 2 | ||||
| -rw-r--r-- | networking/udhcp/script.c | 2 | ||||
| -rw-r--r-- | networking/zcip.c | 4 | ||||
| -rw-r--r-- | util-linux/mount.c | 4 |
12 files changed, 24 insertions, 30 deletions
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 2854a539c..37e8487e1 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
| @@ -159,14 +159,14 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv) | |||
| 159 | continue; | 159 | continue; |
| 160 | } | 160 | } |
| 161 | cmd[0] = name; | 161 | cmd[0] = name; |
| 162 | ret = wait4pid(spawn(cmd)); | 162 | ret = spawn_and_wait(cmd); |
| 163 | if (ret == 0) | 163 | if (ret == 0) |
| 164 | continue; | 164 | continue; |
| 165 | n = 1; | 165 | n = 1; |
| 166 | if (ret < 0) | 166 | if (ret < 0) |
| 167 | bb_perror_msg("can't execute '%s'", name); | 167 | bb_perror_msg("can't execute '%s'", name); |
| 168 | else /* ret > 0 */ | 168 | else /* ret > 0 */ |
| 169 | bb_error_msg("%s exited with code %d", name, ret); | 169 | bb_error_msg("%s exited with code %d", name, ret & 0xff); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | return n; | 172 | return n; |
diff --git a/findutils/xargs.c b/findutils/xargs.c index c7117771c..f5dbc7825 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
| @@ -64,16 +64,9 @@ static int xargs_exec(char **args) | |||
| 64 | bb_error_msg("%s: exited with status 255; aborting", args[0]); | 64 | bb_error_msg("%s: exited with status 255; aborting", args[0]); |
| 65 | return 124; | 65 | return 124; |
| 66 | } | 66 | } |
| 67 | /* Huh? I think we won't see this, ever. We don't wait with WUNTRACED! | 67 | if (status >= 0x180) { |
| 68 | if (WIFSTOPPED(status)) { | ||
| 69 | bb_error_msg("%s: stopped by signal %d", | ||
| 70 | args[0], WSTOPSIG(status)); | ||
| 71 | return 125; | ||
| 72 | } | ||
| 73 | */ | ||
| 74 | if (status >= 1000) { | ||
| 75 | bb_error_msg("%s: terminated by signal %d", | 68 | bb_error_msg("%s: terminated by signal %d", |
| 76 | args[0], status - 1000); | 69 | args[0], status - 0x180); |
| 77 | return 125; | 70 | return 125; |
| 78 | } | 71 | } |
| 79 | if (status) | 72 | if (status) |
diff --git a/include/libbb.h b/include/libbb.h index 044d09047..72d6c7dc8 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -812,21 +812,22 @@ int bb_execvp(const char *file, char *const argv[]) FAST_FUNC; | |||
| 812 | #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__) | 812 | #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__) |
| 813 | #endif | 813 | #endif |
| 814 | 814 | ||
| 815 | /* NOMMU friendy fork+exec */ | 815 | /* NOMMU friendy fork+exec: */ |
| 816 | pid_t spawn(char **argv) FAST_FUNC; | 816 | pid_t spawn(char **argv) FAST_FUNC; |
| 817 | pid_t xspawn(char **argv) FAST_FUNC; | 817 | pid_t xspawn(char **argv) FAST_FUNC; |
| 818 | 818 | ||
| 819 | pid_t safe_waitpid(pid_t pid, int *wstat, int options) FAST_FUNC; | 819 | pid_t safe_waitpid(pid_t pid, int *wstat, int options) FAST_FUNC; |
| 820 | /* Unlike waitpid, waits ONLY for one process. | 820 | pid_t wait_any_nohang(int *wstat) FAST_FUNC; |
| 821 | /* wait4pid: unlike waitpid, waits ONLY for one process. | ||
| 822 | * Returns sig + 0x180 if child is killed by signal. | ||
| 821 | * It's safe to pass negative 'pids' from failed [v]fork - | 823 | * It's safe to pass negative 'pids' from failed [v]fork - |
| 822 | * wait4pid will return -1 (and will not clobber [v]fork's errno). | 824 | * wait4pid will return -1 (and will not clobber [v]fork's errno). |
| 823 | * IOW: rc = wait4pid(spawn(argv)); | 825 | * IOW: rc = wait4pid(spawn(argv)); |
| 824 | * if (rc < 0) bb_perror_msg("%s", argv[0]); | 826 | * if (rc < 0) bb_perror_msg("%s", argv[0]); |
| 825 | * if (rc > 0) bb_error_msg("exit code: %d", rc); | 827 | * if (rc > 0) bb_error_msg("exit code: %d", rc & 0xff); |
| 826 | */ | 828 | */ |
| 827 | int wait4pid(pid_t pid) FAST_FUNC; | 829 | int wait4pid(pid_t pid) FAST_FUNC; |
| 828 | pid_t wait_any_nohang(int *wstat) FAST_FUNC; | 830 | /* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */ |
| 829 | /* wait4pid(spawn(argv)) + NOFORK/NOEXEC (if configured) */ | ||
| 830 | int spawn_and_wait(char **argv) FAST_FUNC; | 831 | int spawn_and_wait(char **argv) FAST_FUNC; |
| 831 | struct nofork_save_area { | 832 | struct nofork_save_area { |
| 832 | jmp_buf die_jmp; | 833 | jmp_buf die_jmp; |
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 9be901722..07024f5f0 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
| @@ -97,7 +97,7 @@ int FAST_FUNC wait4pid(pid_t pid) | |||
| 97 | if (WIFEXITED(status)) | 97 | if (WIFEXITED(status)) |
| 98 | return WEXITSTATUS(status); | 98 | return WEXITSTATUS(status); |
| 99 | if (WIFSIGNALED(status)) | 99 | if (WIFSIGNALED(status)) |
| 100 | return WTERMSIG(status) + 1000; | 100 | return WTERMSIG(status) + 0x180; |
| 101 | return 0; | 101 | return 0; |
| 102 | } | 102 | } |
| 103 | 103 | ||
diff --git a/mailutils/mime.c b/mailutils/mime.c index 125ca01dd..ee147802e 100644 --- a/mailutils/mime.c +++ b/mailutils/mime.c | |||
| @@ -357,7 +357,7 @@ static int parse(const char *boundary, char **argv) | |||
| 357 | if (opts & OPT_X) { | 357 | if (opts & OPT_X) { |
| 358 | signal(SIGPIPE, SIG_DFL); | 358 | signal(SIGPIPE, SIG_DFL); |
| 359 | // exit if helper exited >0 | 359 | // exit if helper exited >0 |
| 360 | rc = wait4pid(pid); | 360 | rc = (wait4pid(pid) & 0xff); |
| 361 | if (rc) | 361 | if (rc) |
| 362 | return rc+20; | 362 | return rc+20; |
| 363 | } | 363 | } |
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 62f5de8b6..4ccb76d95 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c | |||
| @@ -751,7 +751,7 @@ static void action_modload(const struct devfsd_notify_struct *info, | |||
| 751 | argv[4] = concat_path_file("/dev", info->devname); /* device */ | 751 | argv[4] = concat_path_file("/dev", info->devname); /* device */ |
| 752 | argv[5] = NULL; | 752 | argv[5] = NULL; |
| 753 | 753 | ||
| 754 | wait4pid(xspawn(argv)); | 754 | spawn_and_wait(argv); |
| 755 | free(argv[4]); | 755 | free(argv[4]); |
| 756 | } /* End Function action_modload */ | 756 | } /* End Function action_modload */ |
| 757 | 757 | ||
| @@ -783,7 +783,7 @@ static void action_execute(const struct devfsd_notify_struct *info, | |||
| 783 | argv[count] = largv[count]; | 783 | argv[count] = largv[count]; |
| 784 | } | 784 | } |
| 785 | argv[count] = NULL; | 785 | argv[count] = NULL; |
| 786 | wait4pid(spawn(argv)); | 786 | spawn_and_wait(argv); |
| 787 | } /* End Function action_execute */ | 787 | } /* End Function action_execute */ |
| 788 | 788 | ||
| 789 | 789 | ||
diff --git a/miscutils/inotifyd.c b/miscutils/inotifyd.c index 999b5e309..271f3ade1 100644 --- a/miscutils/inotifyd.c +++ b/miscutils/inotifyd.c | |||
| @@ -155,7 +155,7 @@ int inotifyd_main(int argc, char **argv) | |||
| 155 | args[1] = events; | 155 | args[1] = events; |
| 156 | args[2] = watches[ie->wd]; | 156 | args[2] = watches[ie->wd]; |
| 157 | args[3] = ie->len ? ie->name : NULL; | 157 | args[3] = ie->len ? ie->name : NULL; |
| 158 | wait4pid(xspawn((char **)args)); | 158 | spawn_and_wait((char **)args); |
| 159 | // we are done if all files got final x event | 159 | // we are done if all files got final x event |
| 160 | if (ie->mask & 0x8000) { | 160 | if (ie->mask & 0x8000) { |
| 161 | if (--argc <= 0) | 161 | if (--argc <= 0) |
diff --git a/networking/ifplugd.c b/networking/ifplugd.c index ac6607c91..62b135524 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c | |||
| @@ -132,10 +132,10 @@ static int run_script(const char *action) | |||
| 132 | argv[3] = (char*) G.extra_arg; | 132 | argv[3] = (char*) G.extra_arg; |
| 133 | argv[4] = NULL; | 133 | argv[4] = NULL; |
| 134 | 134 | ||
| 135 | /* r < 0 - can't exec, 0 <= r < 1000 - exited, >1000 - killed by sig (r-1000) */ | 135 | /* r < 0 - can't exec, 0 <= r < 0x180 - exited, >=0x180 - killed by sig (r-0x180) */ |
| 136 | r = wait4pid(spawn(argv)); | 136 | r = spawn_and_wait(argv); |
| 137 | 137 | ||
| 138 | bb_error_msg("exit code: %d", r); | 138 | bb_error_msg("exit code: %d", r & 0xff); |
| 139 | return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r; | 139 | return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r; |
| 140 | 140 | ||
| 141 | #else /* insanity */ | 141 | #else /* insanity */ |
diff --git a/networking/ntpd.c b/networking/ntpd.c index 04df3fa7f..6d9183a4b 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
| @@ -772,7 +772,7 @@ static void run_script(const char *action, double offset) | |||
| 772 | 772 | ||
| 773 | /* Don't want to wait: it may run hwclock --systohc, and that | 773 | /* Don't want to wait: it may run hwclock --systohc, and that |
| 774 | * may take some time (seconds): */ | 774 | * may take some time (seconds): */ |
| 775 | /*wait4pid(spawn(argv));*/ | 775 | /*spawn_and_wait(argv);*/ |
| 776 | spawn(argv); | 776 | spawn(argv); |
| 777 | 777 | ||
| 778 | unsetenv("stratum"); | 778 | unsetenv("stratum"); |
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index 574c74f45..a74697c90 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c | |||
| @@ -271,7 +271,7 @@ void FAST_FUNC udhcp_run_script(struct dhcp_packet *packet, const char *name) | |||
| 271 | argv[0] = (char*) client_config.script; | 271 | argv[0] = (char*) client_config.script; |
| 272 | argv[1] = (char*) name; | 272 | argv[1] = (char*) name; |
| 273 | argv[2] = NULL; | 273 | argv[2] = NULL; |
| 274 | wait4pid(spawn(argv)); | 274 | spawn_and_wait(argv); |
| 275 | 275 | ||
| 276 | for (curr = envp; *curr; curr++) { | 276 | for (curr = envp; *curr; curr++) { |
| 277 | log2(" %s", *curr); | 277 | log2(" %s", *curr); |
diff --git a/networking/zcip.c b/networking/zcip.c index db10d0a26..6b0b1c491 100644 --- a/networking/zcip.c +++ b/networking/zcip.c | |||
| @@ -160,13 +160,13 @@ static int run(char *argv[3], const char *param, struct in_addr *ip) | |||
| 160 | } | 160 | } |
| 161 | bb_info_msg(fmt, argv[2], argv[0], addr); | 161 | bb_info_msg(fmt, argv[2], argv[0], addr); |
| 162 | 162 | ||
| 163 | status = wait4pid(spawn(argv + 1)); | 163 | status = spawn_and_wait(argv + 1); |
| 164 | if (status < 0) { | 164 | if (status < 0) { |
| 165 | bb_perror_msg("%s %s %s" + 3, argv[2], argv[0]); | 165 | bb_perror_msg("%s %s %s" + 3, argv[2], argv[0]); |
| 166 | return -errno; | 166 | return -errno; |
| 167 | } | 167 | } |
| 168 | if (status != 0) | 168 | if (status != 0) |
| 169 | bb_error_msg("script %s %s failed, exitcode=%d", argv[1], argv[2], status); | 169 | bb_error_msg("script %s %s failed, exitcode=%d", argv[1], argv[2], status & 0xff); |
| 170 | return status; | 170 | return status; |
| 171 | } | 171 | } |
| 172 | 172 | ||
diff --git a/util-linux/mount.c b/util-linux/mount.c index 620b14667..e24fc4024 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
| @@ -456,7 +456,7 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts) | |||
| 456 | args[rc++] = filteropts; | 456 | args[rc++] = filteropts; |
| 457 | } | 457 | } |
| 458 | args[rc] = NULL; | 458 | args[rc] = NULL; |
| 459 | rc = wait4pid(spawn(args)); | 459 | rc = spawn_and_wait(args); |
| 460 | free(args[0]); | 460 | free(args[0]); |
| 461 | if (!rc) | 461 | if (!rc) |
| 462 | break; | 462 | break; |
| @@ -1633,7 +1633,7 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
| 1633 | } | 1633 | } |
| 1634 | args[n++] = mp->mnt_dir; | 1634 | args[n++] = mp->mnt_dir; |
| 1635 | args[n] = NULL; | 1635 | args[n] = NULL; |
| 1636 | rc = wait4pid(xspawn(args)); | 1636 | rc = spawn_and_wait(args); |
| 1637 | goto report_error; | 1637 | goto report_error; |
| 1638 | } | 1638 | } |
| 1639 | 1639 | ||
