- unique constraint
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed-logger.c
index 76403ecac4ff8d60cbc2ee7c56101cff37dbafd2..8129c7cbf6d5d092c5688210d15e08396358ad49 100644 (file)
@@ -4,7 +4,7 @@
 
   GNUnet is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
-  by the Free Software Foundation; either version 2, or (at your
+  by the Free Software Foundation; either version 3, or (at your
   option) any later version.
 
   GNUnet is distributed in the hope that it will be useful, but
@@ -145,7 +145,7 @@ queue_message (struct GNUNET_SERVER_Client *client,
 
   type = ntohs (msg->type);
   size = ntohs (msg->size);
-  mq_entry = GNUNET_malloc (sizeof (struct MessageQueue));
+  mq_entry = GNUNET_new (struct MessageQueue);
   mq_entry->msg = msg;
   mq_entry->client = client;
   GNUNET_SERVER_client_keep (client);
@@ -165,7 +165,7 @@ queue_message (struct GNUNET_SERVER_Client *client,
  *
  * @param cls NULL
  * @param client identification of the client
- * @param message the actual message
+ * @param msg the actual message
  */
 static void
 handle_log_msg (void *cls, struct GNUNET_SERVER_Client *client,
@@ -201,7 +201,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
     GNUNET_free (mq_entry);
   }
-  GNUNET_BIO_write_close (bio);
+  GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bio));
 }
 
 
@@ -222,21 +222,37 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
   };
   char *dir;
   char *fn;
+  char *hname;
+  size_t hname_len;
   pid_t pid;
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED-LOGGER", "DIR",
                                                &dir))
   {
-    LOG (GNUNET_ERROR_TYPE_ERROR, "Not logging directory definied.  Exiting\n");    
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Not logging directory definied.  Exiting\n");
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   pid = getpid ();
-  (void) GNUNET_asprintf (&fn, "%s/%jd.dat", dir, (intmax_t) pid);
+  hname_len = GNUNET_OS_get_hostname_max_length ();
+  hname = GNUNET_malloc (hname_len);
+  if (0 != gethostname (hname, hname_len))
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname.  Exiting\n");
+    GNUNET_free (hname);
+    GNUNET_free (dir);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  (void) GNUNET_asprintf (&fn, "%s/%.*s_%jd.dat", dir, hname_len, hname,
+                          (intmax_t) pid);
+  GNUNET_free (hname);
   GNUNET_free (dir);
   if (NULL == (bio = GNUNET_BIO_write_open (fn)))
   {
     GNUNET_free (fn);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   GNUNET_free (fn);
@@ -256,7 +272,7 @@ main (int argc, char *const *argv)
 {
   //sleep (15);                 /* Debugging */
   return (GNUNET_OK ==
-          GNUNET_SERVICE_run (argc, argv, "testbed-logger", 
+          GNUNET_SERVICE_run (argc, argv, "testbed-logger",
                               GNUNET_SERVICE_OPTION_NONE,
                               &logger_run, NULL)) ? 0 : 1;
 }