[gnome-continuous-yocto/gnomeostree-3.28-rocko: 6811/8267] bitbake: daemonize: Various fixes
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-continuous-yocto/gnomeostree-3.28-rocko: 6811/8267] bitbake: daemonize: Various fixes
- Date: Sun, 17 Dec 2017 05:22:07 +0000 (UTC)
commit 21a19e0e0bf1b39969f6f2ec37a5784d0069715b
Author: Richard Purdie <richard purdie linuxfoundation org>
Date: Tue Jul 18 22:22:12 2017 +0100
bitbake: daemonize: Various fixes
Currently if this code is used with something like oeqa's xml logging
it fails as sys.stdout is an io stream. Add in try/except to handle
this case.
Add a waitpid() call to remove a zombie whilst forking.
Also, append to the logfile, don't overwrite it (otherwise
debugging can be a real pain when the server is restarting for
unknown reasons).
(Bitbake rev: 4e780fa19fc720948cf73133f56f7d837ad9283a)
Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>
bitbake/lib/bb/daemonize.py | 20 ++++++++++++--------
1 files changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/bitbake/lib/bb/daemonize.py b/bitbake/lib/bb/daemonize.py
index ab4a954..8380828 100644
--- a/bitbake/lib/bb/daemonize.py
+++ b/bitbake/lib/bb/daemonize.py
@@ -29,6 +29,7 @@ __version__ = "0.2"
# Standard Python modules.
import os # Miscellaneous OS interfaces.
import sys # System-specific parameters and functions.
+import io
# Default daemon parameters.
# File mode creation mask of the daemon.
@@ -124,6 +125,7 @@ def createDaemon(function, logfile):
# streams to be flushed twice and any temporary files may be unexpectedly
# removed. It's therefore recommended that child branches of a fork()
# and the parent branch(es) of a daemon use _exit().
+ os.waitpid(pid, 0)
return
# Close all open file descriptors. This prevents the child from keeping
@@ -177,16 +179,18 @@ def createDaemon(function, logfile):
# os.dup2(0, 1) # standard output (1)
# os.dup2(0, 2) # standard error (2)
-
- si = open('/dev/null', 'r')
- so = open(logfile, 'w')
- se = so
-
-
# Replace those fds with our own
+ si = open('/dev/null', 'r')
os.dup2(si.fileno(), sys.stdin.fileno())
- os.dup2(so.fileno(), sys.stdout.fileno())
- os.dup2(se.fileno(), sys.stderr.fileno())
+
+ try:
+ so = open(logfile, 'a+')
+ se = so
+ os.dup2(so.fileno(), sys.stdout.fileno())
+ os.dup2(se.fileno(), sys.stderr.fileno())
+ except io.UnsupportedOperation:
+ sys.stdout = open(logfile, 'a+')
+ sys.stderr = sys.stdout
function()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]