The patch is incomplete. I'll send a version 2 of the patch.
Sorry for any inconvenience.
-Jan
Tue, Sep 16, 2014 at 10:49:52AM CEST, jtluka(a)redhat.com wrote:
The daemon code used just a single fork to detach lnst-slave and
become
a daemon. However this was insufficient and caused hangs when daemonized
inside Beaker jobs. The proper way is to use double fork method.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Common/Daemon.py | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/lnst/Common/Daemon.py b/lnst/Common/Daemon.py
index cf7dd22..2e13c72 100644
--- a/lnst/Common/Daemon.py
+++ b/lnst/Common/Daemon.py
@@ -64,6 +64,17 @@ class Daemon:
pid = os.fork()
if pid > 0:
sys.exit(0)
+ except OSError as e:
+ logging.error("fork failed: %d (%s)\n" % (e.errno, e.strerror))
+ sys.exit(1)
+
+ os.setsid()
+
+ # do the second fork
+ try:
+ pid = os.fork()
+ if pid > 0:
+ sys.exit(0)
pid = os.getpid()
self._write_pid(pid)
logging.info("deamonized with pid %d" % pid)
--
1.9.3