gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3323 - in GNUnet/src: applications/identity server transpo


From: grothoff
Subject: [GNUnet-SVN] r3323 - in GNUnet/src: applications/identity server transports util/config_impl util/disk util/network util/network_client util/os util/threads
Date: Sat, 26 Aug 2006 20:00:24 -0700 (PDT)

Author: grothoff
Date: 2006-08-26 20:00:13 -0700 (Sat, 26 Aug 2006)
New Revision: 3323

Added:
   GNUnet/src/util/os/check.conf
Modified:
   GNUnet/src/applications/identity/hostkey.c
   GNUnet/src/applications/identity/identity.c
   GNUnet/src/server/startup.c
   GNUnet/src/server/tcpserver.c
   GNUnet/src/server/version.c
   GNUnet/src/transports/ip.c
   GNUnet/src/transports/ip6.c
   GNUnet/src/transports/tcp.c
   GNUnet/src/transports/udp.c
   GNUnet/src/util/config_impl/impl.c
   GNUnet/src/util/disk/storage.c
   GNUnet/src/util/network/io.c
   GNUnet/src/util/network/select.c
   GNUnet/src/util/network_client/daemon.c
   GNUnet/src/util/network_client/tcpio.c
   GNUnet/src/util/os/Makefile.am
   GNUnet/src/util/os/daemontest.c
   GNUnet/src/util/threads/pthread.c
Log:
fixing various bugs

Modified: GNUnet/src/applications/identity/hostkey.c
===================================================================
--- GNUnet/src/applications/identity/hostkey.c  2006-08-26 09:18:10 UTC (rev 
3322)
+++ GNUnet/src/applications/identity/hostkey.c  2006-08-27 03:00:13 UTC (rev 
3323)
@@ -117,10 +117,15 @@
   FREE(gnHome);
   strcat(hostkeyfile, "/");
   strcat(hostkeyfile, HOSTKEYFILE);
-  res = disk_file_read(ectx,
-                      hostkeyfile,
-                      sizeof(unsigned short),
-                      &len);
+  res = 0;
+  if (disk_file_test(ectx,
+                    hostkeyfile)) {
+    res = disk_file_read(ectx,
+                        hostkeyfile,
+                        sizeof(unsigned short),
+                        &len);
+  }
+  encPrivateKey = NULL;
   if (res == sizeof(unsigned short)) {
     encPrivateKey = (PrivateKeyEncoded*) MALLOC(ntohs(len));
     if (ntohs(len) !=
@@ -135,8 +140,7 @@
             hostkeyfile);
       encPrivateKey = NULL;
     }
