[network-manager-openconnect] Wait for "QUIT" command before exiting



commit d0c4ce17395d48566300e7bdd25a06617d13ecb3
Author: Dan Winship <danw gnome org>
Date:   Fri Apr 27 15:55:02 2012 -0400

    Wait for "QUIT" command before exiting
    
    According to the NM VPN auth dialog "protocol", the helper isn't
    supposed to exit until the caller sends "QUIT". Doing otherwise
    creates a race condition. Copy in the code that the other plugins use
    for this.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674991

 auth-dialog/main.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/auth-dialog/main.c b/auth-dialog/main.c
index 83e42eb..109531e 100644
--- a/auth-dialog/main.c
+++ b/auth-dialog/main.c
@@ -1407,6 +1407,30 @@ static auth_ui_data *init_ui_data (char *vpn_name, GHashTable *options, GHashTab
 	return ui_data;
 }
 
+static void wait_for_quit (void)
+{
+	GString *str;
+	char c;
+	ssize_t n;
+	time_t start;
+
+	str = g_string_sized_new (10);
+	start = time (NULL);
+	do {
+		errno = 0;
+		n = read (0, &c, 1);
+		if (n == 0 || (n < 0 && errno == EAGAIN))
+			g_usleep (G_USEC_PER_SEC / 10);
+		else if (n == 1) {
+			g_string_append_c (str, c);
+			if (strstr (str->str, "QUIT") || (str->len > 10))
+				break;
+		} else
+			break;
+	} while (time (NULL) < start + 20);
+	g_string_free (str, TRUE);
+}
+
 static struct option long_options[] = {
 	{"reprompt", 0, 0, 'r'},
 	{"uuid", 1, 0, 'u'},
@@ -1511,5 +1535,7 @@ int main (int argc, char **argv)
 	printf("\n\n");
 	fflush(stdout);
 
+	wait_for_quit ();
+
 	return _ui_data->retval;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]