From 41ddd9f60604cd994eeb37eb5708e9d3d5c8484b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 25 Jun 2010 01:46:53 +0200 Subject: *: make exec failure message more consistent Signed-off-by: Denys Vlasenko --- runit/chpst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runit') diff --git a/runit/chpst.c b/runit/chpst.c index 1a68eb755..028a28d6c 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -383,5 +383,5 @@ int chpst_main(int argc UNUSED_PARAM, char **argv) close(STDERR_FILENO); BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("exec %s", argv[0]); + bb_perror_msg_and_die("can't execute '%s'", argv[0]); } -- cgit v1.2.3-55-g6feb From a73b87e9343df2a6f14e328a977e7b70eb3ed707 Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Sun, 27 Jun 2010 03:23:31 +0200 Subject: *: s/"/bin/sh"/DEFAULT_SHELL, run_shell() API fix, remove unneeded strdup function old new delta run_shell 157 166 +9 su_main 477 470 -7 sulogin_main 515 503 -12 Signed-off-by: Ladislav Michl Signed-off-by: Denys Vlasenko --- archival/libunarchive/data_extract_to_command.c | 4 +- include/libbb.h | 7 ++- libbb/run_shell.c | 18 ++++---- libbb/setup_environment.c | 4 +- loginutils/login.c | 12 +++--- loginutils/su.c | 57 ++++++++++++++----------- loginutils/sulogin.c | 8 ++-- runit/svlogd.c | 2 +- 8 files changed, 58 insertions(+), 54 deletions(-) (limited to 'runit') diff --git a/archival/libunarchive/data_extract_to_command.c b/archival/libunarchive/data_extract_to_command.c index 53a7217c2..eb09439bc 100644 --- a/archival/libunarchive/data_extract_to_command.c +++ b/archival/libunarchive/data_extract_to_command.c @@ -102,8 +102,8 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle) close(p[1]); xdup2(p[0], STDIN_FILENO); signal(SIGPIPE, SIG_DFL); - execl("/bin/sh", "/bin/sh" + 5, "-c", archive_handle->tar__to_command, NULL); - bb_perror_msg_and_die("can't execute '%s'", "/bin/sh"); + execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c", archive_handle->tar__to_command, NULL); + bb_perror_msg_and_die("can't execute '%s'", DEFAULT_SHELL); } close(p[0]); /* Our caller is expected to do signal(SIGPIPE, SIG_IGN) diff --git a/include/libbb.h b/include/libbb.h index 58719a85b..53b768d88 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1157,7 +1157,6 @@ char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC; extern void bb_do_delay(int seconds) FAST_FUNC; extern void change_identity(const struct passwd *pw) FAST_FUNC; extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) NORETURN FAST_FUNC; -extern void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) FAST_FUNC; #if ENABLE_SELINUX extern void renew_current_security_context(void) FAST_FUNC; extern void set_current_security_context(security_context_t sid) FAST_FUNC; @@ -1593,12 +1592,12 @@ extern struct globals *const ptr_to_globals; * use bb_default_login_shell and following defines. * If you change LIBBB_DEFAULT_LOGIN_SHELL, * don't forget to change increment constant. */ -#define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh" +#define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh" extern const char bb_default_login_shell[]; /* "/bin/sh" */ -#define DEFAULT_SHELL (bb_default_login_shell+1) +#define DEFAULT_SHELL (bb_default_login_shell+1) /* "sh" */ -#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) +#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) #if ENABLE_FEATURE_DEVFS # define CURRENT_VC "/dev/vc/0" diff --git a/libbb/run_shell.c b/libbb/run_shell.c index 4608a24a9..4d92c3caa 100644 --- a/libbb/run_shell.c +++ b/libbb/run_shell.c @@ -49,15 +49,14 @@ void FAST_FUNC set_current_security_context(security_context_t sid) #endif -/* Run SHELL, or DEFAULT_SHELL if SHELL is empty. - If COMMAND is nonzero, pass it to the shell with the -c option. - If ADDITIONAL_ARGS is nonzero, pass it to the shell as more - arguments. */ - +/* Run SHELL, or DEFAULT_SHELL if SHELL is "" or NULL. + * If COMMAND is nonzero, pass it to the shell with the -c option. + * If ADDITIONAL_ARGS is nonzero, pass it to the shell as more + * arguments. */ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args) { const char **args; - int argno = 1; + int argno; int additional_args_cnt = 0; for (args = additional_args; args && *args; args++) @@ -65,11 +64,13 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, args = xmalloc(sizeof(char*) * (4 + additional_args_cnt)); - args[0] = bb_get_last_path_component_nostrip(xstrdup(shell)); + if (!shell || !shell[0]) + shell = DEFAULT_SHELL; + args[0] = bb_get_last_path_component_nostrip(shell); if (loginshell) args[0] = xasprintf("-%s", args[0]); - + argno = 1; if (command) { args[argno++] = "-c"; args[argno++] = command; @@ -79,6 +80,7 @@ void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, args[argno++] = *additional_args; } args[argno] = NULL; + #if ENABLE_SELINUX if (current_sid) setexeccon(current_sid); diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 13e60d8e4..a95fbc5bf 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c @@ -43,7 +43,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass const char *term; /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. - Unset all other environment variables. */ + * Unset all other environment variables. */ term = getenv("TERM"); clearenv(); if (term) @@ -57,7 +57,7 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass //xsetenv("SHELL", shell); } else if (flags & SETUP_ENV_CHANGEENV) { /* Set HOME, SHELL, and if not becoming a super-user, - USER and LOGNAME. */ + * USER and LOGNAME. */ if (pw->pw_uid) { shortcut: xsetenv("USER", pw->pw_name); diff --git a/loginutils/login.c b/loginutils/login.c index 078cd68ed..88ed0af78 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -201,7 +201,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) }; char *fromhost; char username[USERNAME_SIZE]; - const char *tmp; + const char *shell; int run_by_root; unsigned opt; int count = 0; @@ -389,10 +389,10 @@ int login_main(int argc UNUSED_PARAM, char **argv) run_login_script(pw, full_tty); change_identity(pw); - tmp = pw->pw_shell; - if (!tmp || !*tmp) - tmp = DEFAULT_SHELL; - setup_environment(tmp, + shell = pw->pw_shell; + if (!shell || !shell[0]) + shell = DEFAULT_SHELL; + setup_environment(shell, (!(opt & LOGIN_OPT_p) * SETUP_ENV_CLEARENV) + SETUP_ENV_CHANGEENV, pw); @@ -427,7 +427,7 @@ int login_main(int argc UNUSED_PARAM, char **argv) signal(SIGINT, SIG_DFL); /* Exec login shell with no additional parameters */ - run_shell(tmp, 1, NULL, NULL); + run_shell(shell, 1, NULL, NULL); /* return EXIT_FAILURE; - not reached */ } diff --git a/loginutils/su.c b/loginutils/su.c index af25655fd..9bae37551 100644 --- a/loginutils/su.c +++ b/loginutils/su.c @@ -10,23 +10,27 @@ #if ENABLE_FEATURE_SU_CHECKS_SHELLS /* Return 1 if SHELL is a restricted shell (one not returned by - getusershell), else 0, meaning it is a standard shell. */ + * getusershell), else 0, meaning it is a standard shell. */ static int restricted_shell(const char *shell) { char *line; + int result = 1; /*setusershell(); - getusershell does it itself*/ while ((line = getusershell()) != NULL) { - if (/* *line != '#' && */ strcmp(line, shell) == 0) - return 0; + if (/* *line != '#' && */ strcmp(line, shell) == 0) { + result = 0; + break; + } } - endusershell(); - return 1; + if (ENABLE_FEATURE_CLEAN_UP) + endusershell(); + return result; } #endif #define SU_OPT_mp (3) -#define SU_OPT_l (4) +#define SU_OPT_l (4) int su_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int su_main(int argc UNUSED_PARAM, char **argv) @@ -38,7 +42,8 @@ int su_main(int argc UNUSED_PARAM, char **argv) struct passwd *pw; uid_t cur_uid = getuid(); const char *tty; - char *old_user; + char user_buf[64]; + const char *old_user; flags = getopt32(argv, "mplc:s:", &opt_command, &opt_shell); //argc -= optind; @@ -56,21 +61,18 @@ int su_main(int argc UNUSED_PARAM, char **argv) } if (ENABLE_FEATURE_SU_SYSLOG) { - /* The utmp entry (via getlogin) is probably the best way to identify - * the user, especially if someone su's from a su-shell. + /* The utmp entry (via getlogin) is probably the best way to + * identify the user, especially if someone su's from a su-shell. * But getlogin can fail -- usually due to lack of utmp entry. * in this case resort to getpwuid. */ - const char *user; #if ENABLE_FEATURE_UTMP - char user_buf[64]; - user = user_buf; + old_user = user_buf; if (getlogin_r(user_buf, sizeof(user_buf)) != 0) #endif { pw = getpwuid(cur_uid); - user = pw ? pw->pw_name : ""; + old_user = pw ? xstrdup(pw->pw_name) : ""; } - old_user = xstrdup(user); tty = xmalloc_ttyname(2); if (!tty) { tty = "none"; @@ -80,13 +82,7 @@ int su_main(int argc UNUSED_PARAM, char **argv) pw = xgetpwnam(opt_username); - /* Make sure pw->pw_shell is non-NULL. It may be NULL when NEW_USER - is a username that is retrieved via NIS (YP), but that doesn't have - a default shell listed. */ - if (!pw->pw_shell || !pw->pw_shell[0]) - pw->pw_shell = (char *)DEFAULT_SHELL; - - if ((cur_uid == 0) || correct_password(pw)) { + if (cur_uid == 0 || correct_password(pw)) { if (ENABLE_FEATURE_SU_SYSLOG) syslog(LOG_NOTICE, "%c %s %s:%s", '+', tty, old_user, opt_username); @@ -99,21 +95,30 @@ int su_main(int argc UNUSED_PARAM, char **argv) if (ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_SU_SYSLOG) { closelog(); - free(old_user); } - if (!opt_shell && (flags & SU_OPT_mp)) + if (!opt_shell && (flags & SU_OPT_mp)) { + /* -s SHELL is not given, but "preserve env" opt is */ opt_shell = getenv("SHELL"); + } + + /* Make sure pw->pw_shell is non-NULL. It may be NULL when NEW_USER + * is a username that is retrieved via NIS (YP), that doesn't have + * a default shell listed. */ + if (!pw->pw_shell || !pw->pw_shell[0]) + pw->pw_shell = (char *)DEFAULT_SHELL; #if ENABLE_FEATURE_SU_CHECKS_SHELLS if (opt_shell && cur_uid != 0 && restricted_shell(pw->pw_shell)) { /* The user being su'd to has a nonstandard shell, and so is - probably a uucp account or has restricted access. Don't - compromise the account by allowing access with a standard - shell. */ + * probably a uucp account or has restricted access. Don't + * compromise the account by allowing access with a standard + * shell. */ bb_error_msg("using restricted shell"); opt_shell = NULL; } + /* else: user can run whatever he wants via "su -s PROG USER". + * This is safe since PROG is run under user's uid/gid. */ #endif if (!opt_shell) opt_shell = pw->pw_shell; diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index 6e3d3b019..3516013f1 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -101,11 +101,9 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv) shell = getenv("SUSHELL"); if (!shell) shell = getenv("sushell"); - if (!shell) { - shell = "/bin/sh"; - if (pwd->pw_shell[0]) - shell = pwd->pw_shell; - } + if (!shell) + shell = pwd->pw_shell; + /* Exec login shell with no additional parameters. Never returns. */ run_shell(shell, 1, NULL, NULL); diff --git a/runit/svlogd.c b/runit/svlogd.c index fc8b4abb9..9fe81b900 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -354,7 +354,7 @@ static void processorstart(struct logdir *ld) xmove_fd(fd, 5); // getenv("SHELL")? - execl("/bin/sh", "/bin/sh" + 5, "-c", ld->processor, (char*) NULL); + execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c", ld->processor, (char*) NULL); bb_perror_msg_and_die(FATAL"can't %s processor %s", "run", ld->name); } ld->fnsave[26] = sv_ch; /* ...restore */ -- cgit v1.2.3-55-g6feb From 21e8e8da6483c80a6054b06e48341968a7dccdd5 Mon Sep 17 00:00:00 2001 From: Pascal Bellard Date: Sun, 4 Jul 2010 00:57:03 +0200 Subject: libbb: introduce and use BB_EXECVP_or_die() function old new delta BB_EXECVP_or_die - 47 +47 time_main 1042 1043 +1 chrt_main 371 364 -7 ionice_main 292 282 -10 setsid_main 69 56 -13 nohup_main 236 223 -13 cttyhack_main 266 253 -13 chroot_main 94 81 -13 chpst_main 746 733 -13 timeout_main 297 279 -18 taskset_main 541 522 -19 vfork_child 67 45 -22 parse 975 953 -22 lpd_main 770 748 -22 launch_helper 192 170 -22 tcpudpsvd_main 1810 1782 -28 nice_main 190 156 -34 env_main 242 206 -36 run_command 221 174 -47 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/17 up/down: 48/-352) Total: -304 bytes Signed-off-by: Pascal Bellard Signed-off-by: Denys Vlasenko --- console-tools/openvt.c | 3 +-- coreutils/chroot.c | 3 +-- coreutils/env.c | 5 +---- coreutils/nice.c | 5 +---- coreutils/nohup.c | 3 +-- include/libbb.h | 1 + libbb/execable.c | 8 ++++++++ libbb/vfork_daemon_rexec.c | 34 ---------------------------------- libbb/xfuncs.c | 34 ++++++++++++++++++++++++++++++++++ mailutils/mail.c | 3 +-- mailutils/mime.c | 3 +-- miscutils/chrt.c | 3 +-- miscutils/ionice.c | 3 +-- miscutils/setsid.c | 3 +-- miscutils/taskset.c | 3 +-- miscutils/time.c | 15 ++++++--------- miscutils/timeout.c | 3 +-- networking/ifupdown.c | 3 +-- networking/tcpudp.c | 4 ++-- printutils/lpd.c | 3 +-- runit/chpst.c | 3 +-- shell/cttyhack.c | 3 +-- 22 files changed, 67 insertions(+), 81 deletions(-) (limited to 'runit') diff --git a/console-tools/openvt.c b/console-tools/openvt.c index 6f58916e7..e3ea71bc5 100644 --- a/console-tools/openvt.c +++ b/console-tools/openvt.c @@ -97,8 +97,7 @@ static NOINLINE void vfork_child(char **argv) //bb_error_msg("our pgrp %d", getpgrp()); //bb_error_msg("VT's sid %d", tcgetsid(0)); //bb_error_msg("VT's pgrp %d", tcgetpgrp(0)); - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } } diff --git a/coreutils/chroot.c b/coreutils/chroot.c index bc0b1f82c..046c2fabf 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c @@ -30,6 +30,5 @@ int chroot_main(int argc UNUSED_PARAM, char **argv) argv[1] = (char *) "-i"; } - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } diff --git a/coreutils/env.c b/coreutils/env.c index c6ba04d35..d4eab191b 100644 --- a/coreutils/env.c +++ b/coreutils/env.c @@ -77,10 +77,7 @@ int env_main(int argc UNUSED_PARAM, char **argv) } if (argv[0]) { - BB_EXECVP(argv[0], argv); - /* SUSv3-mandated exit codes. */ - xfunc_error_retval = (errno == ENOENT) ? 127 : 126; - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } if (environ) { /* clearenv() may set environ == NULL! */ diff --git a/coreutils/nice.c b/coreutils/nice.c index 0f70f1079..ff3eb1140 100644 --- a/coreutils/nice.c +++ b/coreutils/nice.c @@ -47,8 +47,5 @@ int nice_main(int argc, char **argv) } } - BB_EXECVP(argv[0], argv); - /* The exec failed... */ - xfunc_error_retval = (errno == ENOENT) ? 127 : 126; /* SUSv3 */ - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } diff --git a/coreutils/nohup.c b/coreutils/nohup.c index 1027ada1c..3dc531409 100644 --- a/coreutils/nohup.c +++ b/coreutils/nohup.c @@ -76,6 +76,5 @@ int nohup_main(int argc UNUSED_PARAM, char **argv) signal(SIGHUP, SIG_IGN); argv++; - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } diff --git a/include/libbb.h b/include/libbb.h index e26001705..4b6699f2f 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -839,6 +839,7 @@ int bb_execvp(const char *file, char *const argv[]) FAST_FUNC; #define BB_EXECVP(prog,cmd) execvp(prog,cmd) #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__) #endif +int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; /* NOMMU friendy fork+exec: */ pid_t spawn(char **argv) FAST_FUNC; diff --git a/libbb/execable.c b/libbb/execable.c index 5c7ac16a2..82241cd81 100644 --- a/libbb/execable.c +++ b/libbb/execable.c @@ -76,3 +76,11 @@ int FAST_FUNC bb_execvp(const char *file, char *const argv[]) argv); } #endif + +int FAST_FUNC BB_EXECVP_or_die(char **argv) +{ + BB_EXECVP(argv[0], argv); + /* SUSv3-mandated exit codes */ + xfunc_error_retval = (errno == ENOENT) ? 127 : 126; + bb_perror_msg_and_die("can't execute '%s'", argv[0]); +} diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 082f0f63e..8102ea2dc 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c @@ -67,40 +67,6 @@ pid_t FAST_FUNC xspawn(char **argv) return pid; } -pid_t FAST_FUNC safe_waitpid(pid_t pid, int *wstat, int options) -{ - pid_t r; - - do - r = waitpid(pid, wstat, options); - while ((r == -1) && (errno == EINTR)); - return r; -} - -pid_t FAST_FUNC wait_any_nohang(int *wstat) -{ - return safe_waitpid(-1, wstat, WNOHANG); -} - -// Wait for the specified child PID to exit, returning child's error return. -int FAST_FUNC wait4pid(pid_t pid) -{ - int status; - - if (pid <= 0) { - /*errno = ECHILD; -- wrong. */ - /* we expect errno to be already set from failed [v]fork/exec */ - return -1; - } - if (safe_waitpid(pid, &status, 0) == -1) - return -1; - if (WIFEXITED(status)) - return WEXITSTATUS(status); - if (WIFSIGNALED(status)) - return WTERMSIG(status) + 0x180; - return 0; -} - #if ENABLE_FEATURE_PREFER_APPLETS void FAST_FUNC save_nofork_data(struct nofork_save_area *save) { diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 65437211d..275dd4b62 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -268,3 +268,37 @@ int FAST_FUNC tcsetattr_stdin_TCSANOW(const struct termios *tp) { return tcsetattr(STDIN_FILENO, TCSANOW, tp); } + +pid_t FAST_FUNC safe_waitpid(pid_t pid, int *wstat, int options) +{ + pid_t r; + + do + r = waitpid(pid, wstat, options); + while ((r == -1) && (errno == EINTR)); + return r; +} + +pid_t FAST_FUNC wait_any_nohang(int *wstat) +{ + return safe_waitpid(-1, wstat, WNOHANG); +} + +// Wait for the specified child PID to exit, returning child's error return. +int FAST_FUNC wait4pid(pid_t pid) +{ + int status; + + if (pid <= 0) { + /*errno = ECHILD; -- wrong. */ + /* we expect errno to be already set from failed [v]fork/exec */ + return -1; + } + if (safe_waitpid(pid, &status, 0) == -1) + return -1; + if (WIFEXITED(status)) + return WEXITSTATUS(status); + if (WIFSIGNALED(status)) + return WTERMSIG(status) + 0x180; + return 0; +} diff --git a/mailutils/mail.c b/mailutils/mail.c index 49e72c32b..5eb99e13d 100644 --- a/mailutils/mail.c +++ b/mailutils/mail.c @@ -67,8 +67,7 @@ void FAST_FUNC launch_helper(const char **argv) if (!G.helper_pid) { // child: try to execute connection helper // NB: SIGCHLD & SIGALRM revert to SIG_DFL on exec - BB_EXECVP(argv[0], (char **)argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die((char**)argv); } // parent diff --git a/mailutils/mime.c b/mailutils/mime.c index 654b8731c..5eb8ef6f2 100644 --- a/mailutils/mime.c +++ b/mailutils/mime.c @@ -288,8 +288,7 @@ static int parse(const char *boundary, char **argv) xsetenv("CHARSET", charset); xsetenv("ENCODING", encoding); xsetenv("FILENAME", filename); - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } // parent dumps to fd[1] close(fd[0]); diff --git a/miscutils/chrt.c b/miscutils/chrt.c index 3d0da58ca..d5f87c4d7 100644 --- a/miscutils/chrt.c +++ b/miscutils/chrt.c @@ -120,6 +120,5 @@ int chrt_main(int argc UNUSED_PARAM, char **argv) if (!argv[0]) /* "-p [...]" */ goto print_rt_info; - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } diff --git a/miscutils/ionice.c b/miscutils/ionice.c index 8393cd8b2..52e51b908 100644 --- a/miscutils/ionice.c +++ b/miscutils/ionice.c @@ -90,8 +90,7 @@ int ionice_main(int argc UNUSED_PARAM, char **argv) if (ioprio_set(IOPRIO_WHO_PROCESS, pid, pri) == -1) bb_perror_msg_and_die("ioprio_%cet", 's'); if (argv[0]) { - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } } diff --git a/miscutils/setsid.c b/miscutils/setsid.c index 60ee062e3..c573fae34 100644 --- a/miscutils/setsid.c +++ b/miscutils/setsid.c @@ -45,6 +45,5 @@ int setsid_main(int argc UNUSED_PARAM, char **argv) } argv++; - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } diff --git a/miscutils/taskset.c b/miscutils/taskset.c index 2891003df..08198d5d4 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c @@ -132,6 +132,5 @@ int taskset_main(int argc UNUSED_PARAM, char **argv) if (!argv[0]) /* "-p [...ignored...]" */ goto print_aff; /* print new affinity and exit */ - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } diff --git a/miscutils/time.c b/miscutils/time.c index f5d1e15fb..5cfbcef8e 100644 --- a/miscutils/time.c +++ b/miscutils/time.c @@ -367,20 +367,17 @@ static void summarize(const char *fmt, char **command, resource_t *resp) Put the statistics in *RESP. */ static void run_command(char *const *cmd, resource_t *resp) { - pid_t pid; /* Pid of child. */ + pid_t pid; void (*interrupt_signal)(int); void (*quit_signal)(int); resp->elapsed_ms = monotonic_ms(); - pid = vfork(); /* Run CMD as child process. */ + pid = vfork(); if (pid < 0) - bb_perror_msg_and_die("fork"); - if (pid == 0) { /* If child. */ - /* Don't cast execvp arguments; that causes errors on some systems, - versus merely warnings if the cast is left off. */ - BB_EXECVP(cmd[0], cmd); - xfunc_error_retval = (errno == ENOENT ? 127 : 126); - bb_perror_msg_and_die("can't execute '%s'", cmd[0]); + bb_perror_msg_and_die("vfork"); + if (pid == 0) { + /* Child */ + BB_EXECVP_or_die((char**)cmd); } /* Have signals kill the child but not self (if possible). */ diff --git a/miscutils/timeout.c b/miscutils/timeout.c index 273d26953..f6e655acc 100644 --- a/miscutils/timeout.c +++ b/miscutils/timeout.c @@ -110,6 +110,5 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) argv[0] = sv1; argv[1] = sv2; #endif - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 714d2a107..1bab2c5cb 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -1052,8 +1052,7 @@ static int popen2(FILE **in, FILE **out, char *command, char *param) close(outfd.rd); xmove_fd(infd.rd, 0); xmove_fd(outfd.wr, 1); - BB_EXECVP(command, argv); - bb_perror_msg_and_die("can't execute '%s'", command); + BB_EXECVP_or_die(argv); } /* parent */ close(infd.rd); diff --git a/networking/tcpudp.c b/networking/tcpudp.c index 4e4756738..53e622b56 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c @@ -501,10 +501,10 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) #ifdef SSLSVD strcpy(id, utoa(pid)); ssl_io(0, argv); + bb_perror_msg_and_die("can't execute '%s'", argv[0]); #else - BB_EXECVP(argv[0], argv); + BB_EXECVP_or_die(argv); #endif - bb_perror_msg_and_die("can't execute '%s'", argv[0]); } /* diff --git a/printutils/lpd.c b/printutils/lpd.c index 15f1ba20b..d91491f1b 100644 --- a/printutils/lpd.c +++ b/printutils/lpd.c @@ -181,8 +181,7 @@ int lpd_main(int argc UNUSED_PARAM, char *argv[]) // this call reopens stdio fds to "/dev/null" // (no daemonization is done) bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO | DAEMON_ONLY_SANITIZE, NULL); - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } // validate input. diff --git a/runit/chpst.c b/runit/chpst.c index 028a28d6c..ad0811294 100644 --- a/runit/chpst.c +++ b/runit/chpst.c @@ -382,6 +382,5 @@ int chpst_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_2) close(STDERR_FILENO); - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } diff --git a/shell/cttyhack.c b/shell/cttyhack.c index bde2acdc9..67736ad62 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c @@ -81,6 +81,5 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv) } } - BB_EXECVP(argv[0], argv); - bb_perror_msg_and_die("can't execute '%s'", argv[0]); + BB_EXECVP_or_die(argv); } -- cgit v1.2.3-55-g6feb