if ((nfd = fcntl(fds[i], F_DUPFD, i+3)) < 0)
return -errno;
- assert_se(close_nointr(fds[i]) == 0);
+ close_nointr_nofail(fds[i]);
fds[i] = nfd;
/* Hmm, the fd we wanted isn't free? Then
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 (fd != nfd) {
r = dup2(fd, nfd) < 0 ? -errno : nfd;
- close_nointr(fd);
+ close_nointr_nofail(fd);
} else
r = nfd;
if (fd != nfd) {
r = dup2(fd, nfd) < 0 ? -errno : nfd;
- close_nointr(fd);
+ close_nointr_nofail(fd);
} else
r = nfd;
struct stat st;
assert(fd >= 0);
- assert(uid >= 0);
/* This might fail. What matters are the results. */
fchown(fd, uid, -1);
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,
const ExecContext *context,
- int *fds, unsigned n_fds,
+ int fds[], unsigned n_fds,
bool apply_permissions,
bool apply_chroot,
bool confirm_spawn,
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) {