aboutsummaryrefslogtreecommitdiff
path: root/src/util/service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/service.c')
-rw-r--r--src/util/service.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/util/service.c b/src/util/service.c
index 0a33809be..173c0f566 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1068,6 +1068,22 @@ write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid)
1068 1068
1069 1069
1070/** 1070/**
1071 * Task run during shutdown.
1072 *
1073 * @param cls unused
1074 * @param tc unused
1075 */
1076static void
1077shutdown_task (void *cls,
1078 const struct GNUNET_SCHEDULER_TaskContext *tc)
1079{
1080 struct GNUNET_SERVER_Handle *server = cls;
1081
1082 GNUNET_SERVER_destroy (server);
1083}
1084
1085
1086/**
1071 * Initial task for the service. 1087 * Initial task for the service.
1072 */ 1088 */
1073static void 1089static void
@@ -1092,6 +1108,10 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1092 sctx->ret = GNUNET_SYSERR; 1108 sctx->ret = GNUNET_SYSERR;
1093 return; 1109 return;
1094 } 1110 }
1111 GNUNET_SCHEDULER_add_delayed (tc->sched,
1112 GNUNET_TIME_UNIT_FOREVER_REL,
1113 &shutdown_task,
1114 sctx->server);
1095 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); 1115 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
1096 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); 1116 memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
1097 i = 0; 1117 i = 0;
@@ -1249,6 +1269,7 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
1249 GNUNET_free (pif); 1269 GNUNET_free (pif);
1250} 1270}
1251 1271
1272
1252/** 1273/**
1253 * Run a standard GNUnet service startup sequence (initialize loggers 1274 * Run a standard GNUnet service startup sequence (initialize loggers
1254 * and configuration, parse options). 1275 * and configuration, parse options).
@@ -1258,8 +1279,6 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx)
1258 * @param serviceName our service name 1279 * @param serviceName our service name
1259 * @param task main task of the service 1280 * @param task main task of the service
1260 * @param task_cls closure for task 1281 * @param task_cls closure for task
1261 * @param term termination task of the service
1262 * @param term_cls closure for term
1263 * @return GNUNET_SYSERR on error, GNUNET_OK 1282 * @return GNUNET_SYSERR on error, GNUNET_OK
1264 * if we shutdown nicely 1283 * if we shutdown nicely
1265 */ 1284 */
@@ -1268,7 +1287,7 @@ GNUNET_SERVICE_run (int argc,
1268 char *const *argv, 1287 char *const *argv,
1269 const char *serviceName, 1288 const char *serviceName,
1270 GNUNET_SERVICE_Main task, 1289 GNUNET_SERVICE_Main task,
1271 void *task_cls, GNUNET_SERVICE_Term term, void *term_cls) 1290 void *task_cls)
1272{ 1291{
1273 char *cfg_fn; 1292 char *cfg_fn;
1274 char *loglev; 1293 char *loglev;
@@ -1347,12 +1366,8 @@ GNUNET_SERVICE_run (int argc,
1347 } 1366 }
1348 1367
1349 /* shutdown */ 1368 /* shutdown */
1350 if (term != NULL)
1351 term (term_cls, sctx.cfg);
1352 if ((do_daemonize == 1) && (sctx.server != NULL)) 1369 if ((do_daemonize == 1) && (sctx.server != NULL))
1353 pid_file_delete (&sctx); 1370 pid_file_delete (&sctx);
1354 if (sctx.server != NULL)
1355 GNUNET_SERVER_destroy (sctx.server);
1356 GNUNET_free_non_null (sctx.my_handlers); 1371 GNUNET_free_non_null (sctx.my_handlers);
1357 GNUNET_CONFIGURATION_destroy (cfg); 1372 GNUNET_CONFIGURATION_destroy (cfg);
1358 GNUNET_free_non_null (sctx.addr); 1373 GNUNET_free_non_null (sctx.addr);
@@ -1413,8 +1428,6 @@ GNUNET_SERVICE_start (const char *serviceName,
1413 while ((sctx->my_handlers[i].callback != NULL)) 1428 while ((sctx->my_handlers[i].callback != NULL))
1414 sctx->my_handlers[i++].callback_cls = sctx; 1429 sctx->my_handlers[i++].callback_cls = sctx;
1415 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); 1430 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
1416
1417
1418 return sctx; 1431 return sctx;
1419} 1432}
1420 1433