Subject: [PATCH] Handle stale X11 lock files (Fixes: #630)

From: Horst Schirmeier <[email-masked]>
Date: Sat, 4 Oct 2014 13:15:13 +0200

Remove stale X11 lock files in cases where x2goagent mysteriously
disappeared (e.g., due to kill -9 or a crash).  This fixes bug #630
(and #626, which hasn't really been fixed yet).  Tested against the
original scenario from bug #626.
---
 x2goserver/sbin/x2gocleansessions | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/x2goserver/sbin/x2gocleansessions b/x2goserver/sbin/x2gocleansessions
index eb1bd3f..3b3775b 100755
--- a/x2goserver/sbin/x2gocleansessions
+++ b/x2goserver/sbin/x2gocleansessions
@@ -171,6 +171,11 @@ elsif ($pid == 0 )
 					syslog('warning', "@sinfo[1], pid @sinfo[0] cleaning up stale X11 socket file: /tmp/.X11-unix/X$display");
 					unlink("/tmp/.X11-unix/X$display");
 				}
+				if (-e "/tmp/.X$display-lock") {
+					# remove the NX-X11 lock file (as the agent will not have managed after a kill -9)
+					syslog('warning', "@sinfo[1], pid @sinfo[0] cleaning up stale X11 lock file: /tmp/.X$display-lock");
+					unlink("/tmp/.X$display-lock");
+				}
 				syslog('debug', "@sinfo[1]: unmounting all shares");
 				system( "su", "@sinfo[11]", "-c", "export HOSTNAME && x2goumount-session @sinfo[1]");
 			}
@@ -184,6 +189,12 @@ elsif ($pid == 0 )
 					syslog('warning', "@sinfo[1], pid @sinfo[0] cleaning up stale X11 socket file: /tmp/.X11-unix/X$display");
 					unlink("/tmp/.X11-unix/X$display");
 				}
+				if (-e "/tmp/.X$display-lock") {
+					# remove the NX-X11 lock file (we don't know how the agent disappeared,
+					# someone might have shot it with kill -9)
+					syslog('warning', "@sinfo[1], pid @sinfo[0] cleaning up stale X11 lock file: /tmp/.X$display-lock");
+					unlink("/tmp/.X$display-lock");
+				}
 				syslog('debug', "@sinfo[1], pid @sinfo[0] does not exist, changing status from @sinfo[4] to F");
 				syslog('debug', "@sinfo[1]: unmounting all shares");
 				system("su", "@sinfo[11]", "-c", "export HOSTNAME && x2goumount-session @sinfo[1]");
-- 
2.0.0.5.gbce14aa

-- 
PGP-Key 0xD40E0E7A