}
/*
- * Execute a command, potentially in a pty with I/O loggging.
+ * Setup the execution environment and execute the command.
+ * If SELinux is enabled, run the command via sesh, otherwise
+ * execute it directly.
+ * If the exec fails, cstat is filled in with the value of errno.
+ */
+void
+exec_cmnd(struct command_details *details, struct command_status *cstat,
+ int *errfd)
+{
+ debug_decl(exec_cmnd, SUDO_DEBUG_EXEC)
+
+ restore_signals();
+ if (exec_setup(details, NULL, -1) == true) {
+ /* headed for execve() */
+ sudo_debug_execve(SUDO_DEBUG_INFO, details->command,
+ details->argv, details->envp);
+ if (details->closefrom >= 0) {
+ int maxfd = details->closefrom;
+ /* Preserve back channel if present. */
+ if (errfd != NULL) {
+ dup2(*errfd, maxfd);
+ (void)fcntl(maxfd, F_SETFD, FD_CLOEXEC);
+ *errfd = maxfd++;
+ }
+ if (sudo_debug_fd_set(maxfd) != -1)
+ maxfd++;
+ closefrom(maxfd);
+ }
+#ifdef HAVE_SELINUX
+ if (ISSET(details->flags, CD_RBAC_ENABLED)) {
+ selinux_execve(details->command, details->argv, details->envp,
+ ISSET(details->flags, CD_NOEXEC));
+ } else
+#endif
+ {
+ sudo_execve(details->command, details->argv, details->envp,
+ ISSET(details->flags, CD_NOEXEC));
+ }
+ cstat->type = CMD_ERRNO;
+ cstat->val = errno;
+ sudo_debug_printf(SUDO_DEBUG_ERROR, "unable to exec %s: %s",
+ details->command, strerror(errno));
+ }
+ debug_return;
+}
+
+/*
+ * Execute a command, potentially in a pty with I/O loggging, and
+ * wait for it to finish.
* This is a little bit tricky due to how POSIX job control works and
* we fact that we have two different controlling terminals to deal with.
*/
}
return -1;
}
-
-void
-exec_cmnd(struct command_details *details, struct command_status *cstat,
- int *errfd)
-{
- debug_decl(exec_cmnd, SUDO_DEBUG_EXEC)
-
- restore_signals();
- if (exec_setup(details, NULL, -1) == true) {
- /* headed for execve() */
- sudo_debug_execve(SUDO_DEBUG_INFO, details->command,
- details->argv, details->envp);
- if (details->closefrom >= 0) {
- int maxfd = details->closefrom;
- /* Preserve back channel if present. */
- if (errfd != NULL) {
- dup2(*errfd, maxfd);
- (void)fcntl(maxfd, F_SETFD, FD_CLOEXEC);
- *errfd = maxfd++;
- }
- if (sudo_debug_fd_set(maxfd) != -1)
- maxfd++;
- closefrom(maxfd);
- }
-#ifdef HAVE_SELINUX
- if (ISSET(details->flags, CD_RBAC_ENABLED)) {
- selinux_execve(details->command, details->argv, details->envp,
- ISSET(details->flags, CD_NOEXEC));
- } else
-#endif
- {
- sudo_execve(details->command, details->argv, details->envp,
- ISSET(details->flags, CD_NOEXEC));
- }
- cstat->type = CMD_ERRNO;
- cstat->val = errno;
- sudo_debug_printf(SUDO_DEBUG_ERROR, "unable to exec %s: %s",
- details->command, strerror(errno));
- }
- debug_return;
-}