From 666e43aca607c90d95379caa13b42a4ed976e8a7 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Sun, 17 Apr 2011 04:45:59 +0000 Subject: syncdaemon: minor cleanups on termination Signed-off-by: Csaba Henk Signed-off-by: Anand Avati BUG: 2736 (gsyncd hangs if crash occurs in the non-main thread) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2736 --- xlators/features/marker/utils/syncdaemon/gsyncd.py | 6 ++---- xlators/features/marker/utils/syncdaemon/syncdutils.py | 11 +++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/xlators/features/marker/utils/syncdaemon/gsyncd.py b/xlators/features/marker/utils/syncdaemon/gsyncd.py index ba4d7a6dd..27c91858e 100644 --- a/xlators/features/marker/utils/syncdaemon/gsyncd.py +++ b/xlators/features/marker/utils/syncdaemon/gsyncd.py @@ -94,7 +94,7 @@ def startup(**kw): GLogger.setup(label=kw.get('label'), **lkw) def main(): - signal.signal(signal.SIGTERM, lambda *a: (finalize(*a), os._exit(1))) + signal.signal(signal.SIGTERM, lambda *a: finalize(*a, **{'exval': 1})) GLogger.setup() excont = FreeObject(exval = 0) try: @@ -103,9 +103,7 @@ def main(): except: log_raise_exception(excont) finally: - finalize() - # force exit in non-main thread too - os._exit(excont.exval) + finalize(excont.exval) def main_i(): rconf = {'go_daemon': 'should'} diff --git a/xlators/features/marker/utils/syncdaemon/syncdutils.py b/xlators/features/marker/utils/syncdaemon/syncdutils.py index c8f751d33..4bf51da74 100644 --- a/xlators/features/marker/utils/syncdaemon/syncdutils.py +++ b/xlators/features/marker/utils/syncdaemon/syncdutils.py @@ -4,7 +4,7 @@ import time import fcntl import shutil import logging -from threading import Thread as baseThread +from threading import Lock, Thread as baseThread from errno import EACCES, EAGAIN from signal import SIGTERM, SIGKILL from time import sleep @@ -88,7 +88,10 @@ def grabpidfile(fname=None, setpid=True): content = str(os.getpid()) + '\n' return grabfile(fname, content=content) -def finalize(*a): +final_lock = Lock() + +def finalize(*a, **kw): + final_lock.acquire() if getattr(gconf, 'pid_file', None): rm_pidf = gconf.pid_file_owned if gconf.cpid: @@ -117,6 +120,7 @@ def finalize(*a): shutil.rmtree(gconf.ssh_ctl_dir) sys.stdout.flush() sys.stderr.flush() + os._exit(kw.get('exval', 0)) def log_raise_exception(excont): exc = sys.exc_info()[1] @@ -150,8 +154,7 @@ class Thread(baseThread): try: log_raise_exception(excont) finally: - finalize() - os._exit(excont.exval) + finalize(exval = excont.exval) kw['target'] = twrap baseThread.__init__(self, *a, **kw) self.setDaemon(True) -- cgit