File x11vnc-thread-auth.diff of Package x11vnc

Index: x11vnc-0.9.4/x11vnc/x11vnc.c
===================================================================
--- x11vnc-0.9.4.orig/x11vnc/x11vnc.c
+++ x11vnc-0.9.4/x11vnc/x11vnc.c
@@ -1131,8 +1131,40 @@ void check_filexfer(void) {
 		last_check = time(NULL);
 	}
 }
 
+/* 
+ * Terrible hack for the multithreaded x11vnc ...
+ * But we get the client confused if we start sending stuff in our
+ * main loop prior to it being initialized properly. So wait.
+ * It's polling :-(
+ */
+static void _mt_wait_for_client()
+{
+	time_t start = time(0);
+	while (!client_count) {
+		if (first_conn_timeout && time(0) - start > first_conn_timeout)
+			return;
+		usleep(100*1000);
+	}
+	while (1) {
+		rfbClientIteratorPtr iter;
+		rfbClientPtr cl;
+		iter = rfbGetClientIterator(screen);
+		while( (cl = rfbClientIteratorNext(iter)) ) {
+			//ClientData *cd = (ClientData *) cl->clientData;
+			if (cl->state == RFB_NORMAL) {
+				rfbReleaseClientIterator(iter);
+				return;
+			}
+		}
+		rfbReleaseClientIterator(iter);
+		if (first_conn_timeout && time(0) - start > first_conn_timeout)
+			return;
+		usleep(100*1000);
+	}
+}
+
 /*
  * main x11vnc loop: polls, checks for events, iterate libvncserver, etc.
  */
 static void watch_loop(void) {
@@ -1141,8 +1173,9 @@ static void watch_loop(void) {
 	time_t start = time(NULL);
 
 	if (use_threads) {
 		rfbRunEventLoop(screen, -1, TRUE);
+		_mt_wait_for_client();
 	}
 
 	while (1) {
 		char msg[] = "new client: %s taking unixpw client off hold.\n";
openSUSE Build Service is sponsored by