Blame virt-who-0.8-create-pid-file-asap.patch

Radek Novacek 375ced
commit ac15c128524cd317623044d7fbaedb4eef3b557e
Radek Novacek 375ced
Author: Radek Novacek <rnovacek@redhat.com>
Radek Novacek 375ced
Date:   Thu Oct 4 12:06:36 2012 +0200
Radek Novacek 375ced
Radek Novacek 375ced
    Create PID file as soon as possible
Radek Novacek 375ced
    
Radek Novacek 375ced
    PID file was created too late causing service stop to be unsuccessfull
Radek Novacek 375ced
    if call too soon after service start.
Radek Novacek 375ced
    
Radek Novacek 375ced
    Now PID file is create immediatelly when service is started and
Radek Novacek 375ced
    recreated after fork.
Radek Novacek 375ced
Radek Novacek 375ced
diff --git a/virt-who.py b/virt-who.py
Radek Novacek 375ced
index 0c8babf..7b15f14 100644
Radek Novacek 375ced
--- a/virt-who.py
Radek Novacek 375ced
+++ b/virt-who.py
Radek Novacek 375ced
@@ -286,7 +286,7 @@ def daemonize(debugMode):
Radek Novacek 375ced
     os.chdir("/")
Radek Novacek 375ced
     return True
Radek Novacek 375ced
 
Radek Novacek 375ced
-def createPidFile(logger):
Radek Novacek 375ced
+def createPidFile(logger=None):
Radek Novacek 375ced
     atexit.register(cleanup)
Radek Novacek 375ced
     signal.signal(signal.SIGINT, cleanup)
Radek Novacek 375ced
     signal.signal(signal.SIGTERM, cleanup)
Radek Novacek 375ced
@@ -297,7 +297,8 @@ def createPidFile(logger):
Radek Novacek 375ced
         f.write("%d" % os.getpid())
Radek Novacek 375ced
         f.close()
Radek Novacek 375ced
     except Exception, e:
Radek Novacek 375ced
-        logger.error("Unable to create pid file: %s" % str(e))
Radek Novacek 375ced
+        if logger is not None:
Radek Novacek 375ced
+            logger.error("Unable to create pid file: %s" % str(e))
Radek Novacek 375ced
 
Radek Novacek 375ced
 def cleanup(sig=None, stack=None):
Radek Novacek 375ced
     try:
Radek Novacek 375ced
@@ -312,6 +313,7 @@ def main():
Radek Novacek 375ced
     if os.access(PIDFILE, os.F_OK):
Radek Novacek 375ced
         print >>sys.stderr, "virt-who seems to be already running. If not, remove %s" % PIDFILE
Radek Novacek 375ced
         sys.exit(1)
Radek Novacek 375ced
+    createPidFile()
Radek Novacek 375ced
 
Radek Novacek 375ced
     parser = OptionParserEpilog(description="Agent for reporting virtual guest IDs to subscription-manager",
Radek Novacek 375ced
                                 epilog="virt-who also reads enviromental variables. They have the same name as command line arguments but uppercased, with underscore instead of dash and prefixed with VIRTWHO_ (e.g. VIRTWHO_ONE_SHOT). Empty variables are considered as disabled, non-empty as enabled")
Radek Novacek 375ced
@@ -425,6 +427,7 @@ def main():
Radek Novacek 375ced
         # Do a double-fork and other daemon initialization
Radek Novacek 375ced
         if not daemonize(options.debug):
Radek Novacek 375ced
             logger.error("Unable to fork, continuing in foreground")
Radek Novacek 375ced
+        createPidFile(logger)
Radek Novacek 375ced
 
Radek Novacek 375ced
     if not options.oneshot:
Radek Novacek 375ced
         if options.background and options.virtType == "libvirt":
Radek Novacek 375ced
@@ -444,8 +447,6 @@ def main():
Radek Novacek 375ced
     except Exception:
Radek Novacek 375ced
         pass
Radek Novacek 375ced
 
Radek Novacek 375ced
-    createPidFile(logger)
Radek Novacek 375ced
-
Radek Novacek 375ced
     logger.debug("Virt-who is running in %s mode" % options.virtType)
Radek Novacek 375ced
 
Radek Novacek 375ced
     if options.oneshot: