Skip to content

Commit 4edfe98

Browse files
N-R-Knavi-desu
authored andcommitted
rc_exec: add a cmd arg
avoids assuming argv[0] is the command
1 parent 704dcdc commit 4edfe98

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

src/shared/rc_exec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct exec_result do_exec(struct exec_args *args)
5858
int stdin_pipe[2] = {-1, -1};
5959
int stdout_pipe[2] = {-1, -1};
6060
int stderr_pipe[2] = {-1, -1};
61+
const char *cmd = args->cmd ? args->cmd : args->argv[0];
6162

6263
if (pipe2(execpipe, O_CLOEXEC) < 0)
6364
goto exit;
@@ -109,7 +110,7 @@ struct exec_result do_exec(struct exec_args *args)
109110
if (args->setsid && setsid() < 0)
110111
goto child_err;
111112
sigprocmask(SIG_SETMASK, &old, NULL);
112-
execvp(args->argv[0], UNCONST(args->argv));
113+
execvp(cmd, UNCONST(args->argv));
113114
child_err:
114115
saved_errno = errno;
115116
write(execpipe[1], &saved_errno, sizeof saved_errno);

src/shared/rc_exec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enum {
3333

3434
struct exec_args {
3535
const char **argv;
36+
const char *cmd; /* if NULL, argv[0] is used */
3637
int redirect_stdin;
3738
int redirect_stdout;
3839
int redirect_stderr;

0 commit comments

Comments
 (0)