gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r3393 - in GNUnet/src: applications/datastore applications/


From: grothoff
Subject: [GNUnet-SVN] r3393 - in GNUnet/src: applications/datastore applications/fs/lib applications/fs/module applications/identity applications/session applications/state applications/topology_default applications/topology_f2f include server transports util/disk util/network util/network_client util/os
Date: Sun, 10 Sep 2006 22:31:48 -0700 (PDT)

Author: grothoff
Date: 2006-09-10 22:31:34 -0700 (Sun, 10 Sep 2006)
New Revision: 3393

Modified:
   GNUnet/src/applications/datastore/datastore.c
   GNUnet/src/applications/datastore/prefetch.c
   GNUnet/src/applications/fs/lib/fslib.c
   GNUnet/src/applications/fs/lib/fslibtest.c
   GNUnet/src/applications/fs/module/querymanager.c
   GNUnet/src/applications/identity/hostkey.c
   GNUnet/src/applications/identity/identity.c
   GNUnet/src/applications/session/connect.c
   GNUnet/src/applications/state/state.c
   GNUnet/src/applications/topology_default/topology.c
   GNUnet/src/applications/topology_f2f/topology.c
   GNUnet/src/include/gnunet_util_disk.h
   GNUnet/src/include/gnunet_util_network.h
   GNUnet/src/server/tcpserver.c
   GNUnet/src/server/version.c
   GNUnet/src/transports/tcp.c
   GNUnet/src/transports/tcp6.c
   GNUnet/src/transports/udp.c
   GNUnet/src/transports/udp6.c
   GNUnet/src/util/disk/storage.c
   GNUnet/src/util/network/io.c
   GNUnet/src/util/network/select.c
   GNUnet/src/util/network_client/tcpio.c
   GNUnet/src/util/os/dso.c
Log:
fixing deadlock and other errors found with fslibtest

Modified: GNUnet/src/applications/datastore/datastore.c
===================================================================
--- GNUnet/src/applications/datastore/datastore.c       2006-09-11 04:36:51 UTC 
(rev 3392)
+++ GNUnet/src/applications/datastore/datastore.c       2006-09-11 05:31:34 UTC 
(rev 3393)
@@ -339,8 +339,10 @@
                                              0,
                                              ((unsigned long long)-1)/1024,
                                              1024,
-                                             &lquota))
+                                             &lquota)) {
+    GE_BREAK(capi->ectx, 0);
     return NULL; /* OOPS */  
+  }
 
   quota
     = lquota * 1024L * 1024L; /* MB to bytes */
@@ -369,7 +371,9 @@
               sq);
   if (OK != initFilters(capi->ectx,
                        capi->cfg)) {
+    GE_BREAK(capi->ectx, 0);
     donePrefetch();
+    capi->releaseService(sq);
     return NULL;
   }
   cronMaintenance(NULL);

Modified: GNUnet/src/applications/datastore/prefetch.c
===================================================================
--- GNUnet/src/applications/datastore/prefetch.c        2006-09-11 04:36:51 UTC 
(rev 3392)
+++ GNUnet/src/applications/datastore/prefetch.c        2006-09-11 05:31:34 UTC 
(rev 3393)
@@ -256,7 +256,7 @@
   SEMAPHORE_DESTROY(acquireMoreSignal);
   SEMAPHORE_DESTROY(doneSignal);
   PTHREAD_JOIN(gather_thread, &unused);
-  for (i=0;i<rCBPos;i++)
+  for (i=0;i<RCB_SIZE;i++)
     FREENONNULL(randomContentBuffer[i].value);
   MUTEX_DESTROY(lock);
   lock = NULL;

Modified: GNUnet/src/applications/fs/lib/fslib.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslib.c      2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/applications/fs/lib/fslib.c      2006-09-11 05:31:34 UTC (rev 
3393)
@@ -250,7 +250,7 @@
         type);
 #endif
   if (OK != connection_write(ctx->sock,
-                         &req->header)) {
+                            &req->header)) {
     FS_stop_search(ctx,
                   ret);
     return NULL;

Modified: GNUnet/src/applications/fs/lib/fslibtest.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslibtest.c  2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/applications/fs/lib/fslibtest.c  2006-09-11 05:31:34 UTC (rev 
3393)
@@ -38,6 +38,8 @@
 
 static cron_t now;
 
+static struct PTHREAD * mainThread;
+
 static Datastore_Value * makeBlock(int i) {
   Datastore_Value * block;
   DBlock * db;
@@ -113,6 +115,9 @@
                         void * cls) {
   int * cnt = cls;
   (*cnt)--;
+  fprintf(stderr, "*");
+  if (*cnt <= 0)
+    PTHREAD_STOP_SLEEP(mainThread);
   return OK;
 }
 
@@ -200,7 +205,7 @@
   return closure.found;
 }
 
