All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Charles Coffing" <ccoffing@novell.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] properly daemonize vncviewer
Date: Tue, 01 Aug 2006 15:11:08 -0400	[thread overview]
Message-ID: <44CF52BA.D169.003C.0@novell.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 842 bytes --]

Hi,

Currently, vncviewer is spawned from xm, but it doesn't properly get
daemonized.  The attached patch makes vncviewer run completely separate
from xm.

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.

We've been running with a variant of this patch (a variant because we
use tightvnc, which requires different arguments) for many months, and
it works well.

Please consider applying to xen-unstable.

Thanks.

Signed-off-by:  Charles Coffing <ccoffing@novell.com>


[-- Attachment #2: xen-daemonize-vncviewer.diff --]
[-- Type: application/octet-stream, Size: 1663 bytes --]

Index: xen-unstable/tools/python/xen/xm/create.py
===================================================================
--- xen-unstable.orig/tools/python/xen/xm/create.py
+++ xen-unstable/tools/python/xen/xm/create.py
@@ -857,11 +857,49 @@ def choose_vnc_display():
 vncpid = None
 
 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)
 
+    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("vncviewer", vncargs)
+            os._exit(1)
+        else:
+            w.write(str(pid2 or 0))
+            w.close()
+            os._exit(0)
+
+    global vncpid
+    os.close(w)
+    r = os.fdopen(r)
+    vncpid = int(r.read())
+    r.close()
+    os.waitpid(pid, 0)
+    if vncpid == 0:
+        return 0
     return VNC_BASE_PORT + display
     
 def preprocess_vnc(vals):

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

             reply	other threads:[~2006-08-01 19:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-01 19:11 Charles Coffing [this message]
2006-08-02  8:32 ` [PATCH] properly daemonize vncviewer Keir Fraser
2006-08-02 18:19   ` Charles Coffing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44CF52BA.D169.003C.0@novell.com \
    --to=ccoffing@novell.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.