Ticket #809 (closed defect: fixed)
daemon() lacks closing the service standard stream
| Reported by: | nrueff | Owned by: | oroussy |
|---|---|---|---|
| Priority: | Highest | Milestone: | 1.2.5 |
| Component: | general | Version: | 1.2.4 |
| Severity: | Blocker | Keywords: | |
| Cc: |
Description
The daemon() function do not seems to replace the daemon stdin, stdout and stderr by /dev/null :
etch:~# ls -l /proc/`pidof -s -x pulse2-inventory-server`/fd total 3 lrwx------ 1 root root 64 2010-03-01 16:35 0 -> socket:[8740] l-wx------ 1 root root 64 2010-03-01 16:35 3 -> /var/log/mmc/pulse2-inventory-server.log lrwx------ 1 root root 64 2010-03-01 16:35 4 -> socket:[8737]
In fact, I'm not even sure that existing file descriptors are cleanly closed. here is a working example (to be introduced after the second fork() :
for fd in range(0, 1024):
try:
os.close(fd)
except OSError:
pass
os.open(os.devnull, os.O_RDWR)
os.dup2(0, 1)
os.dup2(0, 2)
IRL, 1024 should be replaced by resource.RLIMIT_NOFILE, logging reconfigured after, and a check should be done around os.devnull (introduced in python 2.4), but you got the idea.
Here is what you may obtain after :
etch:~# ls /proc/`pidof -s -x pulse2-inventory-server`/fd -l total 6 lrwx------ 1 root root 64 2010-03-01 17:06 0 -> /dev/null lrwx------ 1 root root 64 2010-03-01 17:06 1 -> /dev/null lrwx------ 1 root root 64 2010-03-01 17:06 2 -> /dev/null l-wx------ 1 root root 64 2010-03-01 17:06 3 -> /var/log/mmc/pulse2-inventory-server.log lrwx------ 1 root root 64 2010-03-01 17:06 4 -> socket:[10568] lrwx------ 1 root root 64 2010-03-01 17:06 5 -> socket:[10570]
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

