Modify ↓
Opened 5 months ago
Last modified 5 months ago
#13764 assigned defect
os._exit() should be used rather than sys.exit() in the child process after a os.fork()
Reported by: | Jun Omae | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.6.1 |
Component: | web frontend/tracd | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
According to the documentation of os._exit()t:
Exit the process with status n, without calling cleanup handlers, flushing stdio buffers, etc. Note: The standard way to exit is sys.exit(n). _exit() should normally only be used in the child process after a fork().
However, sys.exit() is used in daemonize().
-
trac/util/daemon.py
diff --git a/trac/util/daemon.py b/trac/util/daemon.py index 3a2db5c27..984025825 100644
a b def daemonize(pidfile=None, progname=None, stdin='/dev/null', 53 53 # Perform first fork 54 54 pid = os.fork() 55 55 if pid > 0: 56 sys.exit(0)# exit first parent56 os._exit(0) # exit first parent 57 57 58 58 # Decouple from parent environment 59 59 os.chdir('/') … … def daemonize(pidfile=None, progname=None, stdin='/dev/null', 63 63 # Perform second fork 64 64 pid = os.fork() 65 65 if pid > 0: 66 sys.exit(0)# exit second parent66 os._exit(0) # exit second parent 67 67 68 68 # The process is now daemonized, redirect standard file descriptors 69 69 for stream in sys.stdout, sys.stderr:
Attachments (0)
Note:
See TracTickets
for help on using tickets.
Test script:
Before the patch:
Data written to stdout and stderr before a call of
daemonize
are written to files thrice.After the patch:
Data written to stdout and stderr before a call of
daemonize
are written to files only once.