[XEND] Daemonise vncviewer when it is spawned from xend.

There are various reasons it should be daemonized, but the particular
problem we hit was that YaST called "xm create" and waited on output on
stdout/stderr; xm then spawned vncviewer (which never closed its
inherited stdout and stderr); xm then would exit, but YaST still had
open file descriptors, and therefore waited forever.  It would be
possible to work around in YaST, but it seemed cleaner to daemonize
vncviewer.

Signed-off-by:  Charles Coffing <ccoffing@novell.com>
This commit is contained in:
kaf24@firebug.cl.cam.ac.uk committed 2006-08-08 10:21:51 +01:00
1 parent baa7c435ce
commit 70858a054e
1 file changed
+48 -4
+48 -4
View File
@@ -844,14 +844,58 @@ def choose_vnc_display():
vncpid = None
def daemonize(prog, args):
"""Runs a program as a daemon with the list of arguments. Returns the PID
of the daemonized program, or returns 0 on error.
"""
r, w = os.pipe()
pid = os.fork()
if pid == 0:
os.close(r)
w = os.fdopen(w, 'w')
os.setsid()
try:
pid2 = os.fork()
except:
pid2 = None
if pid2 == 0:
os.chdir("/")
for fd in range(0, 256):
try:
os.close(fd)
except:
pass
os.open("/dev/null", os.O_RDWR)
os.dup2(0, 1)
os.dup2(0, 2)
os.execvp(prog, args)
os._exit(1)
else:
w.write(str(pid2 or 0))
w.close()
os._exit(0)
os.close(w)
r = os.fdopen(r)
daemon_pid = int(r.read())
r.close()
os.waitpid(pid, 0)
return daemon_pid
def spawn_vnc(display):
"""Spawns a vncviewer that listens on the specified display. On success,
returns the port that the vncviewer is listening on and sets the global
vncpid. On failure, returns 0. Note that vncviewer is daemonized.
"""
vncargs = (["vncviewer", "-log", "*:stdout:0",
"-listen", "%d" % (VNC_BASE_PORT + display) ])
global vncpid
vncpid = os.spawnvp(os.P_NOWAIT, "vncviewer", vncargs)
global vncpid
vncpid = daemonize("vncviewer", vncargs)
if vncpid == 0:
return 0
return VNC_BASE_PORT + display
def preprocess_vnc(vals):
"""If vnc was specified, spawn a vncviewer in listen mode
and pass its address to the domain on the kernel command line.
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.