summaryrefslogtreecommitdiff
blob: b6843b64e923bbe6e38754d5c30b7911a3a2e615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From 285adc8acd22892f86435edd84bf9b22c915b349 Mon Sep 17 00:00:00 2001
From: Bill Wilson
Date: Wed, 5 Nov 2014 17:46:37 -0600
Subject: Avoid possible busy loop in read_server_setup()

A patch from Joe Garcia.  A ssh tunnel can be up but possibly not
connected to anything in which case gkrellm_getline() can return 0.
This patch prevents a busy loop by limiting the 0 return retries.

diff --git a/src/client.c b/src/client.c
index e7c5116..0eb2924 100644
--- a/src/client.c
+++ b/src/client.c
@@ -1712,8 +1712,10 @@ process_server_line(KeyTable *table, gint table_size, gchar *line)
 static gboolean
 read_server_setup(gint fd)
 	{
-	gchar			buf[4097]; /* TODO: Use dynamic receive buffer */
-	gint			table_size;
+	gchar	buf[4097]; /* TODO: Use dynamic receive buffer */
+	gint	table_size;
+	gint	rs;
+	gint	retries = 10;
 
 	gkrellm_debug(DEBUG_CLIENT, "read_server_setup()\n");
 
@@ -1726,13 +1728,18 @@ read_server_setup(gint fd)
 
 	gkrellm_free_glist_and_data(&client_plugin_setup_line_list);
 
-    gint rs;
-
 	while (1)
 		{
 		rs = gkrellm_getline(fd, buf, sizeof(buf));
-        if (rs < 0)
-            return FALSE;
+		if (rs < 0)
+			return FALSE;
+		if (rs == 0)
+			{
+			if (--retries)
+				usleep(10000);
+			else
+				return FALSE;
+			}
 		if (!strcmp(buf, "</gkrellmd_setup>"))
 			break;
 		process_server_line(&setup_table[0], table_size, buf);
@@ -1751,6 +1758,12 @@ read_server_setup(gint fd)
 		rs = gkrellm_getline(fd, buf, sizeof(buf));
         if (rs < 0)
             return FALSE;
+        if (rs==0){
+        	if(--retries)
+        		usleep(10000);
+        	else
+        		return FALSE;
+        }
 		if (!strcmp(buf, "</initial_update>"))
 			break;
 		process_server_line(&update_table[0], table_size, buf);
-- 
cgit v0.10.2-6-g49f6