diff options
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/features/marker/utils/syncdaemon/gsyncd.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/gsyncd.py b/xlators/features/marker/utils/syncdaemon/gsyncd.py index fedf1fbdb0c..6655056489d 100644 --- a/xlators/features/marker/utils/syncdaemon/gsyncd.py +++ b/xlators/features/marker/utils/syncdaemon/gsyncd.py @@ -63,6 +63,17 @@ def startup(**kw): if fd: os.close(fd) + if getattr(gconf, 'pid_file', None) and kw.get('go_daemon') != 'postconn': + try: + write_pid(gconf.pid_file) + except OSError: + gconf.pid_file = None + ex = sys.exc_info()[1] + if ex.errno == EEXIST: + sys.stderr.write("pidfile is taken, exiting.\n") + exit(2) + raise + if kw.get('go_daemon') == 'should': x, y = os.pipe() gconf.cpid = os.fork() @@ -70,29 +81,19 @@ def startup(**kw): os.close(x) sys.exit() os.close(y) + os.setsid() + dn = os.open(os.devnull, os.O_RDWR) + for f in (sys.stdin, sys.stdout, sys.stderr): + os.dup2(dn, f.fileno()) + if getattr(gconf, 'pid_file', None): + write_pid(gconf.pid_file + '.tmp') + os.rename(gconf.pid_file + '.tmp', gconf.pid_file) # wait for parent to terminate # so we can start up with # no messing from the dirty # ol' bustard select.select((x,), (), ()) os.close(x) - if getattr(gconf, 'pid_file', None): - write_pid(gconf.pid_file + '.tmp') - os.rename(gconf.pid_file + '.tmp', gconf.pid_file) - os.setsid() - dn = os.open(os.devnull, os.O_RDWR) - for f in (sys.stdin, sys.stdout, sys.stderr): - os.dup2(dn, f.fileno()) - elif getattr(gconf, 'pid_file', None): - try: - write_pid(gconf.pid_file) - except OSError: - gconf.pid_file = None - ex = sys.exc_info()[1] - if ex.errno == EEXIST: - sys.stderr.write("pidfile is taken, exiting.\n") - exit(2) - raise lkw = {'level': gconf.log_level} if kw.get('log_file'): |