-  } else
-    encPrivateKey = NULL;
+  }
   if (encPrivateKey == NULL) { /* make new hostkey */
     GE_LOG(ectx,
           GE_INFO | GE_USER | GE_BULK,

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2006-08-26 09:18:10 UTC (rev 
3322)
+++ GNUnet/src/applications/identity/identity.c 2006-08-27 03:00:13 UTC (rev 
3323)
@@ -219,11 +219,13 @@
     fn = MALLOC(strlen(trustDirectory)+sizeof(EncName)+1);
     strcpy(fn, trustDirectory);
     strcat(fn, (char*) &fil);
-    if (sizeof(unsigned int) ==
-       disk_file_read(ectx, 
-                      fn,
-                      sizeof(unsigned int),
-                      &trust)) {
+    if ( (disk_file_test(ectx,
+                        fn) == YES) &&
+        (sizeof(unsigned int) ==
+         disk_file_read(ectx, 
+                        fn,
+                        sizeof(unsigned int),
+                        &trust)) ) {
       entry->trust = ntohl(trust);
     } else {
       entry->trust = 0;
@@ -337,18 +339,33 @@
                    strlen(networkIdDirectory) + 1);
   strcpy(fullname, networkIdDirectory);
   strcat(fullname, filename);
-  if (0 == UNLINK(fullname))
-    GE_LOG(ectx,
-          GE_WARNING | GE_USER | GE_ADMIN | GE_BULK,
-          _("File `%s' in directory `%s' does not match naming convention. "
-            "Removed.\n"),
-          filename,
-          networkIdDirectory);
-  else
-    GE_LOG_STRERROR_FILE(ectx,
-                        GE_ERROR | GE_USER | GE_BULK,
-                        "unlink",
-                        fullname);
+  if (disk_file_test(ectx, fullname) == YES) {
+    if (0 == UNLINK(fullname))
+      GE_LOG(ectx,
+            GE_WARNING | GE_USER | GE_ADMIN | GE_BULK,
+            _("File `%s' in directory `%s' does not match naming convention. "
+              "Removed.\n"),
+            filename,
+            networkIdDirectory);
+    else
+      GE_LOG_STRERROR_FILE(ectx,
+                          GE_ERROR | GE_USER | GE_BULK,
+                          "unlink",
+                          fullname);
+  } else if (disk_directory_test(ectx, fullname) == YES) {
+    if (0 == RMDIR(fullname)) 
+      GE_LOG(ectx,
+            GE_WARNING | GE_USER | GE_ADMIN | GE_BULK,
+            _("Directory `%s' in directory `%s' does not match naming 
convention. "
+              "Removed.\n"),
+            filename,
+            networkIdDirectory);
+    else
+      GE_LOG_STRERROR_FILE(ectx,
+                          GE_ERROR | GE_USER | GE_BULK,
+                          "rmdir",
+                          fullname);
+  }
   FREE(fullname);
   return OK;
 }
@@ -519,16 +536,19 @@
   fn = getHostFileName(&msg->senderIdentity,
                       ntohs(msg->protocol));
   buffer = MALLOC(MAX_BUFFER_SIZE);
-  size = disk_file_read(ectx,
-                       fn,
-                       MAX_BUFFER_SIZE,
-                       buffer);
-  oldMsg = (P2P_hello_MESSAGE*) buffer;
-  if ((unsigned int)size == P2P_hello_MESSAGE_size(oldMsg)) {
-    if (ntohl(oldMsg->expirationTime) > ntohl(msg->expirationTime)) {
-      FREE(fn);
-      FREE(buffer);
-      return; /* have more recent hello in stock */
+  if (disk_file_test(ectx,
+                    fn) == YES) {
+    size = disk_file_read(ectx,
+                         fn,
+                         MAX_BUFFER_SIZE,
+                         buffer);
+    oldMsg = (P2P_hello_MESSAGE*) buffer;
+    if ((unsigned int)size == P2P_hello_MESSAGE_size(oldMsg)) {
+      if (ntohl(oldMsg->expirationTime) > ntohl(msg->expirationTime)) {
+       FREE(fn);
+       FREE(buffer);
+       return; /* have more recent hello in stock */
+      }
     }
   }
   disk_file_write(ectx,
@@ -1116,6 +1136,7 @@
                                                      &gnHome));
   if (gnHome == NULL)
     return NULL;
+  disk_directory_create(ectx, gnHome);
   tmp = MALLOC(strlen(gnHome) + strlen(HOST_DIR) + 2);
   strcpy(tmp, gnHome);
   strcat(tmp, DIR_SEPARATOR_STR);

Modified: GNUnet/src/server/startup.c
===================================================================
--- GNUnet/src/server/startup.c 2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/server/startup.c 2006-08-27 03:00:13 UTC (rev 3323)
@@ -44,15 +44,15 @@
   if (0 == GC_get_configuration_value_string(cfg,
                                             "GNUNETD",
                                             "USER",
-                                            NULL,
+                                            "",
                                             &user)) {
     if (OK != os_change_user(ectx,
                             user)) {
       FREE(user);
       return SYSERR;
     }
-    FREE(user);
   }
+  FREE(user);
   return OK;
 }
 

Modified: GNUnet/src/server/tcpserver.c
===================================================================
--- GNUnet/src/server/tcpserver.c       2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/server/tcpserver.c       2006-08-27 03:00:13 UTC (rev 3323)
@@ -147,14 +147,16 @@
                                    unsigned int addr_len) {
   struct ClientHandle * session;
   IPaddr ip;
+  struct sockaddr_in * a;
 
-  if (addr_len != sizeof(IPaddr))
-    return NULL;
+  if (addr_len != sizeof(struct sockaddr_in)) 
+    return NULL;  
+  a = (struct sockaddr_in *) addr;
   memcpy(&ip,
-        addr,
-        addr_len);
-  if (! isWhitelisted(ip))
-    return NULL;
+        &a->sin_addr,
+        sizeof(IPaddr));
+  if (! isWhitelisted(ip)) 
+    return NULL;  
   session = MALLOC(sizeof(ClientHandle));
   session->sock = sock;
   return session;
@@ -183,6 +185,10 @@
  */
 int sendToClient(struct ClientHandle * handle,
                 const MESSAGE_HEADER * message) {
+  GE_LOG(ectx,
+        GE_INFO | GE_USER | GE_BULK,
+        "%s: sending reply to client\n",
+        __FUNCTION__);
   return select_write(selector,
                      handle->sock,
                      message,
@@ -208,7 +214,7 @@
   MUTEX_LOCK(handlerlock);
   if (ptyp >= max_registeredType) {
     GE_LOG(ectx,
-          GE_INFO,
+          GE_INFO | GE_USER | GE_BULK,
           "%s: Message of type %d not understood: no handler registered\n",
           __FUNCTION__,
           ptyp,
@@ -219,7 +225,7 @@
   callback = handlers[ptyp];
   if (callback == NULL) {
     GE_LOG(ectx,
-          GE_INFO,
+          GE_INFO | GE_USER | GE_BULK,
           "%s: Message of type %d not understood: no handler registered\n",
           __FUNCTION__,
           ptyp);
@@ -228,6 +234,13 @@
   } else {
     if (OK != callback(sender,
                       msg)) {
+#if 0
+      GE_LOG(ectx,
+            GE_INFO | GE_USER | GE_BULK,
+            "%s: Message of type %d caused error in handler\n",
+            __FUNCTION__,
+            ptyp);
+#endif
       MUTEX_UNLOCK(handlerlock);
       return SYSERR;
     }
@@ -242,7 +255,6 @@
  * the config file.
  */
 static unsigned short getGNUnetPort() {
-  struct servent * pse;        /* pointer to service information entry */
   unsigned long long port;
 
   if (-1 == GC_get_configuration_value_number(cfg,
@@ -250,13 +262,9 @@
                                              "PORT",
                                              1,
                                              65535,
-                                             2086,
-                                             &port)) {
-    if ((pse = getservbyname("gnunet", "tcp")))
-      port = htons(pse->s_port);
-    else
-      port = 0;
-  }
+                                             2087,
+                                             &port)) 
+    port = 0; 
   return (unsigned short) port;
 }
 
@@ -350,7 +358,7 @@
   selector = select_create(e,
                           NULL,
                           listenerFD,
-                          sizeof(IPaddr),
+                          sizeof(struct sockaddr_in),
                           0, /* no timeout */
                           &select_message_handler,
                           NULL,

Modified: GNUnet/src/server/version.c
===================================================================
--- GNUnet/src/server/version.c 2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/server/version.c 2006-08-27 03:00:13 UTC (rev 3323)
@@ -30,7 +30,8 @@
 #include "gnunet_directories.h"
 #include "version.h"
 
-#define VERSIONFILE "state.sdb/GNUNET-VERSION"
+#define VERSIONFILE "/state.sdb/GNUNET-VERSION"
+#define VERSIONDIR "/state.sdb/"
 
 /**
  * Extend string by "section:part=val;" where
@@ -128,6 +129,9 @@
     return NULL;
   cn = MALLOC(strlen(en) + strlen(VERSIONFILE) + 1);
   strcpy(cn, en);
+  strcat(cn, VERSIONDIR);
+  disk_directory_create(ectx, cn);
+  strcpy(cn, en);
   strcat(cn, VERSIONFILE);
   FREE(en);
   return cn;
@@ -153,12 +157,18 @@
           _("Failed to determine filename used to store GNUnet version 
information!\n"));
     return OK; /* uh uh */
   }
+  if (disk_file_test(ectx,
+                    fn) != YES) {
+    FREE(fn);
+    upToDate(ectx, cfg); /* first start */
+    return OK;
+  }
   len = disk_file_read(ectx,
                       fn,
                       MAX_VS,
                       version);
   FREE(fn);
-  if (len == -1) {
+  if (len == -1) { /* should never happen -- file should exist */
     upToDate(ectx,
             cfg); /* first start */
     return OK;

Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c  2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/transports/ip.c  2006-08-27 03:00:13 UTC (rev 3323)
@@ -147,10 +147,10 @@
   }
   GE_LOG(ectx,
         GE_WARNING | GE_ADMIN | GE_USER | GE_BULK,
-        _("Could not find interface `%s' in `%s', "
+        _("Could not find interface `%s' using `%s', "
           "trying to find another interface.\n"),
-        "ioctl",
-      interfaces);
+        interfaces,
+        "ioctl");
   /* if no such interface exists, take any interface but loopback */
   for (i=0;i<ifCount;i++){
     if (ioctl(sockfd, SIOCGIFADDR, &ifr[i]) != 0)
@@ -180,8 +180,8 @@
   GE_LOG(ectx,
         GE_WARNING | GE_USER | GE_BULK,
         _("Could not obtain IP for interface `%s' using `%s'.\n"),
-        "ioctl",
-      interfaces);
+        interfaces,
+        "ioctl");
   FREE(interfaces);
   return SYSERR;
 #else /* MinGW */
@@ -305,10 +305,11 @@
   char * ipString;
   int retval;
 
+  ipString = NULL;
   if (0 != GC_get_configuration_value_string(cfg,
                                             "NETWORK",
                                             "IP",
-                                            NULL,
+                                            "",
                                             &ipString)) {
 #if LINUX || SOMEBSD || MINGW
     if (OK == getAddressFromIOCTL(cfg,
@@ -323,8 +324,8 @@
     retval = get_host_by_name(ectx,
                              ipString,
                              address);
-    FREE(ipString);
   }
+  FREE(ipString);
   return retval;
 }
 

Modified: GNUnet/src/transports/ip6.c
===================================================================
--- GNUnet/src/transports/ip6.c 2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/transports/ip6.c 2006-08-27 03:00:13 UTC (rev 3323)
@@ -92,10 +92,11 @@
   struct hostent * ip; /* for the lookup of the IP in gnunet.conf */
 
   retval = SYSERR;
+  ipString = NULL;
   if (0 != GC_get_configuration_value_string(cfg,
                                             "NETWORK",
                                             "IP",
-                                            NULL,
+                                            "",
                                             &ipString)) {
     retval = getAddress6FromHostname(ectx,
                                     address);
@@ -123,8 +124,8 @@
        retval = OK;
       }
     }
-    FREE(ipString);
   }
+  FREE(ipString);  
   return retval;
 }
 

Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/transports/tcp.c 2006-08-27 03:00:13 UTC (rev 3323)
@@ -347,18 +347,15 @@
        
   MUTEX_LOCK(tcplock);
   FREENONNULL(filteredNetworks_);
-  if (0 != GC_get_configuration_value_string(cfg,
-                                            "TCP",
-                                            "BLACKLIST",
-                                            NULL,
-                                            &ch)) 
-    filteredNetworks_ = parse_ipv4_network_specification(ectx,
-                                                        "");
-  else {
-    filteredNetworks_ = parse_ipv4_network_specification(ectx,
-                                                        ch);
-    FREE(ch);
-  }
+  ch = NULL;
+  GC_get_configuration_value_string(cfg,
+                                   "TCP",
+                                   "BLACKLIST",
+                                   "",
+                                   &ch);
+  filteredNetworks_ = parse_ipv4_network_specification(ectx,
+                                                      ch);
+  FREE(ch);
   MUTEX_UNLOCK(tcplock);
   /* TODO: error handling! */
   return 0;

Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/transports/udp.c 2006-08-27 03:00:13 UTC (rev 3323)
@@ -371,18 +371,15 @@
 
   MUTEX_LOCK(configLock);
   FREENONNULL(filteredNetworks_);
-  if (0 != GC_get_configuration_value_string(cfg,
-                                            "UDP",
-                                            "BLACKLIST",
-                                            NULL,
-                                            &ch)) 
-    filteredNetworks_ = parse_ipv4_network_specification(ectx,
-                                                        "");
-  else {
-    filteredNetworks_ = parse_ipv4_network_specification(ectx,
-                                                        ch);
-    FREE(ch);
-  }
+  ch = NULL;
+  GC_get_configuration_value_string(cfg,
+                                   "UDP",
+                                   "BLACKLIST",
+                                   "",
+                                   &ch);
+  filteredNetworks_ = parse_ipv4_network_specification(ectx,
+                                                      ch);
+  FREE(ch);  
   MUTEX_UNLOCK(configLock);
   return 0;
 }

Modified: GNUnet/src/util/config_impl/impl.c
===================================================================
--- GNUnet/src/util/config_impl/impl.c  2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/util/config_impl/impl.c  2006-08-27 03:00:13 UTC (rev 3323)
@@ -210,7 +210,7 @@
     if (emptyline == 1)
       continue;
     /* remove tailing whitespace */
-    for (i=strlen(line)-1;(i>=0) && (line[i] == ' ');i--)
+    for (i=strlen(line)-1;(i>=0) && (isspace(line[i]));i--)
       line[i] = '\0';
     if (1 == sscanf(line, "@INLINE@ %191[^\n]", value) ) {
       /* @INLINE@ value */
@@ -232,8 +232,8 @@
       /* tag = value */
       /* Strip LF */
       i = strlen(value) - 1;
-      if (i >= 0 && value[i] == '\r')
-        value[i] = '\0';
+      while ((i >= 0) && (isspace(value[i])))
+        value[i--] = '\0';
       /* remove quotes */
       i = 0;
       if (value[0] == '"') {
@@ -622,35 +622,6 @@
   return ret;
 }
 
-/**
- * Get a configuration value that should be a string.
- * @param def default value (use indicated by return value;
- *        will NOT be aliased, maybe NULL)
- * @param value will be set to a freshly allocated configuration
- *        value, or NULL if option is not specified and no default given
- * @return 0 on success, -1 on error, 1 for default
- */
-static int 
-_get_configuration_value_filename(struct GC_Configuration * cfg,
-                                 const char * section,
-                                 const char * option,
-                                 const char * def,
-                                 char ** value) {
-  GC_ConfigurationData * data;
-  int ret;
-  char * tmp;
-  
-  data = cfg->data;
-  tmp = NULL;
-  ret = _get_configuration_value_string(cfg, section, option, def, &tmp);
-  if (tmp != NULL) {
-    *value = string_expandFileName(data->ectx, tmp);
-    FREE(tmp);
-  } else {
-    *value = NULL;
-  }
-  return ret;
-}
 
 /**
  * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
@@ -668,6 +639,8 @@
   char * prefix;
   char * result;
 
+  if (orig[0] != '$')
+    return orig;
   i = 0;
   while ( (orig[i] != '/') &&
          (orig[i] != '\\') &&
@@ -706,7 +679,41 @@
   return result;
 }
 
+/**
+ * Get a configuration value that should be a string.
+ * @param def default value (use indicated by return value;
+ *        will NOT be aliased, maybe NULL)
+ * @param value will be set to a freshly allocated configuration
+ *        value, or NULL if option is not specified and no default given
+ * @return 0 on success, -1 on error, 1 for default
+ */
 static int 
+_get_configuration_value_filename(struct GC_Configuration * cfg,
+                                 const char * section,
+                                 const char * option,
+                                 const char * def,
+                                 char ** value) {
+  GC_ConfigurationData * data;
+  int ret;
+  char * tmp;
+  
+  data = cfg->data;
+  tmp = NULL;
+  ret = _get_configuration_value_string(cfg, section, option, def, &tmp);
+  if (tmp != NULL) {
+    tmp = _configuration_expand_dollar(cfg,
+                                      section,
+                                      tmp);
+    *value = string_expandFileName(data->ectx, 
+                                  tmp);
+    FREE(tmp);
+  } else {
+    *value = NULL;
+  }
+  return ret;
+}
+
+static int 
 _set_configuration_value_number(struct GC_Configuration * cfg,
                                struct GE_Context * ectx,
                                const char * section,

Modified: GNUnet/src/util/disk/storage.c
===================================================================
--- GNUnet/src/util/disk/storage.c      2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/util/disk/storage.c      2006-08-27 03:00:13 UTC (rev 3323)
@@ -352,8 +352,8 @@
          FREE(rdir);
          return SYSERR;
        }
-       rdir[pos] = DIR_SEPARATOR;
       }
+      rdir[pos] = DIR_SEPARATOR;     
     }
     pos++;
   }

