asserts
[oweals/gnunet.git] / src / util / service.c
index f64734b8faa7330fed8aa12cc86a448da4481f19..82e7070a10eca8b471bd9869d964eb0503e7fcda 100644 (file)
@@ -510,11 +510,6 @@ struct GNUNET_SERVICE_Context
    */
   int require_found;
 
-  /**
-   * Can clients ask us to initiate a shutdown?
-   */
-  int allow_shutdown;
-
   /**
    * Our options.
    */
@@ -570,35 +565,6 @@ handle_test (void *cls,
 }
 
 
-/**
- * Handler for SHUTDOWN message.
- *
- * @param cls closure (refers to service)
- * @param client identification of the client
- * @param message the actual message
- */
-static void
-handle_shutdown (void *cls,
-                 struct GNUNET_SERVER_Client *client,
-                 const struct GNUNET_MessageHeader *message)
-{
-  struct GNUNET_SERVICE_Context *service = cls;
-  if (!service->allow_shutdown)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _
-                  ("Received shutdown request, but configured to ignore!\n"));
-      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-      return;
-    }
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              _("Initiating shutdown as requested by client.\n"));
-  GNUNET_assert (service->sched != NULL);
-  GNUNET_SCHEDULER_shutdown (service->sched);
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
 /**
  * Default handlers for all services.  Will be copied and the
  * "callback_cls" fields will be replaced with the specific service
@@ -607,8 +573,6 @@ handle_shutdown (void *cls,
 static const struct GNUNET_SERVER_MessageHandler defhandlers[] = {
   {&handle_test, NULL, GNUNET_MESSAGE_TYPE_TEST,
    sizeof (struct GNUNET_MessageHeader)},
-  {&handle_shutdown, NULL, GNUNET_MESSAGE_TYPE_SHUTDOWN,
-   sizeof (struct GNUNET_MessageHeader)},
   {NULL, NULL, 0, 0}
 };
 
@@ -781,7 +745,6 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
 
   *addrs = NULL;
   *addr_lens = NULL;
-  resi = 0;
   if (GNUNET_CONFIGURATION_have_value (cfg,
                                        serviceName, "DISABLEV6"))
     {
@@ -959,7 +922,6 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
 #endif
           ((struct sockaddr_in *) saddrs[1])->sin_family = AF_INET;
           ((struct sockaddr_in *) saddrs[1])->sin_port = htons (port);
-
         }
     }
   *addrs = saddrs;
@@ -977,7 +939,6 @@ GNUNET_SERVICE_get_server_addresses (const char *serviceName,
  * - TIMEOUT (after how many ms does an inactive service timeout);
  * - MAXBUF (maximum incoming message size supported)
  * - DISABLEV6 (disable support for IPv6, otherwise we use dual-stack)
- * - ALLOW_SHUTDOWN (allow clients to shutdown this service)
  * - BINDTO (hostname or IP address to bind to, otherwise we take everything)
  * - ACCEPT_FROM  (only allow connections from specified IPv4 subnets)
  * - ACCEPT_FROM6 (only allow connections from specified IPv6 subnets)
@@ -1000,8 +961,13 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
           GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
                                                sctx->serviceName,
                                                "TIMEOUT", &idleout))
-        return GNUNET_SYSERR;
-
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Specified value for `%s' of service `%s' is invalid\n"),
+                     "TIMEOUT",
+                     sctx->serviceName);
+         return GNUNET_SYSERR;
+       }
       sctx->timeout = idleout;
     }
   else
@@ -1013,22 +979,16 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
           GNUNET_CONFIGURATION_get_value_number (sctx->cfg,
                                                  sctx->serviceName,
                                                  "MAXBUF", &maxbuf))
-        return GNUNET_SYSERR;
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Specified value for `%s' of service `%s' is invalid\n"),
+                     "MAXBUF",
+                     sctx->serviceName);
+         return GNUNET_SYSERR;
+       }
     }
   else
     maxbuf = GNUNET_SERVER_MAX_MESSAGE_SIZE;
-  if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
-                                       sctx->serviceName, "ALLOW_SHUTDOWN"))
-    {
-      if (GNUNET_SYSERR ==
-          (sctx->allow_shutdown =
-           GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->serviceName,
-                                                 "ALLOW_SHUTDOWN")))
-        return GNUNET_SYSERR;
-    }
-  else
-    sctx->allow_shutdown = GNUNET_NO;
-
 
   if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
                                        sctx->serviceName, "TOLERANT"))
@@ -1037,7 +997,13 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
           (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
                                                             sctx->serviceName,
                                                             "TOLERANT")))
-        return GNUNET_SYSERR;
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     _("Specified value for `%s' of service `%s' is invalid\n"),
+                     "TOLERANT",
+                     sctx->serviceName);
+         return GNUNET_SYSERR;
+       }
     }
   else
     tolerant = GNUNET_NO;
@@ -1418,17 +1384,17 @@ GNUNET_SERVICE_run (int argc,
   /* setup subsystems */
   if (GNUNET_SYSERR == GNUNET_GETOPT_run (serviceName, service_options, argc,
       argv))    
-    HANDLE_ERROR;
+    goto shutdown;
   if (GNUNET_OK != GNUNET_log_setup (serviceName, loglev, logfile))
     HANDLE_ERROR;
   if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_fn))
-    HANDLE_ERROR;
+    goto shutdown;
   if (GNUNET_OK != setup_service (&sctx))
-    HANDLE_ERROR;
+    goto shutdown;
   if ( (do_daemonize == 1) && (GNUNET_OK != detach_terminal (&sctx)))    
     HANDLE_ERROR;
   if (GNUNET_OK != set_user_id (&sctx))
-    HANDLE_ERROR;
+    goto shutdown;
 #if DEBUG_SERVICE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Service `%s' runs with configuration from `%s'\n",
@@ -1452,8 +1418,9 @@ shutdown:
 
   GNUNET_CONFIGURATION_destroy (cfg);
   i = 0;
-  while (sctx.addrs[i] != NULL)    
-    GNUNET_free (sctx.addrs[i++]);    
+  if (sctx.addrs != NULL)
+    while (sctx.addrs[i] != NULL)    
+      GNUNET_free (sctx.addrs[i++]);    
   GNUNET_free_non_null (sctx.addrs);
   GNUNET_free_non_null (sctx.addrlens);
   GNUNET_free_non_null (logfile);