]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use os._exit after forking
authorAngus Lees <gus@inodes.org>
Fri, 15 May 2015 07:54:18 +0000 (17:54 +1000)
committerAngus Lees <gus@inodes.org>
Tue, 26 May 2015 00:11:52 +0000 (10:11 +1000)
As the docs point out(*), _exit should be used after a fork() to avoid
both processes flushing filehandles, calling destructors with side
effects, etc.  This change does just that.

(*) https://docs.python.org/2/library/os.html#os._exit

Change-Id: I68da6283c44ab8857baf217ac1443bd17988257d

neutron/agent/linux/daemon.py
neutron/tests/unit/agent/linux/test_daemon.py

index f180f5432287eae93b6898d40acdf58508adbefd..b4c7853b54a7327fbac63cf28db2ff7a5e9ee6a7 100644 (file)
@@ -173,7 +173,7 @@ class Daemon(object):
         try:
             pid = os.fork()
             if pid > 0:
-                sys.exit(0)
+                os._exit(0)
         except OSError:
             LOG.exception(_LE('Fork failed'))
             sys.exit(1)
index 4c01b6dbf8841da8f4eb56e1492c93584a329a7c..1ff0cc12268223ab7ad428fcb330e8cb6ce9cf52 100644 (file)
@@ -225,9 +225,9 @@ class TestDaemon(base.BaseTestCase):
 
     def test_fork_parent(self):
         self.os.fork.return_value = 1
-        with testtools.ExpectedException(SystemExit):
-            d = daemon.Daemon('pidfile')
-            d._fork()
+        d = daemon.Daemon('pidfile')
+        d._fork()
+        self.os._exit.assert_called_once_with(mock.ANY)
 
     def test_fork_child(self):
         self.os.fork.return_value = 0