Modified: GNUnet/src/util/network/io.c
===================================================================
--- GNUnet/src/util/network/io.c        2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/util/network/io.c        2006-08-27 03:00:13 UTC (rev 3323)
@@ -94,8 +94,9 @@
 
 void socket_destroy(struct SocketHandle * s) {
   GE_ASSERT(NULL, s != NULL);
-  if (0 != SHUTDOWN(s->handle,
-                   SHUT_RDWR))
+  if ( (0 != SHUTDOWN(s->handle,
+                   SHUT_RDWR)) &&
+       (errno != ENOTCONN) ) 
     GE_LOG_STRERROR(s->ectx,
                    GE_WARNING | GE_ADMIN | GE_BULK, 
                    "shutdown");
@@ -153,7 +154,7 @@
   size_t ret;
 
   socket_set_blocking(s, 
-                     0 == (nc & NC_Blocking));
+                     0 != (nc & NC_Blocking));
   flags = 0;
 #ifdef CYGWIN
   if (0 == (nc & NC_IgnoreInt))
@@ -179,17 +180,16 @@
                        flags);
     if ( (ret == (size_t) -1) &&
         (errno == EINTR) &&
-        (0 != (nc & NC_IgnoreInt)) )
-      continue;
+        (0 != (nc & NC_IgnoreInt)) ) 
+      continue;    
     if (ret == (size_t) -1) {
       if (errno == EINTR) {
        *read = pos;
        return YES;
       }
-      if ( (errno == EAGAIN) ||
-          (errno == EWOULDBLOCK) ) {
-       if (0 != (nc & NC_Blocking))
-         continue;
+      if (errno == EWOULDBLOCK) {
+       if (0 != (nc & NC_Blocking)) 
+         continue;     
        *read = pos;
        return (pos == 0) ? NO : YES;
       }
@@ -199,6 +199,11 @@
       *read = pos;
       return SYSERR;
     }
+    if (ret == 0) {
+      /* most likely: other side closed connection */
+      *read = pos;
+      return SYSERR; 
+    }
     pos += ret;
   } while ( (pos < max) &&
            (0 != (nc & NC_Blocking)) );
