When relocating fds, update the debug fd if it is set so we are

guaranteed to get debugging output.
This commit is contained in:
Todd C. Miller
2014-01-15 06:00:59 -07:00
parent 640a5ddb48
commit 8ca711ee15
3 changed files with 24 additions and 1 deletions

View File

@@ -570,3 +570,19 @@ sudo_debug_fd_get(void)
{
return sudo_debug_fd;
}
/*
* Setter for the debug descriptor.
*/
int
sudo_debug_fd_set(int fd)
{
if (sudo_debug_fd != -1 && fd != sudo_debug_fd) {
if (dup2(sudo_debug_fd, fd) == -1)
return -1;
(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
close(sudo_debug_fd);
sudo_debug_fd = fd;
}
return sudo_debug_fd;
}