-#define START_DAEMON 0
+#define START_DAEMON 1
 
 int main(int argc, char * argv[]){
 #if START_DAEMON
@@ -252,6 +257,7 @@
 
   /* ACTUAL TEST CODE */
   for (i=1;i<32;i++) {
+    fprintf(stderr, ".");
     block = makeBlock(i);
     fileBlockGetQuery((DBlock*) &block[1],
                      ntohl(block->size) - sizeof(Datastore_Value),
@@ -297,9 +303,12 @@
                           MAX_BUFFER_SIZE,
                           &hc));
     UNLINK(tmpName);
+    FREE(tmpName);
     FREE(block);
   }
+  fprintf(stderr, "\n");
   for (i=32;i<MAX_BUFFER_SIZE;i*=2) {
+    fprintf(stderr, ".");
     block = makeBlock(i);
     fileBlockGetQuery((DBlock*) &block[1],
                      ntohl(block->size) - sizeof(Datastore_Value),
@@ -327,6 +336,7 @@
                           &hc));
     FREE(block);
   }
+  fprintf(stderr, "\n");
 
   /* multiple search results test */
   makeRandomId(&hc);
@@ -339,6 +349,7 @@
                        block));
   FREE(block);
   i = 2;
+  mainThread = PTHREAD_GET_SELF();
   hnd = FS_start_search(ctx,
                        ANY_BLOCK,
                        1,
@@ -351,6 +362,7 @@
   CHECK(hnd != NULL);
   PTHREAD_SLEEP(10 * cronSECONDS);
   FS_stop_search(ctx, hnd);
+  PTHREAD_REL_SELF(mainThread);
   CHECK(i <= 0);
                
 
@@ -359,6 +371,7 @@
   /* END OF TEST CODE */
 
  FAILURE:
+  fprintf(stderr, "\n");
   if (ctx != NULL)
     FS_SEARCH_destroyContext(ctx);
   if (sock != NULL)
@@ -369,6 +382,7 @@
 #if START_DAEMON
   GE_ASSERT(NULL, OK == os_daemon_stop(NULL, daemon));
 #endif
+  GC_free(cfg);
   return (ok == YES) ? 0 : 1;
 }
 

Modified: GNUnet/src/applications/fs/module/querymanager.c
===================================================================
--- GNUnet/src/applications/fs/module/querymanager.c    2006-09-11 04:36:51 UTC 
(rev 3392)
+++ GNUnet/src/applications/fs/module/querymanager.c    2006-09-11 05:31:34 UTC 
(rev 3393)
@@ -148,9 +148,10 @@
   GE_ASSERT(ectx, ntohl(value->size) > sizeof(Datastore_Value));
   matchCount = 0;
 #if DEBUG_QUERYMANAGER
-  IF_GELOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
-       hash2enc(key,
-                &enc));
+  IF_GELOG(ectx,
+          GE_DEBUG | GE_REQUEST | GE_USER,
+          hash2enc(key,
+                   &enc));
 #endif
   MUTEX_LOCK(queryManagerLock);
   for (i=trackerCount-1;i>=0;i--) {
@@ -168,10 +169,11 @@
             &value[1],
             ntohl(value->size) - sizeof(Datastore_Value));
 #if DEBUG_QUERYMANAGER
-      GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
-         "Sending reply for `%s' to client waiting in slot %u.\n",
-         &enc,
-         i);
+      GE_LOG(ectx,
+            GE_DEBUG | GE_REQUEST | GE_USER,
+            "Sending reply for `%s' to client waiting in slot %u.\n",
+            &enc,
+            i);
 #endif
       coreAPI->sendToClient(trackers[i]->client,
                            &rc->header);

Modified: GNUnet/src/applications/identity/hostkey.c
===================================================================
--- GNUnet/src/applications/identity/hostkey.c  2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/applications/identity/hostkey.c  2006-09-11 05:31:34 UTC (rev 
3393)
@@ -115,15 +115,19 @@
   hostkeyfile = MALLOC(strlen(gnHome) + strlen(HOSTKEYFILE)+2);
   strcpy(hostkeyfile, gnHome);
   FREE(gnHome);
