[PATCH] Don't wait for systemctl shutdown command to exit (#974383)

Brian C. Lane bcl at redhat.com
Tue Aug 6 16:58:14 UTC 2013


From: "Brian C. Lane" <bcl at redhat.com>

Using os.system to wait for shutdown means it blocks, we get a SIGTERM
but can't act on it so it delays for 90 seconds and sends SIGKILL,
making the shutdown slow.

Use subprocess.Popen instead so we can exit while systemctl does the
shutdown.

Also don't use sys.exit in forked child processes, they don't need to
call the exit handler, the parent will handle that.
---
 anaconda | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/anaconda b/anaconda
index 47e70e7..86b7295 100755
--- a/anaconda
+++ b/anaconda
@@ -71,11 +71,11 @@ def exitHandler(rebootData, storage, exitCode=None):
                 dracut_eject(drive.path)
 
         if rebootData.action == KS_SHUTDOWN:
-            os.system("systemctl --no-wall poweroff")
+            subprocess.Popen(["systemctl", "--no-wall", "poweroff"])
         elif rebootData.action == KS_WAIT:
-            os.system("systemctl --no-wall halt")
+            subprocess.Popen(["systemctl", "--no-wall", "halt"])
         else: # reboot action is KS_REBOOT or None
-            os.system("systemctl --no-wall reboot")
+            subprocess.Popen(["systemctl", "--no-wall", "reboot"])
 
 def startMetacityWM():
     childpid = os.fork()
@@ -89,10 +89,10 @@ def startMetacityWM():
         except BaseException as e:
             # catch all possible exceptions
             log.error("Problems running the window manager: %s" % str(e))
-            sys.exit(1)
+            os._exit(1)
 
         log.info("The window manager has terminated.")
-        sys.exit(0)
+        os._exit(0)
     return childpid
 
 def startAuditDaemon():
@@ -103,7 +103,7 @@ def startAuditDaemon():
             os.execl(cmd, cmd)
         except OSError as e:
             log.error("Error running the audit daemon: %s" % str(e))
-        sys.exit(0)
+        os._exit(0)
     # auditd will turn into a daemon so catch the immediate child pid now:
     os.waitpid(childpid, 0)
 
-- 
1.8.3.1



More information about the anaconda-patches mailing list