@@ -218,7 +223,7 @@
   size_t ret;
 
   socket_set_blocking(s, 
-                     0 == (nc & NC_Blocking));
+                     0 != (nc & NC_Blocking));
   flags = 0;
 #ifdef CYGWIN
   if (0 == (nc & NC_IgnoreInt))
@@ -253,8 +258,7 @@
        *read = pos;
        return YES;
       }
-      if ( (errno == EAGAIN) ||
-          (errno == EWOULDBLOCK) ) {
+      if (errno == EWOULDBLOCK) {
        if (0 != (nc & NC_Blocking))
          continue;
        *read = pos;
@@ -266,6 +270,11 @@
       *read = pos;
       return SYSERR;
     }
+    if (ret == 0) {
+      /* most likely: other side closed connection */
+      *read = pos;
+      return SYSERR; 
+    }
     pos += ret;
   } while ( (pos < max) &&
            (0 != (nc & NC_Blocking)) );
@@ -283,7 +292,7 @@
   size_t ret;
 
   socket_set_blocking(s, 
-                     0 == (nc & NC_Blocking));
+                     0 != (nc & NC_Blocking));
   flags = 0;
 #if SOMEBSD || SOLARIS
   if (0 == (nc & NC_Blocking))
@@ -317,8 +326,7 @@
        *sent = pos;
        return YES;
       }
