return 0;
}
-static int flags_fds(int fds[], unsigned n_fds, bool nonblock) {
+static int flags_fds(const int fds[], unsigned n_fds, bool nonblock) {
unsigned i;
int r;
if (fstat(fd, &st) < 0)
return -errno;
- if (st.st_uid != uid ||
- st.st_mode != TTY_MODE)
+ if (st.st_uid != uid || (st.st_mode & 0777) != TTY_MODE)
return -EPERM;
return 0;
}
int exec_spawn(ExecCommand *command,
+ char **argv,
const ExecContext *context,
- int *fds, unsigned n_fds,
+ int fds[], unsigned n_fds,
bool apply_permissions,
bool apply_chroot,
bool confirm_spawn,
assert(ret);
assert(fds || n_fds <= 0);
- if (!(line = exec_command_line(command)))
+ if (!argv)
+ argv = command->argv;
+
+ if (!(line = exec_command_line(argv)))
return -ENOMEM;
log_debug("About to execute: %s", line);
goto fail;
/* Now ask the question. */
- if (!(line = exec_command_line(command))) {
+ if (!(line = exec_command_line(argv))) {
r = EXIT_MEMORY;
goto fail;
}
r = EXIT_USER;
goto fail;
}
+
+ if (is_terminal_input(context->std_input))
+ if (chown_terminal(STDIN_FILENO, uid) < 0) {
+ r = EXIT_STDIN;
+ goto fail;
+ }
}
if (apply_permissions)
goto fail;
}
- if (is_terminal_input(context->std_input))
- if (chown_terminal(STDIN_FILENO, uid) < 0) {
- r = EXIT_STDIN;
- goto fail;
- }
-
if (apply_chroot) {
if (context->root_directory)
if (chroot(context->root_directory) < 0) {
goto fail;
}
- execve(command->path, command->argv, final_env);
+ execve(command->path, argv, final_env);
r = EXIT_EXEC;
fail:
prefix, s->status);
}
-char *exec_command_line(ExecCommand *c) {
+char *exec_command_line(char **argv) {
size_t k;
char *n, *p, **a;
bool first = true;
- assert(c);
- assert(c->argv);
+ assert(argv);
k = 1;
- STRV_FOREACH(a, c->argv)
+ STRV_FOREACH(a, argv)
k += strlen(*a)+3;
if (!(n = new(char, k)))
return NULL;
p = n;
- STRV_FOREACH(a, c->argv) {
+ STRV_FOREACH(a, argv) {
if (!first)
*(p++) = ' ';
p2 = strappend(prefix, "\t");
prefix2 = p2 ? p2 : prefix;
- cmd = exec_command_line(c);
+ cmd = exec_command_line(c->argv);
fprintf(f,
"%sCommand Line: %s\n",