Skip to content

Commit

Permalink
Waiting for pid file to be created before we proceed
Browse files Browse the repository at this point in the history
  • Loading branch information
yurivict committed May 16, 2015
1 parent 2e9dbac commit bab0e8a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tiny_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
## This is the module that recomputes IP and UDP packet checksums

import os, pwd, grp, sys
import errno
import signal
import atexit

Expand Down Expand Up @@ -45,7 +46,13 @@ def do_daemonize(pid_file):
write_pid_file2(pid_file, pid)
sys.exit(0); # exit from second parent
# wait for the initial process to finish so that pid file is written
os.waitpid(pid_init, 0)
try:
os.waitpid(pid_init, 0)
except OSError as err:
# ECHILD means that initial process has ended
if err.errno != errno.ECHILD:
raise
# pig_file has to be deleted
atexit.register(os.remove, pid_file)

def write_pid_file2(fname, pid):
Expand Down

0 comments on commit bab0e8a

Please sign in to comment.