-  strcat(hostkeyfile, "/");
+  if (hostkeyfile[strlen(hostkeyfile)-1] != '/')
+    strcat(hostkeyfile, "/");
   strcat(hostkeyfile, HOSTKEYFILE);
   res = 0;
-  if (disk_file_test(ectx,
-                    hostkeyfile)) {
+  if (YES == disk_file_test(ectx,
+                           hostkeyfile)) {
     res = disk_file_read(ectx,
                         hostkeyfile,
                         sizeof(unsigned short),
                         &len);
+  } else {
+    printf("Could not read host key at `%s', generating fresh key.\n",
+          hostkeyfile);
   }
   encPrivateKey = NULL;
   if (res == sizeof(unsigned short)) {

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/applications/identity/identity.c 2006-09-11 05:31:34 UTC (rev 
3393)
@@ -600,8 +600,8 @@
  * @returns SYSERR on failure, OK on success
  */
 static P2P_hello_MESSAGE * identity2Helo(const PeerIdentity *  hostId,
-                                   unsigned short protocol,
-                                   int tryTemporaryList) {
+                                        unsigned short protocol,
+                                        int tryTemporaryList) {
   P2P_hello_MESSAGE * result;
   HostEntry * host;
   char * fn;
@@ -669,26 +669,27 @@
   /* do direct read */
   fn = getHostFileName(hostId,
                       protocol);
+  if (1 != disk_file_test(ectx,
+                         fn)) {
+    FREE(fn);
+    MUTEX_UNLOCK(lock_);
+    return NULL;
+  }
   size = disk_file_read(ectx,
                        fn,
                        sizeof(P2P_hello_MESSAGE),
                        &buffer);
   if (size != sizeof(P2P_hello_MESSAGE)) {
-    struct stat buf;
-
-    if (0 == STAT(fn,
-                 &buf)) {
-      if (0 == UNLINK(fn))
-       GE_LOG(ectx,
-              GE_WARNING | GE_USER | GE_BULK,
-              _("Removed file `%s' containing invalid hello data.\n"),
-              fn);
-      else
-       GE_LOG_STRERROR_FILE(ectx,
-                            GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
-                            "unlink",
-                            fn);
-    }
+    if (0 == UNLINK(fn))
+      GE_LOG(ectx,
+            GE_WARNING | GE_USER | GE_BULK,
+            _("Removed file `%s' containing invalid hello data.\n"),
+            fn);
+    else
+      GE_LOG_STRERROR_FILE(ectx,
+                          GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
+                          "unlink",
+                          fn);
     FREE(fn);
     MUTEX_UNLOCK(lock_);
     return NULL;
@@ -1052,8 +1053,8 @@
  * @brief Delete expired hosts
  */
 static int discardHostsHelper(const char *filename,
-          const char *dirname,
-          void *now) {
+                             const char *dirname,
+                             void *now) {
   char *fn;
   struct stat hostStat;
   int hostFile;

Modified: GNUnet/src/applications/session/connect.c
===================================================================
--- GNUnet/src/applications/session/connect.c   2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/applications/session/connect.c   2006-09-11 05:31:34 UTC (rev 
3393)
@@ -490,7 +490,7 @@
   EncName enc;
 
   hash2enc(&sender->hashPubKey,
-     &enc);
+          &enc);
   if ( (topology != NULL) &&
        (topology->allowConnectionFrom(sender) == SYSERR) ) {
     GE_LOG(ectx,

Modified: GNUnet/src/applications/state/state.c
===================================================================
--- GNUnet/src/applications/state/state.c       2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/applications/state/state.c       2006-09-11 05:31:34 UTC (rev 
3393)
@@ -242,21 +242,16 @@
   static State_ServiceAPI api;
 
   char * dbh;
-  char * dir;
   size_t n;
 
-  if (-1 == GC_get_configuration_value_string(capi->cfg,
-                                             "GNUNETD",
-                                             "GNUNETD_HOME",
-                                             VAR_DAEMON_DIRECTORY,
-                                             &dir))
+  dbh = NULL;
+  if (-1 == GC_get_configuration_value_filename(capi->cfg,
+                                               "GNUNETD",
+                                               "GNUNETD_HOME",
+                                               VAR_DAEMON_DIRECTORY,
+                                               &dbh))
     return NULL;
-  GE_ASSERT(capi->ectx, dir != NULL);
-  dbh = string_expandFileName(capi->ectx,
-                             dir);
-  FREE(dir);
-  if (dbh == NULL) 
-    return NULL;
+  GE_ASSERT(capi->ectx, dbh != NULL);
   n = strlen(dbh) + strlen(DIR_EXT) + 5;
   handle = MALLOC(n);
   SNPRINTF(handle, 

Modified: GNUnet/src/applications/topology_default/topology.c
===================================================================
--- GNUnet/src/applications/topology_default/topology.c 2006-09-11 04:36:51 UTC 
(rev 3392)
+++ GNUnet/src/applications/topology_default/topology.c 2006-09-11 05:31:34 UTC 
(rev 3393)
@@ -322,7 +322,12 @@
 }
 
 static int allowConnection(const PeerIdentity * peer) {
-  return OK; /* allow everything */
+  if ( (coreAPI->myIdentity != NULL) &&
+       (0 == memcmp(coreAPI->myIdentity,
+                   peer,
+                   sizeof(PeerIdentity))) )
+    return SYSERR; /* disallow connections to self */
+  return OK; /* allow everything else */
 }
 
 Topology_ServiceAPI *

Modified: GNUnet/src/applications/topology_f2f/topology.c
===================================================================
--- GNUnet/src/applications/topology_f2f/topology.c     2006-09-11 04:36:51 UTC 
(rev 3392)
+++ GNUnet/src/applications/topology_f2f/topology.c     2006-09-11 05:31:34 UTC 
(rev 3393)
@@ -101,6 +101,11 @@
 static int allowConnection(const PeerIdentity * peer) {
   int i;
 
+  if ( (coreAPI->myIdentity != NULL) &&
+       (0 == memcmp(coreAPI->myIdentity,
+                   peer,
+                   sizeof(PeerIdentity))) )
+    return SYSERR; /* disallow connections to self */
   for (i=friendCount-1;i>=0;i--)
     if (0 == memcmp(&friends[i], 
                    peer,

Modified: GNUnet/src/include/gnunet_util_disk.h
===================================================================
--- GNUnet/src/include/gnunet_util_disk.h       2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/include/gnunet_util_disk.h       2006-09-11 05:31:34 UTC (rev 
3393)
@@ -52,11 +52,11 @@
                               const char * part);
 
 /**
- * Assert that fil corresponds to a filename
+ * Check that fil corresponds to a filename
  * (of a file that exists and that is not a directory).
  * 
- * @return YES if exists, NO if not a file, SYSERR
- *   if file does not exist
+ * @returns YES if yes, NO if not a file, SYSERR if something 
+ * else (will print an error message in that case, too).
  */
 int disk_file_test(struct GE_Context * ectx,
                   const char * fil);

Modified: GNUnet/src/include/gnunet_util_network.h
===================================================================
--- GNUnet/src/include/gnunet_util_network.h    2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/include/gnunet_util_network.h    2006-09-11 05:31:34 UTC (rev 
3393)
@@ -305,6 +305,11 @@
              int osSocket);
 
 /**
+ * Close the socket (does NOT destroy it)
+ */
+void socket_close(struct SocketHandle * s);
+
+/**
  * Destroy the socket (also closes it).
  */
 void socket_destroy(struct SocketHandle * s);
@@ -393,6 +398,7 @@
  * from the given socket and pass messages read to the
  * given message handler.
  *
+ * @param desc for debugging (description)
  * @param sock the listen socket
  * @param max_addr_len maximum expected length of addresses for
  *        connections accepted on the given socket
@@ -403,7 +409,8 @@
  *        queueing messages (in bytes)
  * @return NULL on error
  */
-struct SelectHandle * select_create(struct GE_Context * ectx,
+struct SelectHandle * select_create(const char * desc,
+                                   struct GE_Context * ectx,
                                    struct LoadMonitor * mon,
                                    int sock,
                                    unsigned int max_addr_len,

Modified: GNUnet/src/server/tcpserver.c
===================================================================
--- GNUnet/src/server/tcpserver.c       2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/server/tcpserver.c       2006-09-11 05:31:34 UTC (rev 3393)
@@ -318,7 +318,8 @@
           listenerPort);
     return SYSERR;
   }
-  selector = select_create(ectx,
+  selector = select_create("tcpserver",
+                          ectx,
                           NULL,
                           listenerFD,
                           sizeof(struct sockaddr_in),

Modified: GNUnet/src/server/version.c
===================================================================
--- GNUnet/src/server/version.c 2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/server/version.c 2006-09-11 05:31:34 UTC (rev 3393)
@@ -111,22 +111,17 @@
 
 static char * getVersionFileName(struct GE_Context * ectx,
                                 struct GC_Configuration * cfg) {
-  char * cn;
   char * en;
+  char * cn;
   
-  cn = NULL;
-  if (-1 == GC_get_configuration_value_string(cfg,
-                                             "GNUNETD",
-                                             "GNUNETD_HOME",
-                                             VAR_DAEMON_DIRECTORY,
-                                             &cn))
+  en = NULL;
+  if (-1 == GC_get_configuration_value_filename(cfg,
+                                               "GNUNETD",
+                                               "GNUNETD_HOME",
+                                               VAR_DAEMON_DIRECTORY,
+                                               &en))
     return NULL;
-  GE_ASSERT(ectx, cn != NULL);
-  en = string_expandFileName(ectx,
-                            cn);
-  FREE(cn);
-  if (en == NULL)
-    return NULL;
+  GE_ASSERT(ectx, en != NULL);
   cn = MALLOC(strlen(en) + strlen(VERSIONFILE) + 1);
   strcpy(cn, en);
   strcat(cn, VERSIONDIR);

Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/transports/tcp.c 2006-09-11 05:31:34 UTC (rev 3393)
@@ -329,7 +329,8 @@
                      "close");
     return SYSERR;
   }
-  selector = select_create(ectx,
+  selector = select_create("tcp",
+                          ectx,
                           coreAPI->load_monitor,
                           s,
                           sizeof(IPaddr),

Modified: GNUnet/src/transports/tcp6.c
===================================================================
--- GNUnet/src/transports/tcp6.c        2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/transports/tcp6.c        2006-09-11 05:31:34 UTC (rev 3393)
@@ -338,7 +338,8 @@
                      "close");
     return SYSERR;
   }
-  selector = select_create(ectx,
+  selector = select_create("tcp6",
+                          ectx,
                           coreAPI->load_monitor,
                           s,
                           sizeof(IPaddr),

Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/transports/udp.c 2006-09-11 05:31:34 UTC (rev 3393)
@@ -338,7 +338,8 @@
     sock = listensock(port);
     if (sock == -1)
       return SYSERR;
-    selector = select_create(ectx,
+    selector = select_create("udp",
+                            ectx,
                             load_monitor,
                             sock,
                             sizeof(IPaddr),

Modified: GNUnet/src/transports/udp6.c
===================================================================
--- GNUnet/src/transports/udp6.c        2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/transports/udp6.c        2006-09-11 05:31:34 UTC (rev 3393)
@@ -336,7 +336,8 @@
     sock = passivesock(port);
     if (sock == -1)
       return SYSERR;
-    selector = select_create(ectx,
+    selector = select_create("udp6",
+                            ectx,
                             load_monitor,
                             sock,
                             sizeof(IPaddr),

Modified: GNUnet/src/util/disk/storage.c
===================================================================
--- GNUnet/src/util/disk/storage.c      2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/util/disk/storage.c      2006-09-11 05:31:34 UTC (rev 3393)
@@ -259,10 +259,10 @@
 }
 
 /**
- * Assert that fil corresponds to a filename
+ * Check that fil corresponds to a filename
  * (of a file that exists and that is not a directory).
- * @returns 1 if yes, 0 if not (will print an error
- * message in that case, too).
+ * @returns YES if yes, NO if not a file, SYSERR if something 
+ * else (will print an error message in that case, too).
  */
 int disk_file_test(struct GE_Context * ectx,
                   const char * fil) {
@@ -280,7 +280,7 @@
     }
     return NO;
   }
-  if (!S_ISREG(filestat.st_mode)) {
+  if (! S_ISREG(filestat.st_mode)) {
     GE_LOG(ectx,
           GE_WARNING | GE_USER | GE_ADMIN | GE_REQUEST, 
           _("Expected `%s' to be a regular file\n"),
@@ -313,6 +313,7 @@
                               dir);
   if (rdir == NULL)
     return SYSERR;
+
   len = strlen(rdir);
 #ifndef MINGW
   pos = 1; /* skip heading '/' */

Modified: GNUnet/src/util/network/io.c
===================================================================
--- GNUnet/src/util/network/io.c        2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/util/network/io.c        2006-09-11 05:31:34 UTC (rev 3393)
@@ -104,10 +104,10 @@
   return ret;
 }
 
-void socket_destroy(struct SocketHandle * s) {
+void socket_close(struct SocketHandle * s) {
   GE_ASSERT(NULL, s != NULL);
   if ( (0 != SHUTDOWN(s->handle,
-                   SHUT_RDWR)) &&
+                     SHUT_RDWR)) &&
        (errno != ENOTCONN) ) 
     GE_LOG_STRERROR(s->ectx,
                    GE_WARNING | GE_ADMIN | GE_BULK, 
@@ -116,6 +116,23 @@
     GE_LOG_STRERROR(s->ectx,
                    GE_WARNING | GE_USER | GE_DEVELOPER | GE_BULK,
                    "close");
+  s->handle = -1;
+}
+
+void socket_destroy(struct SocketHandle * s) {
+  GE_ASSERT(NULL, s != NULL);
+  if (s->handle != -1) {
+    if ( (0 != SHUTDOWN(s->handle,
+                       SHUT_RDWR)) &&
+        (errno != ENOTCONN) ) 
+      GE_LOG_STRERROR(s->ectx,
+                     GE_WARNING | GE_ADMIN | GE_BULK, 
+                     "shutdown");
+    if (0 != CLOSE(s->handle))
+      GE_LOG_STRERROR(s->ectx,
+                     GE_WARNING | GE_USER | GE_DEVELOPER | GE_BULK,
+                     "close");
+  }
   FREE(s);
 }
 

Modified: GNUnet/src/util/network/select.c
===================================================================
--- GNUnet/src/util/network/select.c    2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/util/network/select.c    2006-09-11 05:31:34 UTC (rev 3393)
@@ -30,7 +30,7 @@
 #include "platform.h"
 #include "network.h"
 
-#define DEBUG_SELECT YES
+#define DEBUG_SELECT NO
 
 /**
  * Select Session handle.
@@ -47,8 +47,20 @@
    */
   void * sock_ctx;
 
+  /**
+   * The read buffer.
+   */
+  char * rbuff;
+
+  /**
+   * The write buffer.
+   */
+  char * wbuff;
+
   cron_t lastUse;
 
+  int locked;
+
   /**
    * Current read position in the buffer.
    */
@@ -60,21 +72,11 @@
   unsigned int rsize;
 
   /**
-   * The read buffer.
-   */
-  char * rbuff;
-
-  /**
    * Position in the write buffer
    */
   unsigned int wpos;
 
   /**
-   * The write buffer.
-   */
-  char * wbuff;
-
-  /**
    * Size of the write buffer
    */
   unsigned int wsize;
@@ -83,6 +85,8 @@
 
 typedef struct SelectHandle {
 
+  const char * description;
+
   /**
    * mutex for synchronized access
    */
@@ -186,6 +190,10 @@
                           Session * s) { 
   int i;
 
+  if (s->locked == 1) {
+    s->locked = -1;
+    return;
+  }
 #if DEBUG_SELECT
   GE_LOG(sh->ectx,
         GE_DEBUG | GE_DEVELOPER | GE_BULK,
@@ -282,14 +290,25 @@
     if (session->pos < len) 
       break; /* wait for more */    
 
+    session->locked = 1;
+    MUTEX_UNLOCK(sh->lock);
     if (OK != sh->mh(sh->mh_cls,
                     sh,
                     session->sock,
                     session->sock_ctx,
                     pack)) {
+      MUTEX_LOCK(sh->lock);
+      session->locked = 0;
       destroySession(sh, session);
       return SYSERR;
     }
+    MUTEX_LOCK(sh->lock);
+    if (session->locked == -1) {
+      session->locked = 0;
+      destroySession(sh, session);
+      return OK;
+    }
+    session->locked = 0;
     /* shrink buffer adequately */
     memmove(&session->rbuff[0],
            &session->rbuff[len],
@@ -482,6 +501,10 @@
                 (struct sockaddr *) clientAddr,
                 &lenOfIncomingAddr);
       if (s == -1) {   
+       GE_LOG(sh->ectx,
+              GE_WARNING | GE_ADMIN | GE_BULK,
+              "Select %s failed to accept!\n",
+              sh->description); 
        GE_LOG_STRERROR(sh->ectx,
                        GE_WARNING | GE_ADMIN | GE_BULK,
                        "accept");
@@ -614,7 +637,8 @@
  *        queueing messages (in bytes)
  * @return NULL on error
  */
-SelectHandle * select_create(struct GE_Context * ectx,
+SelectHandle * select_create(const char * description,
+                            struct GE_Context * ectx,
                             struct LoadMonitor * mon,
                             int sock,
                             unsigned int max_addr_len,
@@ -636,6 +660,7 @@
     return NULL;
   }
   sh = MALLOC(sizeof(SelectHandle));
+  sh->description = description;
   memset(sh, 0, sizeof(SelectHandle));
   if (0 != PIPE(sh->signal_pipe)) {
     GE_LOG_STRERROR(ectx,

Modified: GNUnet/src/util/network_client/tcpio.c
===================================================================
--- GNUnet/src/util/network_client/tcpio.c      2006-09-11 04:36:51 UTC (rev 
3392)
+++ GNUnet/src/util/network_client/tcpio.c      2006-09-11 05:31:34 UTC (rev 
3393)
@@ -62,6 +62,8 @@
   
   struct MUTEX * writelock;
 
+  struct MUTEX * destroylock;
+
   struct GE_Context * ectx;
 
   struct GC_Configuration * cfg;
@@ -126,22 +128,31 @@
   result->sock = NULL;
   result->readlock = MUTEX_CREATE(NO);
   result->writelock = MUTEX_CREATE(NO);
+  result->destroylock = MUTEX_CREATE(NO);
   result->ectx = ectx;
   result->cfg = cfg;
   return result;
 }
 
 void connection_close_temporarily(struct ClientServerConnection * sock) {
+  MUTEX_LOCK(sock->destroylock);
   if (sock->sock != NULL) {
+    socket_close(sock->sock);
+    MUTEX_LOCK(sock->readlock);
+    MUTEX_LOCK(sock->writelock);
     socket_destroy(sock->sock);
     sock->sock = NULL;
+    MUTEX_UNLOCK(sock->writelock);
+    MUTEX_UNLOCK(sock->readlock);
   }
+  MUTEX_UNLOCK(sock->destroylock);
 }
 
 void connection_destroy(struct ClientServerConnection * sock) {
   connection_close_temporarily(sock);
   MUTEX_DESTROY(sock->readlock);
   MUTEX_DESTROY(sock->writelock);
+  MUTEX_DESTROY(sock->destroylock);
   FREE(sock);
 }
 
@@ -272,8 +283,8 @@
                    &sent);
   if ( (res != YES) ||
        (sent != size) ) {
+    MUTEX_UNLOCK(sock->writelock);
     connection_close_temporarily(sock);
-    MUTEX_UNLOCK(sock->writelock);
     return SYSERR;
   }
   MUTEX_UNLOCK(sock->writelock);
@@ -299,14 +310,14 @@
                          sizeof(unsigned short),
                          &pos)) ||
        (pos != sizeof(unsigned short)) ) {
+    MUTEX_UNLOCK(sock->readlock);
     connection_close_temporarily(sock);
-    MUTEX_UNLOCK(sock->readlock);
     return SYSERR;
   }
   size = ntohs(size);
   if (size < sizeof(MESSAGE_HEADER)) {
+    MUTEX_UNLOCK(sock->readlock);
     connection_close_temporarily(sock);
-    MUTEX_UNLOCK(sock->readlock);
     return SYSERR; /* invalid header */
   }
 
@@ -317,9 +328,9 @@
                          size - pos,
                          &pos)) ||
        (pos + sizeof(unsigned short) != size) ) {
-    connection_close_temporarily(sock);
     FREE(buf);
     MUTEX_UNLOCK(sock->readlock);
+    connection_close_temporarily(sock);
     return SYSERR;
   }
 #if DEBUG_TCPIO

Modified: GNUnet/src/util/os/dso.c
===================================================================
--- GNUnet/src/util/os/dso.c    2006-09-11 04:36:51 UTC (rev 3392)
+++ GNUnet/src/util/os/dso.c    2006-09-11 05:31:34 UTC (rev 3393)
@@ -104,7 +104,7 @@
 }
 
 void os_plugin_unload(struct PluginHandle * plugin) {
-  lt_dlclose(plugin->handle);
+  // lt_dlclose(plugin->handle);
   FREE(plugin->libprefix);
   FREE(plugin->dsoname);
   FREE(plugin);





reply via email to

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