From bfb6fb08b8dbd7efc02a21c9d53cfc362d1b1786 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sun, 5 Oct 2014 16:22:43 +0300 Subject: Return early when remote DISPLAY variable set When DISPLAY is set to a remote display, the remote display server is down/unreachable and you su from user to root (or some other user), this can take ~30 seconds+ to complete. ps reveals ck-get-x11-server-pid is waiting on network connection to the xserver that will eventually timeout. Since it is impossible to get the process ID of the other end of a TCP connection (manpages say Xlib uses TCP connections when DISPLAY has a hostname: part) this patch skips getting the PID for remote DISPLAYs. References: If the DISPLAY variable has a hostname component, e.g. "remotehost:0.0", XOpenDisplay will use a TCP connection to it, and the fd it returns later will be a TCP socket. (http://tronche.com/gui/x/xlib/display/opening.html) It is only possible to get the peer socket's PID for UNIX domain sockets. (E.g. On linux, SO_PEERCRED is only usable for UNIX domain sockets (i.e. PF_UNIX) )( http://linux.die.net/man/7/socket) Bug report and patch provided by Joe Mullally. https://bugs.launchpad.net/ubuntu/+source/consolekit/+bug/517323 --- tools/ck-get-x11-server-pid.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tools') diff --git a/tools/ck-get-x11-server-pid.c b/tools/ck-get-x11-server-pid.c index 3324164..036a12a 100644 --- a/tools/ck-get-x11-server-pid.c +++ b/tools/ck-get-x11-server-pid.c @@ -47,6 +47,11 @@ display_init (int *argc, char ***argv) exit (1); } + if (display_name[0] != ':' && g_strrstr(display_name, ":") != NULL) { + g_warning ("DISPLAY is not a UNIX domain socket, can't get PID"); + exit (1); + } + xdisplay = XOpenDisplay (display_name); if (xdisplay == NULL) { g_warning ("cannot open display: %s", display_name ? display_name : ""); -- cgit v1.2.3