-      if ( (errno == EAGAIN) ||
-          (errno == EWOULDBLOCK) ) {
+      if (errno == EWOULDBLOCK) {
        if (0 != (nc & NC_Blocking))
          continue;
        *sent = pos;
@@ -330,6 +338,11 @@
       *sent = pos;
       return SYSERR;
     }
+    if (ret == 0) {
+      /* strange error; most likely: other side closed connection */
+      *sent = pos;
+      return SYSERR; 
+    }
     pos += ret;
   } while ( (pos < max) &&
            (0 != (nc & NC_Blocking)) );
@@ -349,7 +362,7 @@
   size_t ret;
 
   socket_set_blocking(s, 
-                     0 == (nc & NC_Blocking));
+                     0 != (nc & NC_Blocking));
   flags = 0;
 #if SOMEBSD || SOLARIS
   if (0 == (nc & NC_Blocking))
@@ -385,8 +398,7 @@
        *sent = pos;
        return YES;
       }
-      if ( (errno == EAGAIN) ||
-          (errno == EWOULDBLOCK) ) {
+      if (errno == EWOULDBLOCK) {
        if (0 != (nc & NC_Blocking))
          continue;
        *sent = pos;
@@ -398,6 +410,11 @@
       *sent = pos;
       return SYSERR;
     }
+    if (ret == 0) {
+      /* strange error; most likely: other side closed connection */
+      *sent = pos;
+      return SYSERR; 
+    }
     pos += ret;
   } while ( (pos < max) &&
            (0 != (nc & NC_Blocking)) );

