[Xfce4-commits] <xfce4-weather-plugin:master> 2010-01-22 Colin Leroy <colin at colino.net>

Colin Leroy noreply at xfce.org
Mon Jan 25 08:40:01 CET 2010


Updating branch refs/heads/master
         to 5a11ada3578c1c81d817f5842308e32266e0a3e4 (commit)
       from 9e16920727c986cc44e61ae4e344083843cf1666 (commit)

commit 5a11ada3578c1c81d817f5842308e32266e0a3e4
Author: Colin Leroy <colin at colino.net>
Date:   Fri Jan 22 10:00:18 2010 +0100

    2010-01-22	Colin Leroy <colin at colino.net>
    
    	* panel-plugin/weather-http.c
    		Fix bug 5965, "weather plugin may deadlock on network error"
    		Patch by Leonid Evdokimov.
    		Also, test git commit.

 ChangeLog                   |    7 +++++++
 INSTALL                     |   17 ++++++++++++++---
 panel-plugin/weather-http.c |   41 ++++++++++++++++++++++++++++-------------
 3 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c87c92a..abd0701 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-01-22	Colin Leroy <colin at colino.net>
+
+	* panel-plugin/weather-http.c
+		Fix bug 5965, "weather plugin may deadlock on network error"
+		Patch by Leonid Evdokimov. 
+		Also, test git commit.
+
 2009-08-04	Colin Leroy <colin at colino.net>
 
 	Release 0.7.3
diff --git a/INSTALL b/INSTALL
index 8b82ade..2550dab 100644
--- a/INSTALL
+++ b/INSTALL
@@ -2,7 +2,7 @@ Installation Instructions
 *************************
 
 Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
-2006, 2007, 2008 Free Software Foundation, Inc.
+2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is free documentation; the Free Software Foundation gives
 unlimited permission to copy, distribute and modify it.
@@ -159,7 +159,7 @@ Particular systems
 CC is not installed, it is recommended to use the following options in
 order to use an ANSI C compiler:
 
-     ./configure CC="cc -Ae"
+     ./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
 
 and if that doesn't work, install pre-built binaries of GCC for HP-UX.
 
@@ -174,6 +174,16 @@ and if that doesn't work, try
 
      ./configure CC="cc -nodtk"
 
+   On Solaris, don't put `/usr/ucb' early in your `PATH'.  This
+directory contains several dysfunctional programs; working variants of
+these programs are available in `/usr/bin'.  So, if you need `/usr/ucb'
+in your `PATH', put it _after_ `/usr/bin'.
+
+   On Haiku, software installed for all users goes in `/boot/common',
+not `/usr/local'.  It is recommended to use the following options:
+
+     ./configure --prefix=/boot/common
+
 Specifying the System Type
 ==========================
 
@@ -189,7 +199,8 @@ type, such as `sun4', or a canonical name which has the form:
 
 where SYSTEM can have one of these forms:
 
-     OS KERNEL-OS
+     OS
+     KERNEL-OS
 
    See the file `config.sub' for the possible values of each field.  If
 `config.sub' isn't included in this package, then this package doesn't
diff --git a/panel-plugin/weather-http.c b/panel-plugin/weather-http.c
index 0fe7713..923a6a6 100644
--- a/panel-plugin/weather-http.c
+++ b/panel-plugin/weather-http.c
@@ -21,6 +21,8 @@
 #include <config.h>
 #endif
 
+#include <sys/select.h>
+#include <sys/time.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
@@ -146,6 +148,8 @@ weather_http_receive_data_idle (gpointer user_data)
   gchar               buffer[1024];
   gint                bytes, n, m;
   gchar              *request;
+  fd_set              fds;
+  struct timeval      select_timeout;
   
   struct addrinfo     h, *r, *a;
   gchar      	     *port = NULL;
@@ -312,16 +316,32 @@ weather_http_receive_data_idle (gpointer user_data)
   connection->received_len = 0;
 
   /* download the file content */
+  FD_ZERO (&fds);
   do
     {
-      /* download some bytes */
-      bytes = recv (connection->fd, buffer, sizeof (buffer) - sizeof (gchar), 0);
-
-      if (weather_http_receive_data_check (connection, timeout))
-        return FALSE;
+      /* FIXME: recv() may block. send() and connect() may block too and the
+       * only right solution is to rewrite whole code using non-blocking
+       * sockets, but that's hard, connect() is already protected with alarm()
+       * and send() blocks only when socket buffers are ultra-small */
+      FD_SET (connection->fd, &fds);
+      select_timeout.tv_sec = WEATHER_MAX_CONN_TIMEOUT;
+      select_timeout.tv_usec = 0;
+
+      m = select (connection->fd+1, &fds, 0, 0, &select_timeout);
+      if (G_LIKELY (m == 1))
+        {
+          bytes = recv (connection->fd, buffer, sizeof (buffer) - sizeof (gchar), 0);
+          if (G_LIKELY (bytes > 0))
+            {
+              /* prepend the downloaded data */
+              connection->received = g_realloc(connection->received, connection->received_len + bytes);
+              memcpy(connection->received+connection->received_len, buffer, bytes);
+              connection->received_len += bytes;
+            }
+        }
 
       /* check for problems */
-      if (G_UNLIKELY (bytes < 0))
+      if (G_UNLIKELY (m < 0 || bytes < 0))
         {
           /* display warning */
           g_warning (_("Failed to receive data (%s)"), g_strerror (errno));
@@ -332,16 +352,11 @@ weather_http_receive_data_idle (gpointer user_data)
           return FALSE;
         }
 
-      /* prepend the downloaded data */
-      connection->received = g_realloc(connection->received, connection->received_len + bytes);
-      memcpy(connection->received+connection->received_len, buffer, bytes);
-      connection->received_len += bytes;
+      if (weather_http_receive_data_check (connection, timeout))
+        return FALSE;
     }
   while (bytes > 0);
 
-  if (weather_http_receive_data_check (connection, timeout))
-    return FALSE;
-
   if (G_LIKELY (connection->received_len > 0))
     {
       /* get the pointer to the content-length */



More information about the Xfce4-commits mailing list