mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
bitkeeper revision 1.1159.79.4 (414ea99cE4RZfWihQhMkvClcGfAGEA)
Daemonization fixes for xend. For some reason I cannot capture output from C extensions that use printf/fprintf to stdout and stderr. This can't be hard to fix though.
This commit is contained in:
1 parent
bc7cec1fbd
commit
e6ff15b27e
1 file changed
+19
-9
@@ -42,7 +42,7 @@ import console
|
||||
import domain
|
||||
from params import *
|
||||
|
||||
DEBUG = 0
|
||||
DEBUG = 1
|
||||
|
||||
class NotifierProtocol(protocol.Protocol):
|
||||
"""Asynchronous handler for i/o on the notifier (event channel).
|
||||
@@ -475,14 +475,24 @@ class Daemon:
|
||||
xfrd_pid = self.cleanup_xfrd()
|
||||
|
||||
# Detach from TTY.
|
||||
if not DEBUG:
|
||||
os.setsid()
|
||||
sys.stdin.close();
|
||||
sys.stdout.close();
|
||||
sys.stderr.close();
|
||||
os.close(0);
|
||||
os.close(1);
|
||||
os.close(2);
|
||||
os.setsid()
|
||||
|
||||
# Detach from standard file descriptors.
|
||||
# I do this at the file-descriptor level: the overlying Python file
|
||||
# objects also use fd's 0, 1 and 2.
|
||||
os.close(0)
|
||||
os.close(1)
|
||||
os.close(2)
|
||||
if DEBUG:
|
||||
os.open('/dev/null', os.O_RDONLY)
|
||||
# XXX KAF: Why doesn't this capture output from C extensions that
|
||||
# fprintf(stdout) or fprintf(stderr) ??
|
||||
os.open('/var/log/xend-debug.log', os.O_WRONLY|os.O_CREAT)
|
||||
else:
|
||||
os.open('/dev/null', os.O_RDWR)
|
||||
os.dup(0)
|
||||
os.dup(1)
|
||||
|
||||
if self.set_user():
|
||||
return 4
|
||||
os.chdir("/")
|
||||
|
||||