Modified: GNUnet/src/util/network/select.c
===================================================================
--- GNUnet/src/util/network/select.c    2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/util/network/select.c    2006-08-27 03:00:13 UTC (rev 3323)
@@ -225,7 +225,7 @@
         session->rsize + 1024);
   }
   ret = socket_recv(session->sock,
-                   NC_Blocking | NC_IgnoreInt, 
+                   NC_Nonblocking | NC_IgnoreInt, 
                    &session->rbuff[session->pos],
                    session->rsize - session->pos,
                    &recvd);
@@ -254,11 +254,14 @@
     if (session->pos < len) 
       break; /* wait for more */    
 
-    sh->mh(sh->mh_cls,
-          sh,
-          session->sock,
-          session->sock_ctx,
-          pack);
+    if (OK != sh->mh(sh->mh_cls,
+                    sh,
+                    session->sock,
+                    session->sock_ctx,
+                    pack)) {
+      destroySession(sh, session);
+      return SYSERR;
+    }
     /* shrink buffer adequately */
     memmove(&session->rbuff[0],
            &session->rbuff[len],
@@ -551,7 +554,8 @@
                             unsigned int memory_quota) {
   SelectHandle * sh;
 
-  if (0 != LISTEN(sock, 5)) {
+  if ( (0 != LISTEN(sock, 5)) &&
+       (errno != EOPNOTSUPP) ) { /* udp: not supported */
     GE_LOG_STRERROR(ectx,
                    GE_ERROR | GE_USER | GE_IMMEDIATE,
                    "listen");
@@ -588,7 +592,7 @@
   sh->ch_cls = ch_cls;
   sh->memory_quota = memory_quota;
   sh->timeout = timeout;
-  sh->lock = MUTEX_CREATE(NO);
+  sh->lock = MUTEX_CREATE(YES);
   sh->listen_sock = socket_create(ectx,
                                  mon,
                                  sock);

Modified: GNUnet/src/util/network_client/daemon.c
===================================================================
--- GNUnet/src/util/network_client/daemon.c     2006-08-26 09:18:10 UTC (rev 
3322)
+++ GNUnet/src/util/network_client/daemon.c     2006-08-27 03:00:13 UTC (rev 
3323)
@@ -88,15 +88,23 @@
 int connection_wait_for_running(struct GE_Context * ectx,
                                struct GC_Configuration * cfg,
                                cron_t timeout) {
+  cron_t min;
+  int ret;
+
   timeout += get_time();
-  while (OK != connection_test_running(ectx,
-                                      cfg)) {
-    PTHREAD_SLEEP(100 * cronMILLIS);
+  while (GNUNET_SHUTDOWN_TEST() == 0) {
+    ret = connection_test_running(ectx,
+                                 cfg);
+    if (ret == OK)
+      return OK;
     if (timeout < get_time())
-      return connection_test_running(ectx,
-                                    cfg);
+      return SYSERR;
+    min = timeout - get_time();
+    if (min > 100 * cronMILLIS)
+      min = 100 * cronMILLIS;
+    PTHREAD_SLEEP(min);
   }
-  return OK;
+  return SYSERR;
 }
 
 /* end of daemon.c */

Modified: GNUnet/src/util/network_client/tcpio.c
===================================================================
--- GNUnet/src/util/network_client/tcpio.c      2006-08-26 09:18:10 UTC (rev 
3322)
+++ GNUnet/src/util/network_client/tcpio.c      2006-08-27 03:00:13 UTC (rev 
3323)
@@ -316,7 +316,7 @@
                          &buf[pos],
                          size - pos,
                          &pos)) ||
-       (pos != sizeof(unsigned short) + size) ) {
+       (pos + sizeof(unsigned short) != size) ) {
     connection_close_temporarily(sock);
     FREE(buf);
     MUTEX_UNLOCK(sock->readlock);

Modified: GNUnet/src/util/os/Makefile.am
===================================================================
--- GNUnet/src/util/os/Makefile.am      2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/util/os/Makefile.am      2006-08-27 03:00:13 UTC (rev 3323)
@@ -2,6 +2,8 @@
 
 SUBDIRS = .
 
+EXTRA_DIST = check.conf
+
 noinst_LTLIBRARIES = \
   libos.la
 

Copied: GNUnet/src/util/os/check.conf (from rev 3322, 
GNUnet/src/util/check.conf)
===================================================================
--- GNUnet/src/util/check.conf  2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/util/os/check.conf       2006-08-27 03:00:13 UTC (rev 3323)
@@ -0,0 +1,30 @@
+# This is the configuration for the GNUnet daemon when running
+# the test in this directory (make check).
+
+[GNUNETD]
+GNUNETD_HOME     = /tmp/gnunet-util-os-test 
+HELLOEXPIRES     = 60
+LOGLEVEL        = ERROR 
+LOGFILE         = $GNUNETD_HOME/log
+KEEPLOG         = 0
+PIDFILE         = $GNUNETD_HOME/gnunetd.pid
+HOSTS          = $GNUNETD_HOME/data/hosts/
+APPLICATIONS = "getoption stats"
+
+[MODULES]
+topology = topology_default
+
+
+[NETWORK]
+PORT = 2087
+INTERFACE = eth0
+HELOEXCHANGE = NO
+TRUSTED = 127.0.0.0/8;
+
+[LOAD]
+INTERFACES          = eth0
+BASICLIMITING       = YES
+MAXNETUPBPSTOTAL    = 50000
+MAXNETDOWNBPSTOTAL  = 50000
+MAXCPULOAD         = 100
+

Modified: GNUnet/src/util/os/daemontest.c
===================================================================
--- GNUnet/src/util/os/daemontest.c     2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/util/os/daemontest.c     2006-08-27 03:00:13 UTC (rev 3323)
@@ -54,11 +54,13 @@
     GE_free_context(ectx);
     return 1;
   }
-  if (0 != connection_wait_for_running(ectx,
+  if (OK != connection_wait_for_running(ectx,
                                       cfg,
                                       30 * cronSECONDS)) {
     fprintf(stderr,
            "Failed to confirm daemon running (after 30s).\n");
+    /* try killing anyway, just to be sure */
+    os_daemon_stop(ectx, daemon);
     GC_free(cfg);
     GE_free_context(ectx);
     return 1;

Modified: GNUnet/src/util/threads/pthread.c
===================================================================
--- GNUnet/src/util/threads/pthread.c   2006-08-26 09:18:10 UTC (rev 3322)
+++ GNUnet/src/util/threads/pthread.c   2006-08-27 03:00:13 UTC (rev 3323)
@@ -184,10 +184,6 @@
  * sleep was long enough.
  */
 void PTHREAD_SLEEP(unsigned long long delay) {
-#ifndef MINGW
-  static struct sigaction sig;
-  static struct sigaction old;
-#endif
 #if LINUX || SOLARIS || SOMEBSD || OSX
   struct timespec req;
   struct timespec rem;
@@ -197,18 +193,6 @@
   struct timeval timeout;
 #endif
 
-  /* make sure SIGALRM does not kill us */
-#ifndef MINGW
-  memset(&sig, 0, sizeof(struct sigaction));
-  memset(&old, 0, sizeof(struct sigaction));
-  sig.sa_flags = SA_NODEFER;
-  sig.sa_handler =  &sigalrmHandler; 
-  if (0 != sigaction(SIGALRM, &sig, &old))
-    GE_LOG_STRERROR(NULL,
-                   GE_WARNING | GE_ADMIN | GE_BULK,
-                   "sigaction");                   
-#endif
-
   /* actual sleep */
 #if LINUX || SOLARIS || SOMEBSD || OSX
   req.tv_sec
@@ -225,7 +209,6 @@
 #elif WINDOWS
   SleepEx(delay, TRUE);
 #else
-  printf("Select!\n");
   /* fall back to select */
   timeout.tv_sec
     = delay / CRON_UNIT_TO_SECONDS;
@@ -240,13 +223,6 @@
                    "select");
 #endif
 
-  /* restore signal handler */
-#ifndef MINGW
-  if (0 != sigaction(SIGALRM, &old, &sig))
-    GE_LOG_STRERROR(NULL,
-                   GE_WARNING | GE_ADMIN | GE_BULK,
-                   "sigaction");                   
-#endif
 }
 
 void PTHREAD_STOP_SLEEP(PThread * handle) {
@@ -272,12 +248,7 @@
           STRERROR(ret));
     break;
   case ESRCH:
-    GE_LOG(NULL,
-          GE_ERROR | GE_USER | GE_DEVELOPER | GE_BULK,
-          _("`%s' failed with error code %s: %s\n"),
-          "pthread_kill",
-          "ESRCH",
-          STRERROR(ret));
+    /* ignore, thread might have already exited by chance */
     break;
   default:
     GE_LOG(NULL,
@@ -290,4 +261,36 @@
   }
 }
 
-/* end of semaphore.c */
+#ifndef MINGW
+static struct sigaction sig;
+static struct sigaction old;
+#endif
+
+
+/**
+ * Initialize the signal handlers, etc.
+ */
+void __attribute__ ((constructor)) pthread_handlers_ltdl_init() {
+  /* make sure SIGALRM does not kill us */
+#ifndef MINGW
+  memset(&sig, 0, sizeof(struct sigaction));
+  memset(&old, 0, sizeof(struct sigaction));
+  sig.sa_flags = SA_NODEFER;
+  sig.sa_handler =  &sigalrmHandler; 
+  if (0 != sigaction(SIGALRM, &sig, &old))
+    GE_LOG_STRERROR(NULL,
+                   GE_WARNING | GE_ADMIN | GE_BULK,
+                   "sigaction");                   
+#endif
+}
+
+void __attribute__ ((destructor)) pthread_handlers_ltdl_fini() {
+#ifndef MINGW
+  if (0 != sigaction(SIGALRM, &old, &sig))
+    GE_LOG_STRERROR(NULL,
+                   GE_WARNING | GE_ADMIN | GE_BULK,
+                   "sigaction");                   
+#endif
+}
+
+/* end of pthread.c */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]