Fix compressed io log corruption in background mode by using _exit()

instead of exit() to avoid flushing buffers twice.

Improved background mode support.  When not allocating a pty, the
command is run in its own process group.  This prevents write access
to the tty.  When running in a pty, stdin is not hooked up and we
never read from /dev/tty, which results in similar behavior.
This commit is contained in:
Todd C. Miller
2011-05-31 12:49:22 -04:00
parent 7199afec89
commit 3c9e5f28fc
2 changed files with 14 additions and 11 deletions

View File

@@ -216,20 +216,19 @@ sudo_execve(struct command_details *details, struct command_status *cstat)
cstat->val = errno;
return -1;
case 0:
/* child continues in a new session in a different pty */
SET(details->flags, CD_USE_PTY);
(void)setsid();
/* child continues without controlling terminal */
(void)setpgid(0, 0);
break;
default:
/* parent exits */
exit(0);
/* parent exits (but does not flush buffers) */
_exit(0);
}
}
/*
* If we have an I/O plugin or the policy plugin has requested one, we
* need to allocate a pty. It is OK to set log_io in the pty-only case
* as the tailqueue plugin will be empty and no I/O logging will occur.
* as the io plugin tailqueue will be empty and no I/O logging will occur.
*/
if (!tq_empty(&io_plugins) || ISSET(details->flags, CD_USE_PTY)) {
log_io = TRUE;