From 30504941ea36ed40bbb628e8144ec2413e6fe765 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Mon, 14 Feb 2011 16:42:05 +0000 Subject: syncdaemon: fix some pidfile issues Signed-off-by: Csaba Henk Signed-off-by: Anand V. Avati BUG: 1570 (geosync related changes) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1570 --- xlators/features/marker/utils/syncdaemon/gsyncd.py | 35 +++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'xlators') diff --git a/xlators/features/marker/utils/syncdaemon/gsyncd.py b/xlators/features/marker/utils/syncdaemon/gsyncd.py index fedf1fbd..66550564 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'): -- cgit