|
Bugzilla – Full Text Bug Listing |
| Summary: | Cannot run background process from sudoed script when I/O logging is enabled | ||
|---|---|---|---|
| Product: | Sudo | Reporter: | Giacomo Picconi <stuxjack> |
| Component: | Sudoers | Assignee: | Todd C. Miller <Todd.Miller> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | daniele |
| Priority: | low | ||
| Version: | 1.8.1 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
|
Description
Giacomo Picconi
2011-07-28 09:44:12 MDT
The problem is that the sudo process that does the logging waits for the command to complete, at which time is closes the pty master. This causes the backgrounded command, which has the pty slave as its tty, to be sent SIGHUP by the kernel. There's no way for sudo to tell that there is a backgrounded child process since when the command exits, any children it has are reparented to init (or whatever process 1 is). This means there is no longer a parent-child relationship and sudo cannot wait for them as the wait system call will report that there are no children left. This is a difficult problem to solve. Linux / Unix doesn't provide a mechanism to notify a process when, all users of a pty are finished. On Linux it would be possible to periodically scan /proc/pid/status for every process on the system. That is what lsof does but this is Linux-specific and somewhat race-prone. On other systems it may be necessary to read kernel memory to find the users of the pty. The Linux inotify interface might be usable to track when users of a tty have closed it but again, this is not portable. Another possibility is to ptrace the child process and just tell it to ignore the SIGHUP. The background process would continue running but no output would be logged after the pty was closed. Of course, ptrace varies considerably from system to system so is not very portable either. It turns out this was a simpler issue than I realized. The trick is for sudo to reclaim the controlling tty before it exits, becoming the foreground process. Sudo and the command run in different process groups and the kernel only send SIGHUP to processes in the foreground process group, which now only consists of the sudo process itself. The fix will be included in sudo 1.8.22. *** Bug 808 has been marked as a duplicate of this bug. *** Fixed in sudo 1.8.22 |