diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/arm | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/arm')
-rw-r--r-- | src/arm/arm_api.c | 508 | ||||
-rw-r--r-- | src/arm/do_start_process.c | 79 | ||||
-rw-r--r-- | src/arm/gnunet-arm.c | 294 | ||||
-rw-r--r-- | src/arm/gnunet-service-arm.c | 744 | ||||
-rw-r--r-- | src/arm/gnunet-service-arm.h | 5 | ||||
-rw-r--r-- | src/arm/gnunet-service-arm_interceptor.c | 1055 | ||||
-rw-r--r-- | src/arm/mockup-service.c | 30 | ||||
-rw-r--r-- | src/arm/test_arm_api.c | 44 | ||||
-rw-r--r-- | src/arm/test_exponential_backoff.c | 292 | ||||
-rw-r--r-- | src/arm/test_gnunet_service_manager.c | 123 |
10 files changed, 1525 insertions, 1649 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 4114b8528..0db9e5c3e 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -106,61 +106,58 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
106 | struct ShutdownContext *shutdown_ctx = cls; | 106 | struct ShutdownContext *shutdown_ctx = cls; |
107 | 107 | ||
108 | if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES)) | 108 | if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES)) |
109 | { | 109 | { |
110 | #if DEBUG_ARM | 110 | #if DEBUG_ARM |
111 | /* Means the other side closed the connection and never confirmed a shutdown */ | 111 | /* Means the other side closed the connection and never confirmed a shutdown */ |
112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
113 | "Service handle shutdown before ACK!\n"); | 113 | "Service handle shutdown before ACK!\n"); |
114 | #endif | 114 | #endif |
115 | if (shutdown_ctx->cont != NULL) | 115 | if (shutdown_ctx->cont != NULL) |
116 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 116 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
117 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 117 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
118 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 118 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
119 | GNUNET_free(shutdown_ctx); | 119 | GNUNET_free (shutdown_ctx); |
120 | } | 120 | } |
121 | else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES)) | 121 | else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES)) |
122 | { | 122 | { |
123 | #if DEBUG_ARM | 123 | #if DEBUG_ARM |
124 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); |
125 | "Service shutdown complete.\n"); | ||
126 | #endif | 125 | #endif |
127 | if (shutdown_ctx->cont != NULL) | 126 | if (shutdown_ctx->cont != NULL) |
128 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO); | 127 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO); |
129 | 128 | ||
130 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 129 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
131 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 130 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
132 | GNUNET_free(shutdown_ctx); | 131 | GNUNET_free (shutdown_ctx); |
133 | } | 132 | } |
134 | else | 133 | else |
134 | { | ||
135 | GNUNET_assert (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader)); | ||
136 | switch (ntohs (msg->type)) | ||
135 | { | 137 | { |
136 | GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader)); | 138 | case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK: |
137 | switch (ntohs(msg->type)) | ||
138 | { | ||
139 | case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK: | ||
140 | #if DEBUG_ARM | 139 | #if DEBUG_ARM |
141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
142 | "Received confirmation for service shutdown.\n"); | 141 | "Received confirmation for service shutdown.\n"); |
143 | #endif | 142 | #endif |
144 | shutdown_ctx->confirmed = GNUNET_YES; | 143 | shutdown_ctx->confirmed = GNUNET_YES; |
145 | GNUNET_CLIENT_receive (shutdown_ctx->sock, | 144 | GNUNET_CLIENT_receive (shutdown_ctx->sock, |
146 | &service_shutdown_handler, | 145 | &service_shutdown_handler, |
147 | shutdown_ctx, | 146 | shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL); |
148 | GNUNET_TIME_UNIT_FOREVER_REL); | 147 | break; |
149 | break; | 148 | default: /* Fall through */ |
150 | default: /* Fall through */ | ||
151 | #if DEBUG_ARM | 149 | #if DEBUG_ARM |
152 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown refused!\n"); |
153 | "Service shutdown refused!\n"); | ||
154 | #endif | 151 | #endif |
155 | if (shutdown_ctx->cont != NULL) | 152 | if (shutdown_ctx->cont != NULL) |
156 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES); | 153 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES); |
157 | 154 | ||
158 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 155 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
159 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 156 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
160 | GNUNET_free(shutdown_ctx); | 157 | GNUNET_free (shutdown_ctx); |
161 | break; | 158 | break; |
162 | } | ||
163 | } | 159 | } |
160 | } | ||
164 | } | 161 | } |
165 | 162 | ||
166 | /** | 163 | /** |
@@ -169,16 +166,18 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
169 | * @param cls closure | 166 | * @param cls closure |
170 | * @param tc context information (why was this task triggered now) | 167 | * @param tc context information (why was this task triggered now) |
171 | */ | 168 | */ |
172 | void service_shutdown_cancel (void *cls, | 169 | void |
173 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 170 | service_shutdown_cancel (void *cls, |
171 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
174 | { | 172 | { |
175 | struct ShutdownContext *shutdown_ctx = cls; | 173 | struct ShutdownContext *shutdown_ctx = cls; |
174 | |||
176 | #if DEBUG_ARM | 175 | #if DEBUG_ARM |
177 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "service_shutdown_cancel called!\n"); | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "service_shutdown_cancel called!\n"); |
178 | #endif | 177 | #endif |
179 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 178 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
180 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 179 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
181 | GNUNET_free(shutdown_ctx); | 180 | GNUNET_free (shutdown_ctx); |
182 | } | 181 | } |
183 | 182 | ||
184 | 183 | ||
@@ -198,21 +197,22 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
198 | struct ShutdownContext *shutdown_ctx = cls; | 197 | struct ShutdownContext *shutdown_ctx = cls; |
199 | 198 | ||
200 | if (size < sizeof (struct GNUNET_MessageHeader)) | 199 | if (size < sizeof (struct GNUNET_MessageHeader)) |
201 | { | 200 | { |
202 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 201 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
203 | _("Failed to transmit shutdown request to client.\n")); | 202 | _("Failed to transmit shutdown request to client.\n")); |
204 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 203 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
205 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 204 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
206 | GNUNET_free(shutdown_ctx); | 205 | GNUNET_free (shutdown_ctx); |
207 | return 0; /* client disconnected */ | 206 | return 0; /* client disconnected */ |
208 | } | 207 | } |
209 | 208 | ||
210 | GNUNET_CLIENT_receive (shutdown_ctx->sock, | 209 | GNUNET_CLIENT_receive (shutdown_ctx->sock, |
211 | &service_shutdown_handler, shutdown_ctx, | 210 | &service_shutdown_handler, shutdown_ctx, |
212 | GNUNET_TIME_UNIT_FOREVER_REL); | 211 | GNUNET_TIME_UNIT_FOREVER_REL); |
213 | shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout), | 212 | shutdown_ctx->cancel_task = |
214 | &service_shutdown_cancel, | 213 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
215 | shutdown_ctx); | 214 | (shutdown_ctx->timeout), |
215 | &service_shutdown_cancel, shutdown_ctx); | ||
216 | msg = (struct GNUNET_MessageHeader *) buf; | 216 | msg = (struct GNUNET_MessageHeader *) buf; |
217 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); | 217 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); |
218 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 218 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
@@ -235,22 +235,22 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
235 | */ | 235 | */ |
236 | static void | 236 | static void |
237 | arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock, | 237 | arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock, |
238 | struct GNUNET_TIME_Relative timeout, | 238 | struct GNUNET_TIME_Relative timeout, |
239 | GNUNET_CLIENT_ShutdownTask cont, | 239 | GNUNET_CLIENT_ShutdownTask cont, void *cont_cls) |
240 | void *cont_cls) | ||
241 | { | 240 | { |
242 | struct ShutdownContext *shutdown_ctx; | 241 | struct ShutdownContext *shutdown_ctx; |
243 | shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); | 242 | |
243 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | ||
244 | shutdown_ctx->cont = cont; | 244 | shutdown_ctx->cont = cont; |
245 | shutdown_ctx->cont_cls = cont_cls; | 245 | shutdown_ctx->cont_cls = cont_cls; |
246 | shutdown_ctx->sock = sock; | 246 | shutdown_ctx->sock = sock; |
247 | shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout); | 247 | shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
248 | GNUNET_CLIENT_notify_transmit_ready (sock, | 248 | GNUNET_CLIENT_notify_transmit_ready (sock, |
249 | sizeof (struct | 249 | sizeof (struct |
250 | GNUNET_MessageHeader), | 250 | GNUNET_MessageHeader), |
251 | timeout, | 251 | timeout, |
252 | GNUNET_YES, | 252 | GNUNET_YES, |
253 | &write_shutdown, shutdown_ctx); | 253 | &write_shutdown, shutdown_ctx); |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
@@ -266,7 +266,7 @@ arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock, | |||
266 | */ | 266 | */ |
267 | struct GNUNET_ARM_Handle * | 267 | struct GNUNET_ARM_Handle * |
268 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 268 | GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
269 | const char *service) | 269 | const char *service) |
270 | { | 270 | { |
271 | struct GNUNET_ARM_Handle *ret; | 271 | struct GNUNET_ARM_Handle *ret; |
272 | 272 | ||
@@ -351,8 +351,7 @@ struct RequestContext | |||
351 | * @param tc why were we called (reason says if ARM is running) | 351 | * @param tc why were we called (reason says if ARM is running) |
352 | */ | 352 | */ |
353 | static void | 353 | static void |
354 | arm_service_report (void *cls, | 354 | arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
355 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
356 | { | 355 | { |
357 | struct RequestContext *pos = cls; | 356 | struct RequestContext *pos = cls; |
358 | struct GNUNET_OS_Process *proc; | 357 | struct GNUNET_OS_Process *proc; |
@@ -362,111 +361,91 @@ arm_service_report (void *cls, | |||
362 | char *lopostfix; | 361 | char *lopostfix; |
363 | 362 | ||
364 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 363 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
365 | { | 364 | { |
366 | #if DEBUG_ARM | 365 | #if DEBUG_ARM |
367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
368 | "Looks like `%s' is already running.\n", | 367 | "Looks like `%s' is already running.\n", "gnunet-service-arm"); |
369 | "gnunet-service-arm"); | ||
370 | #endif | 368 | #endif |
371 | /* arm is running! */ | 369 | /* arm is running! */ |
372 | if (pos->callback != NULL) | 370 | if (pos->callback != NULL) |
373 | pos->callback (pos->cls, GNUNET_YES); | 371 | pos->callback (pos->cls, GNUNET_YES); |
374 | GNUNET_free (pos); | 372 | GNUNET_free (pos); |
375 | return; | 373 | return; |
376 | } | 374 | } |
377 | #if DEBUG_ARM | 375 | #if DEBUG_ARM |
378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
379 | "Looks like `%s' is not running, will start it.\n", | 377 | "Looks like `%s' is not running, will start it.\n", |
380 | "gnunet-service-arm"); | 378 | "gnunet-service-arm"); |
381 | #endif | 379 | #endif |
382 | if (GNUNET_OK != | 380 | if (GNUNET_OK != |
383 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, | 381 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, |
384 | "arm", "PREFIX", &loprefix)) | 382 | "arm", "PREFIX", &loprefix)) |
385 | loprefix = GNUNET_strdup (""); | 383 | loprefix = GNUNET_strdup (""); |
386 | if (GNUNET_OK != | 384 | if (GNUNET_OK != |
387 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, | 385 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, |
388 | "arm", "OPTIONS", &lopostfix)) | 386 | "arm", "OPTIONS", &lopostfix)) |
389 | lopostfix = GNUNET_strdup (""); | 387 | lopostfix = GNUNET_strdup (""); |
390 | if (GNUNET_OK != | 388 | if (GNUNET_OK != |
391 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, | 389 | GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, |
392 | "arm", | 390 | "arm", "BINARY", &binary)) |
393 | "BINARY", | 391 | { |
394 | &binary)) | 392 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
395 | { | 393 | _ |
396 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 394 | ("Configuration failes to specify option `%s' in section `%s'!\n"), |
397 | _("Configuration failes to specify option `%s' in section `%s'!\n"), | 395 | "BINARY", "arm"); |
398 | "BINARY", | 396 | if (pos->callback != NULL) |
399 | "arm"); | 397 | pos->callback (pos->cls, GNUNET_SYSERR); |
400 | if (pos->callback != NULL) | 398 | GNUNET_free (pos); |
401 | pos->callback (pos->cls, GNUNET_SYSERR); | 399 | GNUNET_free (loprefix); |
402 | GNUNET_free (pos); | 400 | GNUNET_free (lopostfix); |
403 | GNUNET_free (loprefix); | 401 | return; |
404 | GNUNET_free (lopostfix); | 402 | } |
405 | return; | ||
406 | } | ||
407 | if (GNUNET_OK != | 403 | if (GNUNET_OK != |
408 | GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, | 404 | GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, |
409 | "arm", "CONFIG", &config)) | 405 | "arm", "CONFIG", &config)) |
410 | { | 406 | { |
411 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 407 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
412 | _("Configuration fails to specify option `%s' in section `%s'!\n"), | 408 | _ |
413 | "CONFIG", | 409 | ("Configuration fails to specify option `%s' in section `%s'!\n"), |
414 | "arm"); | 410 | "CONFIG", "arm"); |
415 | if (pos->callback != NULL) | 411 | if (pos->callback != NULL) |
416 | pos->callback (pos->cls, GNUNET_SYSERR); | 412 | pos->callback (pos->cls, GNUNET_SYSERR); |
417 | GNUNET_free (binary); | 413 | GNUNET_free (binary); |
418 | GNUNET_free (pos); | 414 | GNUNET_free (pos); |
419 | GNUNET_free (loprefix); | 415 | GNUNET_free (loprefix); |
420 | GNUNET_free (lopostfix); | 416 | GNUNET_free (lopostfix); |
421 | return; | 417 | return; |
422 | } | 418 | } |
423 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (pos->h->cfg, | 419 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pos->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_NO == GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "HOSTFILE")) /* Means we are ONLY running locally */ |
424 | "TESTING", | 420 | ) |
425 | "WEAKRANDOM")) && | 421 | { |
426 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pos->h->cfg, | 422 | /* we're clearly running a test, don't daemonize */ |
427 | "TESTING", | 423 | proc = do_start_process (NULL, loprefix, binary, "-c", config, |
428 | "WEAKRANDOM")) && | ||
429 | (GNUNET_NO == GNUNET_CONFIGURATION_have_value (pos->h->cfg, | ||
430 | "TESTING", | ||
431 | "HOSTFILE")) /* Means we are ONLY running locally */ | ||
432 | ) | ||
433 | { | ||
434 | /* we're clearly running a test, don't daemonize */ | ||
435 | proc = do_start_process (NULL, | ||
436 | loprefix, | ||
437 | binary, | ||
438 | "-c", config, | ||
439 | #if DEBUG_ARM | 424 | #if DEBUG_ARM |
440 | "-L", "DEBUG", | 425 | "-L", "DEBUG", |
441 | #endif | 426 | #endif |
442 | /* no daemonization! */ | 427 | /* no daemonization! */ |
443 | lopostfix, | 428 | lopostfix, NULL); |
444 | NULL); | 429 | } |
445 | } | ||
446 | else | 430 | else |
447 | { | 431 | { |
448 | proc = do_start_process (NULL, | 432 | proc = do_start_process (NULL, loprefix, binary, "-c", config, |
449 | loprefix, | ||
450 | binary, | ||
451 | "-c", config, | ||
452 | #if DEBUG_ARM | 433 | #if DEBUG_ARM |
453 | "-L", "DEBUG", | 434 | "-L", "DEBUG", |
454 | #endif | 435 | #endif |
455 | "-d", | 436 | "-d", lopostfix, NULL); |
456 | lopostfix, | 437 | } |
457 | NULL); | ||
458 | } | ||
459 | GNUNET_free (binary); | 438 | GNUNET_free (binary); |
460 | GNUNET_free (config); | 439 | GNUNET_free (config); |
461 | GNUNET_free (loprefix); | 440 | GNUNET_free (loprefix); |
462 | GNUNET_free (lopostfix); | 441 | GNUNET_free (lopostfix); |
463 | if (proc == NULL) | 442 | if (proc == NULL) |
464 | { | 443 | { |
465 | if (pos->callback != NULL) | 444 | if (pos->callback != NULL) |
466 | pos->callback (pos->cls, GNUNET_SYSERR); | 445 | pos->callback (pos->cls, GNUNET_SYSERR); |
467 | GNUNET_free (pos); | 446 | GNUNET_free (pos); |
468 | return; | 447 | return; |
469 | } | 448 | } |
470 | if (pos->callback != NULL) | 449 | if (pos->callback != NULL) |
471 | pos->callback (pos->cls, GNUNET_YES); | 450 | pos->callback (pos->cls, GNUNET_YES); |
472 | GNUNET_free (proc); | 451 | GNUNET_free (proc); |
@@ -488,44 +467,41 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
488 | int ret; | 467 | int ret; |
489 | 468 | ||
490 | if (msg == NULL) | 469 | if (msg == NULL) |
491 | { | 470 | { |
492 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
493 | _("Error receiving response to `%s' request from ARM for service `%s'\n"), | 472 | _ |
494 | (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) | 473 | ("Error receiving response to `%s' request from ARM for service `%s'\n"), |
495 | ? "START" | 474 | (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP", |
496 | : "STOP", | 475 | (const char *) &sc[1]); |
497 | (const char*) &sc[1]); | 476 | GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO); |
498 | GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO); | 477 | sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg); |
499 | sc->h->client = GNUNET_CLIENT_connect ("arm", | 478 | GNUNET_assert (NULL != sc->h->client); |
500 | sc->h->cfg); | 479 | GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES); |
501 | GNUNET_assert (NULL != sc->h->client); | 480 | if (sc->callback != NULL) |
502 | GNUNET_CLIENT_ignore_shutdown (sc->h->client, GNUNET_YES); | 481 | sc->callback (sc->cls, GNUNET_SYSERR); |
503 | if (sc->callback != NULL) | 482 | GNUNET_free (sc); |
504 | sc->callback (sc->cls, GNUNET_SYSERR); | 483 | return; |
505 | GNUNET_free (sc); | 484 | } |
506 | return; | ||
507 | } | ||
508 | #if DEBUG_ARM | 485 | #if DEBUG_ARM |
509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
510 | "Received response from ARM for service `%s': %u\n", | 487 | "Received response from ARM for service `%s': %u\n", |
511 | (const char*) &sc[1], | 488 | (const char *) &sc[1], ntohs (msg->type)); |
512 | ntohs(msg->type)); | ||
513 | #endif | 489 | #endif |
514 | switch (ntohs (msg->type)) | 490 | switch (ntohs (msg->type)) |
515 | { | 491 | { |
516 | case GNUNET_MESSAGE_TYPE_ARM_IS_UP: | 492 | case GNUNET_MESSAGE_TYPE_ARM_IS_UP: |
517 | ret = GNUNET_YES; | 493 | ret = GNUNET_YES; |
518 | break; | 494 | break; |
519 | case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN: | 495 | case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN: |
520 | ret = GNUNET_NO; | 496 | ret = GNUNET_NO; |
521 | break; | 497 | break; |
522 | case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN: | 498 | case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN: |
523 | ret = GNUNET_SYSERR; | 499 | ret = GNUNET_SYSERR; |
524 | break; | 500 | break; |
525 | default: | 501 | default: |
526 | GNUNET_break (0); | 502 | GNUNET_break (0); |
527 | ret = GNUNET_SYSERR; | 503 | ret = GNUNET_SYSERR; |
528 | } | 504 | } |
529 | if (sc->callback != NULL) | 505 | if (sc->callback != NULL) |
530 | sc->callback (sc->cls, ret); | 506 | sc->callback (sc->cls, ret); |
531 | GNUNET_free (sc); | 507 | GNUNET_free (sc); |
@@ -544,7 +520,7 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
544 | */ | 520 | */ |
545 | static void | 521 | static void |
546 | change_service (struct GNUNET_ARM_Handle *h, | 522 | change_service (struct GNUNET_ARM_Handle *h, |
547 | const char *service_name, | 523 | const char *service_name, |
548 | struct GNUNET_TIME_Relative timeout, | 524 | struct GNUNET_TIME_Relative timeout, |
549 | GNUNET_ARM_Callback cb, void *cb_cls, uint16_t type) | 525 | GNUNET_ARM_Callback cb, void *cb_cls, uint16_t type) |
550 | { | 526 | { |
@@ -553,19 +529,19 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
553 | struct GNUNET_MessageHeader *msg; | 529 | struct GNUNET_MessageHeader *msg; |
554 | 530 | ||
555 | slen = strlen (service_name) + 1; | 531 | slen = strlen (service_name) + 1; |
556 | if (slen + sizeof (struct GNUNET_MessageHeader) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 532 | if (slen + sizeof (struct GNUNET_MessageHeader) >= |
557 | { | 533 | GNUNET_SERVER_MAX_MESSAGE_SIZE) |
558 | GNUNET_break (0); | 534 | { |
559 | if (cb != NULL) | 535 | GNUNET_break (0); |
560 | cb (cb_cls, GNUNET_NO); | 536 | if (cb != NULL) |
561 | return; | 537 | cb (cb_cls, GNUNET_NO); |
562 | } | 538 | return; |
539 | } | ||
563 | #if DEBUG_ARM | 540 | #if DEBUG_ARM |
564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
565 | (type == GNUNET_MESSAGE_TYPE_ARM_START) | 542 | (type == GNUNET_MESSAGE_TYPE_ARM_START) |
566 | ? _("Requesting start of service `%s'.\n") | 543 | ? _("Requesting start of service `%s'.\n") |
567 | : _("Requesting termination of service `%s'.\n"), | 544 | : _("Requesting termination of service `%s'.\n"), service_name); |
568 | service_name); | ||
569 | #endif | 545 | #endif |
570 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); | 546 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); |
571 | sctx->h = h; | 547 | sctx->h = h; |
@@ -580,23 +556,26 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
580 | memcpy (&msg[1], service_name, slen); | 556 | memcpy (&msg[1], service_name, slen); |
581 | if (GNUNET_OK != | 557 | if (GNUNET_OK != |
582 | GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, | 558 | GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, |
583 | msg, | 559 | msg, |
584 | GNUNET_TIME_absolute_get_remaining (sctx->timeout), | 560 | GNUNET_TIME_absolute_get_remaining |
585 | GNUNET_YES, | 561 | (sctx->timeout), GNUNET_YES, |
586 | &handle_response, | 562 | &handle_response, sctx)) |
587 | sctx)) | 563 | { |
588 | { | 564 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
589 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 565 | (type == GNUNET_MESSAGE_TYPE_ARM_START) |
590 | (type == GNUNET_MESSAGE_TYPE_ARM_START) | 566 | ? |
591 | ? _("Error while trying to transmit request to start `%s' to ARM\n") | 567 | _ |
592 | : _("Error while trying to transmit request to stop `%s' to ARM\n"), | 568 | ("Error while trying to transmit request to start `%s' to ARM\n") |
593 | (const char*) &service_name); | 569 | : |
594 | if (cb != NULL) | 570 | _ |
595 | cb (cb_cls, GNUNET_SYSERR); | 571 | ("Error while trying to transmit request to stop `%s' to ARM\n"), |
596 | GNUNET_free (sctx); | 572 | (const char *) &service_name); |
597 | GNUNET_free (msg); | 573 | if (cb != NULL) |
598 | return; | 574 | cb (cb_cls, GNUNET_SYSERR); |
599 | } | 575 | GNUNET_free (sctx); |
576 | GNUNET_free (msg); | ||
577 | return; | ||
578 | } | ||
600 | GNUNET_free (msg); | 579 | GNUNET_free (msg); |
601 | } | 580 | } |
602 | 581 | ||
@@ -612,7 +591,7 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
612 | */ | 591 | */ |
613 | void | 592 | void |
614 | GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, | 593 | GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, |
615 | const char *service_name, | 594 | const char *service_name, |
616 | struct GNUNET_TIME_Relative timeout, | 595 | struct GNUNET_TIME_Relative timeout, |
617 | GNUNET_ARM_Callback cb, void *cb_cls) | 596 | GNUNET_ARM_Callback cb, void *cb_cls) |
618 | { | 597 | { |
@@ -623,39 +602,42 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, | |||
623 | #if DEBUG_ARM | 602 | #if DEBUG_ARM |
624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 603 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
625 | _("Asked to start service `%s' within %llu ms\n"), service_name, | 604 | _("Asked to start service `%s' within %llu ms\n"), service_name, |
626 | (unsigned long long) timeout.rel_value); | 605 | (unsigned long long) timeout.rel_value); |
627 | #endif | 606 | #endif |
628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 607 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
629 | _("Asked to start service `%s' within %llu ms\n"), service_name, | 608 | _("Asked to start service `%s' within %llu ms\n"), service_name, |
630 | (unsigned long long) timeout.rel_value); | 609 | (unsigned long long) timeout.rel_value); |
631 | if (0 == strcasecmp ("arm", service_name)) | 610 | if (0 == strcasecmp ("arm", service_name)) |
632 | { | 611 | { |
633 | slen = strlen ("arm") + 1; | 612 | slen = strlen ("arm") + 1; |
634 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); | 613 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); |
635 | sctx->h = h; | 614 | sctx->h = h; |
636 | sctx->callback = cb; | 615 | sctx->callback = cb; |
637 | sctx->cls = cb_cls; | 616 | sctx->cls = cb_cls; |
638 | sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 617 | sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
639 | memcpy (&sctx[1], service_name, slen); | 618 | memcpy (&sctx[1], service_name, slen); |
640 | GNUNET_CLIENT_service_test ("arm", | 619 | GNUNET_CLIENT_service_test ("arm", |
641 | h->cfg, timeout, &arm_service_report, sctx); | 620 | h->cfg, timeout, &arm_service_report, sctx); |
642 | return; | 621 | return; |
643 | } | 622 | } |
644 | if (h->client == NULL) | 623 | if (h->client == NULL) |
624 | { | ||
625 | client = GNUNET_CLIENT_connect ("arm", h->cfg); | ||
626 | if (client == NULL) | ||
645 | { | 627 | { |
646 | client = GNUNET_CLIENT_connect ("arm", h->cfg); | 628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
647 | if (client == NULL) | 629 | "arm_api, GNUNET_CLIENT_connect returned NULL\n"); |
648 | { | 630 | cb (cb_cls, GNUNET_SYSERR); |
649 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, GNUNET_CLIENT_connect returned NULL\n"); | 631 | return; |
650 | cb (cb_cls, GNUNET_SYSERR); | ||
651 | return; | ||
652 | } | ||
653 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); | ||
654 | GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES); | ||
655 | h->client = client; | ||
656 | } | 632 | } |
657 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n"); | 633 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
658 | change_service (h, service_name, timeout, cb, cb_cls, GNUNET_MESSAGE_TYPE_ARM_START); | 634 | "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); |
635 | GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES); | ||
636 | h->client = client; | ||
637 | } | ||
638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n"); | ||
639 | change_service (h, service_name, timeout, cb, cb_cls, | ||
640 | GNUNET_MESSAGE_TYPE_ARM_START); | ||
659 | } | 641 | } |
660 | 642 | ||
661 | /** | 643 | /** |
@@ -666,15 +648,15 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, | |||
666 | * @param reason reason for callback, GNUNET_NO if arm is shutdown | 648 | * @param reason reason for callback, GNUNET_NO if arm is shutdown |
667 | * GNUNET_YES if arm remains running, and GNUNET_SYSERR on error | 649 | * GNUNET_YES if arm remains running, and GNUNET_SYSERR on error |
668 | */ | 650 | */ |
669 | void arm_shutdown_callback (void *cls, | 651 | void |
670 | int reason) | 652 | arm_shutdown_callback (void *cls, int reason) |
671 | { | 653 | { |
672 | struct ARM_ShutdownContext *arm_shutdown_ctx = cls; | 654 | struct ARM_ShutdownContext *arm_shutdown_ctx = cls; |
673 | 655 | ||
674 | if (arm_shutdown_ctx->cb != NULL) | 656 | if (arm_shutdown_ctx->cb != NULL) |
675 | arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason); | 657 | arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason); |
676 | 658 | ||
677 | GNUNET_free(arm_shutdown_ctx); | 659 | GNUNET_free (arm_shutdown_ctx); |
678 | } | 660 | } |
679 | 661 | ||
680 | 662 | ||
@@ -698,28 +680,30 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, | |||
698 | 680 | ||
699 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 681 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
700 | _("Stopping service `%s' within %llu ms\n"), service_name, | 682 | _("Stopping service `%s' within %llu ms\n"), service_name, |
701 | (unsigned long long) timeout.rel_value); | 683 | (unsigned long long) timeout.rel_value); |
702 | if (h->client == NULL) | 684 | if (h->client == NULL) |
685 | { | ||
686 | client = GNUNET_CLIENT_connect ("arm", h->cfg); | ||
687 | if (client == NULL) | ||
703 | { | 688 | { |
704 | client = GNUNET_CLIENT_connect ("arm", h->cfg); | 689 | cb (cb_cls, GNUNET_SYSERR); |
705 | if (client == NULL) | ||
706 | { | ||
707 | cb (cb_cls, GNUNET_SYSERR); | ||
708 | return; | ||
709 | } | ||
710 | GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES); | ||
711 | h->client = client; | ||
712 | } | ||
713 | if (0 == strcasecmp ("arm", service_name)) | ||
714 | { | ||
715 | arm_shutdown_ctx = GNUNET_malloc(sizeof(struct ARM_ShutdownContext)); | ||
716 | arm_shutdown_ctx->cb = cb; | ||
717 | arm_shutdown_ctx->cb_cls = cb_cls; | ||
718 | arm_service_shutdown (h->client, timeout, &arm_shutdown_callback, arm_shutdown_ctx); | ||
719 | h->client = NULL; | ||
720 | return; | 690 | return; |
721 | } | 691 | } |
722 | change_service (h, service_name, timeout, cb, cb_cls, GNUNET_MESSAGE_TYPE_ARM_STOP); | 692 | GNUNET_CLIENT_ignore_shutdown (client, GNUNET_YES); |
693 | h->client = client; | ||
694 | } | ||
695 | if (0 == strcasecmp ("arm", service_name)) | ||
696 | { | ||
697 | arm_shutdown_ctx = GNUNET_malloc (sizeof (struct ARM_ShutdownContext)); | ||
698 | arm_shutdown_ctx->cb = cb; | ||
699 | arm_shutdown_ctx->cb_cls = cb_cls; | ||
700 | arm_service_shutdown (h->client, timeout, &arm_shutdown_callback, | ||
701 | arm_shutdown_ctx); | ||
702 | h->client = NULL; | ||
703 | return; | ||
704 | } | ||
705 | change_service (h, service_name, timeout, cb, cb_cls, | ||
706 | GNUNET_MESSAGE_TYPE_ARM_STOP); | ||
723 | } | 707 | } |
724 | 708 | ||
725 | 709 | ||
diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c index a2aca9dea..19b3bc224 100644 --- a/src/arm/do_start_process.c +++ b/src/arm/do_start_process.c | |||
@@ -13,8 +13,7 @@ | |||
13 | * @return PID of the started process, -1 on error | 13 | * @return PID of the started process, -1 on error |
14 | */ | 14 | */ |
15 | static struct GNUNET_OS_Process * | 15 | static struct GNUNET_OS_Process * |
16 | do_start_process (const int *lsocks, | 16 | do_start_process (const int *lsocks, const char *first_arg, ...) |
17 | const char *first_arg, ...) | ||
18 | { | 17 | { |
19 | va_list ap; | 18 | va_list ap; |
20 | char **argv; | 19 | char **argv; |
@@ -34,24 +33,24 @@ do_start_process (const int *lsocks, | |||
34 | do | 33 | do |
35 | { | 34 | { |
36 | /* *INDENT-ON* */ | 35 | /* *INDENT-ON* */ |
37 | rpos = arg; | 36 | rpos = arg; |
38 | while ('\0' != *rpos) | 37 | while ('\0' != *rpos) |
39 | { | 38 | { |
40 | if (' ' == *rpos) | 39 | if (' ' == *rpos) |
41 | { | 40 | { |
42 | if (last != NULL) | ||
43 | argv_size++; | ||
44 | last = NULL; | ||
45 | while (' ' == *rpos) | ||
46 | rpos++; | ||
47 | } | ||
48 | if ( (last == NULL) && (*rpos != '\0') ) | ||
49 | last = rpos; | ||
50 | if (*rpos != '\0') | ||
51 | rpos++; | ||
52 | } | ||
53 | if (last != NULL) | 41 | if (last != NULL) |
54 | argv_size++; | 42 | argv_size++; |
43 | last = NULL; | ||
44 | while (' ' == *rpos) | ||
45 | rpos++; | ||
46 | } | ||
47 | if ((last == NULL) && (*rpos != '\0')) | ||
48 | last = rpos; | ||
49 | if (*rpos != '\0') | ||
50 | rpos++; | ||
51 | } | ||
52 | if (last != NULL) | ||
53 | argv_size++; | ||
55 | /* *INDENT-OFF* */ | 54 | /* *INDENT-OFF* */ |
56 | } | 55 | } |
57 | while (NULL != (arg = (va_arg (ap, const char*)))); | 56 | while (NULL != (arg = (va_arg (ap, const char*)))); |
@@ -67,29 +66,29 @@ do_start_process (const int *lsocks, | |||
67 | do | 66 | do |
68 | { | 67 | { |
69 | /* *INDENT-ON* */ | 68 | /* *INDENT-ON* */ |
70 | cp = GNUNET_strdup (arg); | 69 | cp = GNUNET_strdup (arg); |
71 | pos = cp; | 70 | pos = cp; |
72 | while ('\0' != *pos) | 71 | while ('\0' != *pos) |
73 | { | 72 | { |
74 | if (' ' == *pos) | 73 | if (' ' == *pos) |
75 | { | 74 | { |
76 | *pos = '\0'; | 75 | *pos = '\0'; |
77 | if (last != NULL) | ||
78 | argv[argv_size++] = GNUNET_strdup (last); | ||
79 | last = NULL; | ||
80 | pos++; | ||
81 | while (' ' == *pos) | ||
82 | pos++; | ||
83 | } | ||
84 | if ( (last == NULL) && (*pos != '\0') ) | ||
85 | last = pos; | ||
86 | if (*pos != '\0') | ||
87 | pos++; | ||
88 | } | ||
89 | if (last != NULL) | 76 | if (last != NULL) |
90 | argv[argv_size++] = GNUNET_strdup (last); | 77 | argv[argv_size++] = GNUNET_strdup (last); |
91 | last = NULL; | 78 | last = NULL; |
92 | GNUNET_free (cp); | 79 | pos++; |
80 | while (' ' == *pos) | ||
81 | pos++; | ||
82 | } | ||
83 | if ((last == NULL) && (*pos != '\0')) | ||
84 | last = pos; | ||
85 | if (*pos != '\0') | ||
86 | pos++; | ||
87 | } | ||
88 | if (last != NULL) | ||
89 | argv[argv_size++] = GNUNET_strdup (last); | ||
90 | last = NULL; | ||
91 | GNUNET_free (cp); | ||
93 | /* *INDENT-OFF* */ | 92 | /* *INDENT-OFF* */ |
94 | } | 93 | } |
95 | while (NULL != (arg = (va_arg (ap, const char*)))); | 94 | while (NULL != (arg = (va_arg (ap, const char*)))); |
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index ccad0f21f..f7ff536be 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -138,9 +138,7 @@ static struct GNUNET_TIME_Relative timeout; | |||
138 | * @param cls closure, unused | 138 | * @param cls closure, unused |
139 | * @param tc context, unused | 139 | * @param tc context, unused |
140 | */ | 140 | */ |
141 | static void | 141 | static void cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
142 | cps_loop (void *cls, | ||
143 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
144 | 142 | ||
145 | 143 | ||
146 | /** | 144 | /** |
@@ -154,39 +152,39 @@ static void | |||
154 | confirm_cb (void *cls, int success) | 152 | confirm_cb (void *cls, int success) |
155 | { | 153 | { |
156 | const char *service = cls; | 154 | const char *service = cls; |
155 | |||
157 | switch (success) | 156 | switch (success) |
157 | { | ||
158 | case GNUNET_OK: | ||
159 | if (quiet != GNUNET_YES) | ||
160 | fprintf (stdout, _("Service `%s' has been started.\n"), service); | ||
161 | if ((phase - 1 != 2) && (phase - 1 != 3)) | ||
158 | { | 162 | { |
159 | case GNUNET_OK: | ||
160 | if (quiet != GNUNET_YES) | ||
161 | fprintf(stdout, _("Service `%s' has been started.\n"), service); | ||
162 | if ((phase - 1 != 2) && (phase - 1 != 3)) | ||
163 | { | ||
164 | if (quiet != GNUNET_YES) | ||
165 | fprintf(stdout, _("Failed to stop service `%s'!\n"), service); | ||
166 | ret = 1; | ||
167 | } | ||
168 | break; | ||
169 | case GNUNET_NO: | ||
170 | if (quiet != GNUNET_YES) | 163 | if (quiet != GNUNET_YES) |
171 | fprintf(stdout, _("Service `%s' has been stopped.\n"), service); | 164 | fprintf (stdout, _("Failed to stop service `%s'!\n"), service); |
172 | if ((phase - 1 != 0) && (phase - 1 != 1)) | 165 | ret = 1; |
173 | { | 166 | } |
174 | if (quiet != GNUNET_YES) | 167 | break; |
175 | fprintf(stdout, _("Failed to start service `%s'!\n"), service); | 168 | case GNUNET_NO: |
176 | ret = 1; | 169 | if (quiet != GNUNET_YES) |
177 | } | 170 | fprintf (stdout, _("Service `%s' has been stopped.\n"), service); |
178 | break; | 171 | if ((phase - 1 != 0) && (phase - 1 != 1)) |
179 | case GNUNET_SYSERR: | 172 | { |
180 | if (quiet != GNUNET_YES) | 173 | if (quiet != GNUNET_YES) |
181 | fprintf(stdout, | 174 | fprintf (stdout, _("Failed to start service `%s'!\n"), service); |
182 | _("Some error communicating with service `%s'.\n"), service); | ||
183 | ret = 1; | 175 | ret = 1; |
184 | break; | ||
185 | } | 176 | } |
177 | break; | ||
178 | case GNUNET_SYSERR: | ||
179 | if (quiet != GNUNET_YES) | ||
180 | fprintf (stdout, | ||
181 | _("Some error communicating with service `%s'.\n"), service); | ||
182 | ret = 1; | ||
183 | break; | ||
184 | } | ||
186 | 185 | ||
187 | GNUNET_SCHEDULER_add_continuation (&cps_loop, | 186 | GNUNET_SCHEDULER_add_continuation (&cps_loop, |
188 | NULL, | 187 | NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
189 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
190 | } | 188 | } |
191 | 189 | ||
192 | 190 | ||
@@ -203,18 +201,17 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
203 | const char *service = cls; | 201 | const char *service = cls; |
204 | 202 | ||
205 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 203 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
206 | { | 204 | { |
207 | if (quiet != GNUNET_YES) | 205 | if (quiet != GNUNET_YES) |
208 | fprintf(stdout, _("Service `%s' is running.\n"), service); | 206 | fprintf (stdout, _("Service `%s' is running.\n"), service); |
209 | } | 207 | } |
210 | else | 208 | else |
211 | { | 209 | { |
212 | if (quiet != GNUNET_YES) | 210 | if (quiet != GNUNET_YES) |
213 | fprintf(stdout, _("Service `%s' is not running.\n"), service); | 211 | fprintf (stdout, _("Service `%s' is not running.\n"), service); |
214 | } | 212 | } |
215 | GNUNET_SCHEDULER_add_continuation (&cps_loop, | 213 | GNUNET_SCHEDULER_add_continuation (&cps_loop, |
216 | NULL, | 214 | NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
217 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
218 | } | 215 | } |
219 | 216 | ||
220 | 217 | ||
@@ -229,30 +226,29 @@ confirm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
229 | static void | 226 | static void |
230 | run (void *cls, | 227 | run (void *cls, |
231 | char *const *args, | 228 | char *const *args, |
232 | const char *cfgfile, | 229 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
233 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
234 | { | 230 | { |
235 | cfg = c; | 231 | cfg = c; |
236 | config_file = cfgfile; | 232 | config_file = cfgfile; |
237 | if (GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "SERVICEHOME", &dir) != GNUNET_OK) | 233 | if (GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &dir) |
238 | { | 234 | != GNUNET_OK) |
239 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 235 | { |
240 | _("Fatal configuration error: `%s' option in section `%s' missing.\n"), | 236 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
241 | "SERVICEHOME", | 237 | _ |
242 | "PATHS"); | 238 | ("Fatal configuration error: `%s' option in section `%s' missing.\n"), |
243 | return; | 239 | "SERVICEHOME", "PATHS"); |
244 | } | 240 | return; |
241 | } | ||
245 | h = GNUNET_ARM_connect (cfg, NULL); | 242 | h = GNUNET_ARM_connect (cfg, NULL); |
246 | if (h == NULL) | 243 | if (h == NULL) |
247 | { | 244 | { |
248 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
249 | _("Fatal error initializing ARM API.\n")); | 246 | _("Fatal error initializing ARM API.\n")); |
250 | ret = 1; | 247 | ret = 1; |
251 | return; | 248 | return; |
252 | } | 249 | } |
253 | GNUNET_SCHEDULER_add_continuation (&cps_loop, | 250 | GNUNET_SCHEDULER_add_continuation (&cps_loop, |
254 | NULL, | 251 | NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); |
255 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
256 | } | 252 | } |
257 | 253 | ||
258 | /** | 254 | /** |
@@ -260,20 +256,23 @@ run (void *cls, | |||
260 | * on arm shutdown provided the end and delete options | 256 | * on arm shutdown provided the end and delete options |
261 | * were specified when gnunet-arm was run. | 257 | * were specified when gnunet-arm was run. |
262 | */ | 258 | */ |
263 | static void delete_files() | 259 | static void |
260 | delete_files () | ||
264 | { | 261 | { |
265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will attempt to remove configuration file %s and service directory %s\n", config_file, dir); | 262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
263 | "Will attempt to remove configuration file %s and service directory %s\n", | ||
264 | config_file, dir); | ||
266 | 265 | ||
267 | if (UNLINK(config_file) != 0) | 266 | if (UNLINK (config_file) != 0) |
268 | { | 267 | { |
269 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 268 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
270 | _("Failed to remove configuration file %s\n"), config_file); | 269 | _("Failed to remove configuration file %s\n"), config_file); |
271 | } | 270 | } |
272 | 271 | ||
273 | if (GNUNET_DISK_directory_remove(dir) != GNUNET_OK) | 272 | if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK) |
274 | { | 273 | { |
275 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 274 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
276 | _("Failed to remove servicehome directory %s\n"), dir); | 275 | _("Failed to remove servicehome directory %s\n"), dir); |
277 | 276 | ||
278 | } | 277 | } |
279 | } | 278 | } |
@@ -286,75 +285,89 @@ static void delete_files() | |||
286 | * @param tc context, unused | 285 | * @param tc context, unused |
287 | */ | 286 | */ |
288 | static void | 287 | static void |
289 | cps_loop (void *cls, | 288 | cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
290 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
291 | { | 289 | { |
292 | while (1) | 290 | while (1) |
291 | { | ||
292 | switch (phase++) | ||
293 | { | 293 | { |
294 | switch (phase++) | 294 | case 0: |
295 | { | 295 | if (term != NULL) |
296 | case 0: | 296 | { |
297 | if (term != NULL) | 297 | GNUNET_ARM_stop_service (h, term, |
298 | { | 298 | (0 == |
299 | GNUNET_ARM_stop_service (h, term, (0 == timeout.rel_value) ? STOP_TIMEOUT : timeout, &confirm_cb, term); | 299 | timeout.rel_value) ? STOP_TIMEOUT : timeout, |
300 | return; | 300 | &confirm_cb, term); |
301 | } | 301 | return; |
302 | break; | 302 | } |
303 | case 1: | 303 | break; |
304 | if ((end) || (restart)) | 304 | case 1: |
305 | { | 305 | if ((end) || (restart)) |
306 | GNUNET_ARM_stop_service (h, "arm", (0 == timeout.rel_value) ? STOP_TIMEOUT_ARM : timeout, &confirm_cb, "arm"); | 306 | { |
307 | return; | 307 | GNUNET_ARM_stop_service (h, "arm", |
308 | } | 308 | (0 == |
309 | break; | 309 | timeout.rel_value) ? STOP_TIMEOUT_ARM : |
310 | case 2: | 310 | timeout, &confirm_cb, "arm"); |
311 | if (start) | 311 | return; |
312 | { | 312 | } |
313 | GNUNET_ARM_start_service (h, "arm", (0 == timeout.rel_value) ? START_TIMEOUT : timeout, &confirm_cb, "arm"); | 313 | break; |
314 | return; | 314 | case 2: |
315 | } | 315 | if (start) |
316 | break; | 316 | { |
317 | case 3: | 317 | GNUNET_ARM_start_service (h, "arm", |
318 | if (init != NULL) | 318 | (0 == |
319 | { | 319 | timeout.rel_value) ? START_TIMEOUT : timeout, |
320 | GNUNET_ARM_start_service (h, init, (0 == timeout.rel_value) ? START_TIMEOUT : timeout, &confirm_cb, init); | 320 | &confirm_cb, "arm"); |
321 | return; | 321 | return; |
322 | } | 322 | } |
323 | break; | 323 | break; |
324 | case 4: | 324 | case 3: |
325 | if (test != NULL) | 325 | if (init != NULL) |
326 | { | 326 | { |
327 | GNUNET_CLIENT_service_test (test, cfg, (0 == timeout.rel_value) ? TEST_TIMEOUT : timeout, &confirm_task, test); | 327 | GNUNET_ARM_start_service (h, init, |
328 | return; | 328 | (0 == |
329 | } | 329 | timeout.rel_value) ? START_TIMEOUT : timeout, |
330 | break; | 330 | &confirm_cb, init); |
331 | case 5: | 331 | return; |
332 | if (restart) | 332 | } |
333 | { | 333 | break; |
334 | GNUNET_ARM_disconnect (h); | 334 | case 4: |
335 | phase = 0; | 335 | if (test != NULL) |
336 | end = 0; | 336 | { |
337 | start = 1; | 337 | GNUNET_CLIENT_service_test (test, cfg, |
338 | restart = 0; | 338 | (0 == |
339 | h = GNUNET_ARM_connect (cfg, NULL); | 339 | timeout.rel_value) ? TEST_TIMEOUT : |
340 | if (h == NULL) | 340 | timeout, &confirm_task, test); |
341 | { | 341 | return; |
342 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 342 | } |
343 | _("Fatal error initializing ARM API.\n")); | 343 | break; |
344 | ret = 1; | 344 | case 5: |
345 | return; | 345 | if (restart) |
346 | } | 346 | { |
347 | GNUNET_SCHEDULER_add_now(&cps_loop, NULL); | 347 | GNUNET_ARM_disconnect (h); |
348 | return; | 348 | phase = 0; |
349 | } | 349 | end = 0; |
350 | /* Fall through */ | 350 | start = 1; |
351 | default: /* last phase */ | 351 | restart = 0; |
352 | GNUNET_ARM_disconnect (h); | 352 | h = GNUNET_ARM_connect (cfg, NULL); |
353 | if ((end == GNUNET_YES) && (delete == GNUNET_YES)) | 353 | if (h == NULL) |
354 | delete_files(); | 354 | { |
355 | return; | 355 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
356 | } | 356 | _("Fatal error initializing ARM API.\n")); |
357 | ret = 1; | ||
358 | return; | ||
359 | } | ||
360 | GNUNET_SCHEDULER_add_now (&cps_loop, NULL); | ||
361 | return; | ||
362 | } | ||
363 | /* Fall through */ | ||
364 | default: /* last phase */ | ||
365 | GNUNET_ARM_disconnect (h); | ||
366 | if ((end == GNUNET_YES) && (delete == GNUNET_YES)) | ||
367 | delete_files (); | ||
368 | return; | ||
357 | } | 369 | } |
370 | } | ||
358 | } | 371 | } |
359 | 372 | ||
360 | 373 | ||
@@ -379,16 +392,19 @@ main (int argc, char *const *argv) | |||
379 | GNUNET_YES, &GNUNET_GETOPT_set_string, &term}, | 392 | GNUNET_YES, &GNUNET_GETOPT_set_string, &term}, |
380 | {'s', "start", NULL, gettext_noop ("start all GNUnet default services"), | 393 | {'s', "start", NULL, gettext_noop ("start all GNUnet default services"), |
381 | GNUNET_NO, &GNUNET_GETOPT_set_one, &start}, | 394 | GNUNET_NO, &GNUNET_GETOPT_set_one, &start}, |
382 | {'r', "restart", NULL, gettext_noop ("stop and start all GNUnet default services"), | 395 | {'r', "restart", NULL, |
396 | gettext_noop ("stop and start all GNUnet default services"), | ||
383 | GNUNET_NO, &GNUNET_GETOPT_set_one, &restart}, | 397 | GNUNET_NO, &GNUNET_GETOPT_set_one, &restart}, |
384 | {'t', "test", "SERVICE", | 398 | {'t', "test", "SERVICE", |
385 | gettext_noop ("test if a particular service is running"), | 399 | gettext_noop ("test if a particular service is running"), |
386 | GNUNET_YES, &GNUNET_GETOPT_set_string, &test}, | 400 | GNUNET_YES, &GNUNET_GETOPT_set_string, &test}, |
387 | {'d', "delete", NULL, gettext_noop ("delete config file and directory on exit"), | 401 | {'d', "delete", NULL, |
402 | gettext_noop ("delete config file and directory on exit"), | ||
388 | GNUNET_NO, &GNUNET_GETOPT_set_one, &delete}, | 403 | GNUNET_NO, &GNUNET_GETOPT_set_one, &delete}, |
389 | {'q', "quiet", NULL, gettext_noop ("don't print status messages"), | 404 | {'q', "quiet", NULL, gettext_noop ("don't print status messages"), |
390 | GNUNET_NO, &GNUNET_GETOPT_set_one, &quiet}, | 405 | GNUNET_NO, &GNUNET_GETOPT_set_one, &quiet}, |
391 | {'T', "timeout", NULL, gettext_noop ("timeout for completing current operation"), | 406 | {'T', "timeout", NULL, |
407 | gettext_noop ("timeout for completing current operation"), | ||
392 | GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms}, | 408 | GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms}, |
393 | GNUNET_GETOPT_OPTION_END | 409 | GNUNET_GETOPT_OPTION_END |
394 | }; | 410 | }; |
@@ -397,16 +413,16 @@ main (int argc, char *const *argv) | |||
397 | timeout.rel_value = temp_timeout_ms; | 413 | timeout.rel_value = temp_timeout_ms; |
398 | 414 | ||
399 | if (GNUNET_OK == GNUNET_PROGRAM_run (argc, | 415 | if (GNUNET_OK == GNUNET_PROGRAM_run (argc, |
400 | argv, | 416 | argv, |
401 | "gnunet-arm", | 417 | "gnunet-arm", |
402 | gettext_noop | 418 | gettext_noop |
403 | ("Control services and the Automated Restart Manager (ARM)"), | 419 | ("Control services and the Automated Restart Manager (ARM)"), |
404 | options, &run, NULL)) | 420 | options, &run, NULL)) |
405 | { | 421 | { |
406 | return ret; | 422 | return ret; |
407 | } | 423 | } |
408 | 424 | ||
409 | return 1; | 425 | return 1; |
410 | } | 426 | } |
411 | 427 | ||
412 | /* end of gnunet-arm.c */ | 428 | /* end of gnunet-arm.c */ |
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 05c6fb438..e4a8e7c6c 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -188,7 +188,7 @@ static struct GNUNET_SERVER_Handle *server; | |||
188 | * @param cls closure, NULL if we need to self-restart | 188 | * @param cls closure, NULL if we need to self-restart |
189 | * @param tc context | 189 | * @param tc context |
190 | */ | 190 | */ |
191 | static void | 191 | static void |
192 | config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 192 | config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
193 | { | 193 | { |
194 | struct ServiceList *pos; | 194 | struct ServiceList *pos; |
@@ -196,21 +196,21 @@ config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
196 | 196 | ||
197 | pos = running_head; | 197 | pos = running_head; |
198 | while (pos != NULL) | 198 | while (pos != NULL) |
199 | { | ||
200 | /* FIXME: this test for config change may be a bit too coarse grained */ | ||
201 | if ((0 == STAT (pos->config, &sbuf)) && | ||
202 | (pos->mtime < sbuf.st_mtime) && (pos->proc != NULL)) | ||
199 | { | 203 | { |
200 | /* FIXME: this test for config change may be a bit too coarse grained */ | 204 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
201 | if ( (0 == STAT (pos->config, &sbuf)) && | 205 | _ |
202 | (pos->mtime < sbuf.st_mtime) && | 206 | ("Restarting service `%s' due to configuration file change.\n")); |
203 | (pos->proc != NULL) ) | 207 | if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) |
204 | { | 208 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
205 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 209 | else |
206 | _("Restarting service `%s' due to configuration file change.\n")); | 210 | pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
207 | if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) | ||
208 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
209 | else | ||
210 | pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | ||
211 | } | ||
212 | pos = pos->next; | ||
213 | } | 211 | } |
212 | pos = pos->next; | ||
213 | } | ||
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
@@ -229,15 +229,14 @@ write_result (void *cls, size_t size, void *buf) | |||
229 | struct GNUNET_MessageHeader *msg; | 229 | struct GNUNET_MessageHeader *msg; |
230 | 230 | ||
231 | if (buf == NULL) | 231 | if (buf == NULL) |
232 | { | 232 | { |
233 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 233 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
234 | _("Could not send status result to client\n")); | 234 | _("Could not send status result to client\n")); |
235 | return 0; /* error, not much we can do */ | 235 | return 0; /* error, not much we can do */ |
236 | } | 236 | } |
237 | #if DEBUG_ARM | 237 | #if DEBUG_ARM |
238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
239 | "Sending status response %u to client\n", | 239 | "Sending status response %u to client\n", (unsigned int) *res); |
240 | (unsigned int) *res); | ||
241 | #endif | 240 | #endif |
242 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 241 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); |
243 | msg = buf; | 242 | msg = buf; |
@@ -259,29 +258,27 @@ write_result (void *cls, size_t size, void *buf) | |||
259 | */ | 258 | */ |
260 | static void | 259 | static void |
261 | signal_result (struct GNUNET_SERVER_Client *client, | 260 | signal_result (struct GNUNET_SERVER_Client *client, |
262 | const char *name, uint16_t result) | 261 | const char *name, uint16_t result) |
263 | { | 262 | { |
264 | uint16_t *res; | 263 | uint16_t *res; |
265 | 264 | ||
266 | if (NULL == client) | 265 | if (NULL == client) |
267 | { | 266 | { |
268 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 267 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
269 | _ | 268 | _("Not sending status result to client: no client known\n")); |
270 | ("Not sending status result to client: no client known\n")); | 269 | return; |
271 | return; | 270 | } |
272 | } | ||
273 | #if DEBUG_ARM | 271 | #if DEBUG_ARM |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
275 | "Telling client that service `%s' is now %s\n", | 273 | "Telling client that service `%s' is now %s\n", |
276 | name, | 274 | name, result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up"); |
277 | result == GNUNET_MESSAGE_TYPE_ARM_IS_DOWN ? "down" : "up"); | ||
278 | #endif | 275 | #endif |
279 | res = GNUNET_malloc (sizeof (uint16_t)); | 276 | res = GNUNET_malloc (sizeof (uint16_t)); |
280 | *res = result; | 277 | *res = result; |
281 | GNUNET_SERVER_notify_transmit_ready (client, | 278 | GNUNET_SERVER_notify_transmit_ready (client, |
282 | sizeof (struct GNUNET_MessageHeader), | 279 | sizeof (struct GNUNET_MessageHeader), |
283 | GNUNET_TIME_UNIT_FOREVER_REL, | 280 | GNUNET_TIME_UNIT_FOREVER_REL, |
284 | &write_result, res); | 281 | &write_result, res); |
285 | } | 282 | } |
286 | 283 | ||
287 | 284 | ||
@@ -299,11 +296,11 @@ find_service (const char *name) | |||
299 | 296 | ||
300 | pos = running_head; | 297 | pos = running_head; |
301 | while (pos != NULL) | 298 | while (pos != NULL) |
302 | { | 299 | { |
303 | if (0 == strcmp (pos->name, name)) | 300 | if (0 == strcmp (pos->name, name)) |
304 | return pos; | 301 | return pos; |
305 | pos = pos->next; | 302 | pos = pos->next; |
306 | } | 303 | } |
307 | return NULL; | 304 | return NULL; |
308 | } | 305 | } |
309 | 306 | ||
@@ -316,9 +313,7 @@ find_service (const char *name) | |||
316 | static void | 313 | static void |
317 | free_service (struct ServiceList *pos) | 314 | free_service (struct ServiceList *pos) |
318 | { | 315 | { |
319 | GNUNET_CONTAINER_DLL_remove (running_head, | 316 | GNUNET_CONTAINER_DLL_remove (running_head, running_tail, pos); |
320 | running_tail, | ||
321 | pos); | ||
322 | GNUNET_free_non_null (pos->config); | 317 | GNUNET_free_non_null (pos->config); |
323 | GNUNET_free_non_null (pos->binary); | 318 | GNUNET_free_non_null (pos->binary); |
324 | GNUNET_free (pos->name); | 319 | GNUNET_free (pos->name); |
@@ -336,8 +331,7 @@ free_service (struct ServiceList *pos) | |||
336 | * @param lsocks -1 terminated list of listen sockets to pass (systemd style), or NULL | 331 | * @param lsocks -1 terminated list of listen sockets to pass (systemd style), or NULL |
337 | */ | 332 | */ |
338 | static void | 333 | static void |
339 | start_process (struct ServiceList *sl, | 334 | start_process (struct ServiceList *sl, const int *lsocks) |
340 | const int *lsocks) | ||
341 | { | 335 | { |
342 | char *loprefix; | 336 | char *loprefix; |
343 | char *options; | 337 | char *options; |
@@ -351,85 +345,70 @@ start_process (struct ServiceList *sl, | |||
351 | /* start service */ | 345 | /* start service */ |
352 | if (GNUNET_OK != | 346 | if (GNUNET_OK != |
353 | GNUNET_CONFIGURATION_get_value_string (cfg, | 347 | GNUNET_CONFIGURATION_get_value_string (cfg, |
354 | sl->name, "PREFIX", &loprefix)) | 348 | sl->name, "PREFIX", &loprefix)) |
355 | loprefix = GNUNET_strdup (prefix_command); | 349 | loprefix = GNUNET_strdup (prefix_command); |
356 | if (GNUNET_OK != | 350 | if (GNUNET_OK != |
357 | GNUNET_CONFIGURATION_get_value_string (cfg, | 351 | GNUNET_CONFIGURATION_get_value_string (cfg, |
358 | sl->name, "OPTIONS", &options)) | 352 | sl->name, "OPTIONS", &options)) |
359 | { | 353 | { |
360 | options = GNUNET_strdup (final_option); | 354 | options = GNUNET_strdup (final_option); |
361 | if (NULL == strstr (options, "%")) | 355 | if (NULL == strstr (options, "%")) |
362 | { | 356 | { |
363 | /* replace '{}' with service name */ | 357 | /* replace '{}' with service name */ |
364 | while (NULL != (optpos = strstr (options, "{}"))) | 358 | while (NULL != (optpos = strstr (options, "{}"))) |
365 | { | 359 | { |
366 | optpos[0] = '%'; | 360 | optpos[0] = '%'; |
367 | optpos[1] = 's'; | 361 | optpos[1] = 's'; |
368 | GNUNET_asprintf (&optpos, | 362 | GNUNET_asprintf (&optpos, options, sl->name); |
369 | options, | 363 | GNUNET_free (options); |
370 | sl->name); | 364 | options = optpos; |
371 | GNUNET_free (options); | 365 | } |
372 | options = optpos; | 366 | /* replace '$PATH' with value associated with "PATH" */ |
373 | } | 367 | while (NULL != (optpos = strstr (options, "$"))) |
374 | /* replace '$PATH' with value associated with "PATH" */ | 368 | { |
375 | while (NULL != (optpos = strstr (options, "$"))) | 369 | optend = optpos + 1; |
376 | { | 370 | while (isupper ((unsigned char) *optend)) |
377 | optend = optpos + 1; | 371 | optend++; |
378 | while (isupper ( (unsigned char) *optend)) optend++; | 372 | b = *optend; |
379 | b = *optend; | 373 | if ('\0' == b) |
380 | if ('\0' == b) | 374 | next = ""; |
381 | next = ""; | 375 | else |
382 | else | 376 | next = optend + 1; |
383 | next = optend+1; | 377 | *optend = '\0'; |
384 | *optend = '\0'; | 378 | if (GNUNET_OK != |
385 | if (GNUNET_OK != | 379 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", |
386 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", | 380 | optpos + 1, &val)) |
387 | optpos+1, | 381 | val = GNUNET_strdup (""); |
388 | &val)) | 382 | *optpos = '\0'; |
389 | val = GNUNET_strdup (""); | 383 | GNUNET_asprintf (&optpos, "%s%s%c%s", options, val, b, next); |
390 | *optpos = '\0'; | 384 | GNUNET_free (options); |
391 | GNUNET_asprintf (&optpos, | 385 | GNUNET_free (val); |
392 | "%s%s%c%s", | 386 | options = optpos; |
393 | options, | 387 | } |
394 | val, | ||
395 | b, | ||
396 | next); | ||
397 | GNUNET_free (options); | ||
398 | GNUNET_free (val); | ||
399 | options = optpos; | ||
400 | } | ||
401 | } | ||
402 | } | 388 | } |
389 | } | ||
403 | use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG"); | 390 | use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG"); |
404 | 391 | ||
405 | #if DEBUG_ARM | 392 | #if DEBUG_ARM |
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
407 | "Starting service `%s' using binary `%s' and configuration `%s'\n", | 394 | "Starting service `%s' using binary `%s' and configuration `%s'\n", |
408 | sl->name, sl->binary, sl->config); | 395 | sl->name, sl->binary, sl->config); |
409 | #endif | 396 | #endif |
410 | if (GNUNET_YES == use_debug) | 397 | if (GNUNET_YES == use_debug) |
411 | sl->proc = do_start_process (lsocks, | 398 | sl->proc = do_start_process (lsocks, |
412 | loprefix, | 399 | loprefix, |
413 | sl->binary, | 400 | sl->binary, |
414 | "-c", sl->config, | 401 | "-c", sl->config, |
415 | "-L", "DEBUG", | 402 | "-L", "DEBUG", options, NULL); |
416 | options, | ||
417 | NULL); | ||
418 | else | 403 | else |
419 | sl->proc = do_start_process (lsocks, | 404 | sl->proc = do_start_process (lsocks, |
420 | loprefix, | 405 | loprefix, |
421 | sl->binary, | 406 | sl->binary, "-c", sl->config, options, NULL); |
422 | "-c", sl->config, | ||
423 | options, | ||
424 | NULL); | ||
425 | if (sl->proc == NULL) | 407 | if (sl->proc == NULL) |
426 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 408 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
427 | _("Failed to start service `%s'\n"), | 409 | _("Failed to start service `%s'\n"), sl->name); |
428 | sl->name); | ||
429 | else | 410 | else |
430 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 411 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting service `%s'\n"), sl->name); |
431 | _("Starting service `%s'\n"), | ||
432 | sl->name); | ||
433 | GNUNET_free (loprefix); | 412 | GNUNET_free (loprefix); |
434 | GNUNET_free (options); | 413 | GNUNET_free (options); |
435 | } | 414 | } |
@@ -444,9 +423,8 @@ start_process (struct ServiceList *sl, | |||
444 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 423 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
445 | */ | 424 | */ |
446 | int | 425 | int |
447 | start_service (struct GNUNET_SERVER_Client *client, | 426 | start_service (struct GNUNET_SERVER_Client *client, |
448 | const char *servicename, | 427 | const char *servicename, const int *lsocks) |
449 | const int *lsocks) | ||
450 | { | 428 | { |
451 | struct ServiceList *sl; | 429 | struct ServiceList *sl; |
452 | char *binary; | 430 | char *binary; |
@@ -454,46 +432,46 @@ start_service (struct GNUNET_SERVER_Client *client, | |||
454 | struct stat sbuf; | 432 | struct stat sbuf; |
455 | 433 | ||
456 | if (GNUNET_YES == in_shutdown) | 434 | if (GNUNET_YES == in_shutdown) |
457 | { | 435 | { |
458 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 436 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
459 | _("ARM is shutting down, service `%s' not started.\n"), | 437 | _("ARM is shutting down, service `%s' not started.\n"), |
460 | servicename); | 438 | servicename); |
461 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 439 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
462 | return GNUNET_SYSERR; | 440 | return GNUNET_SYSERR; |
463 | } | 441 | } |
464 | sl = find_service (servicename); | 442 | sl = find_service (servicename); |
465 | if (sl != NULL) | 443 | if (sl != NULL) |
466 | { | 444 | { |
467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
468 | _("Service `%s' already running.\n"), servicename); | 446 | _("Service `%s' already running.\n"), servicename); |
469 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP); | 447 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP); |
470 | return GNUNET_SYSERR; | 448 | return GNUNET_SYSERR; |
471 | } | 449 | } |
472 | if (GNUNET_OK != | 450 | if (GNUNET_OK != |
473 | GNUNET_CONFIGURATION_get_value_string (cfg, | 451 | GNUNET_CONFIGURATION_get_value_string (cfg, |
474 | servicename, "BINARY", &binary)) | 452 | servicename, "BINARY", &binary)) |
475 | { | 453 | { |
476 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 454 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
477 | _("Binary implementing service `%s' not known!\n"), | 455 | _("Binary implementing service `%s' not known!\n"), |
478 | servicename); | 456 | servicename); |
479 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 457 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
480 | return GNUNET_SYSERR; | 458 | return GNUNET_SYSERR; |
481 | } | 459 | } |
482 | if ((GNUNET_OK != | 460 | if ((GNUNET_OK != |
483 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 461 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
484 | servicename, | 462 | servicename, |
485 | "CONFIG", | 463 | "CONFIG", |
486 | &config)) || | 464 | &config)) || |
487 | (0 != STAT (config, &sbuf))) | 465 | (0 != STAT (config, &sbuf))) |
488 | { | 466 | { |
489 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 467 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
490 | _("Configuration file `%s' for service `%s' not known!\n"), | 468 | _("Configuration file `%s' for service `%s' not known!\n"), |
491 | config, servicename); | 469 | config, servicename); |
492 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 470 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
493 | GNUNET_free (binary); | 471 | GNUNET_free (binary); |
494 | GNUNET_free_non_null (config); | 472 | GNUNET_free_non_null (config); |
495 | return GNUNET_SYSERR; | 473 | return GNUNET_SYSERR; |
496 | } | 474 | } |
497 | (void) stop_listening (servicename); | 475 | (void) stop_listening (servicename); |
498 | sl = GNUNET_malloc (sizeof (struct ServiceList)); | 476 | sl = GNUNET_malloc (sizeof (struct ServiceList)); |
499 | sl->name = GNUNET_strdup (servicename); | 477 | sl->name = GNUNET_strdup (servicename); |
@@ -502,9 +480,7 @@ start_service (struct GNUNET_SERVER_Client *client, | |||
502 | sl->mtime = sbuf.st_mtime; | 480 | sl->mtime = sbuf.st_mtime; |
503 | sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | 481 | sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS; |
504 | sl->restartAt = GNUNET_TIME_UNIT_FOREVER_ABS; | 482 | sl->restartAt = GNUNET_TIME_UNIT_FOREVER_ABS; |
505 | GNUNET_CONTAINER_DLL_insert (running_head, | 483 | GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl); |
506 | running_tail, | ||
507 | sl); | ||
508 | start_process (sl, lsocks); | 484 | start_process (sl, lsocks); |
509 | if (NULL != client) | 485 | if (NULL != client) |
510 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP); | 486 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UP); |
@@ -519,58 +495,57 @@ start_service (struct GNUNET_SERVER_Client *client, | |||
519 | * @param servicename name of the service to stop | 495 | * @param servicename name of the service to stop |
520 | */ | 496 | */ |
521 | static void | 497 | static void |
522 | stop_service (struct GNUNET_SERVER_Client *client, | 498 | stop_service (struct GNUNET_SERVER_Client *client, const char *servicename) |
523 | const char *servicename) | ||
524 | { | 499 | { |
525 | struct ServiceList *pos; | 500 | struct ServiceList *pos; |
526 | 501 | ||
527 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 502 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
528 | _("Preparing to stop `%s'\n"), servicename); | 503 | _("Preparing to stop `%s'\n"), servicename); |
529 | pos = find_service (servicename); | 504 | pos = find_service (servicename); |
530 | if (pos == NULL) | 505 | if (pos == NULL) |
531 | { | 506 | { |
532 | if (GNUNET_OK == stop_listening (servicename)) | 507 | if (GNUNET_OK == stop_listening (servicename)) |
533 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 508 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
534 | else | 509 | else |
535 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN); | 510 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN); |
536 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 511 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
537 | return; | 512 | return; |
538 | } | 513 | } |
539 | if (pos->killing_client != NULL) | 514 | if (pos->killing_client != NULL) |
540 | { | 515 | { |
541 | /* killing already in progress */ | 516 | /* killing already in progress */ |
542 | #if DEBUG_ARM | 517 | #if DEBUG_ARM |
543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
544 | "Service `%s' is already down\n", servicename); | 519 | "Service `%s' is already down\n", servicename); |
545 | #endif | 520 | #endif |
546 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 521 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
547 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 522 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
548 | return; | 523 | return; |
549 | } | 524 | } |
550 | 525 | ||
551 | if (GNUNET_YES == in_shutdown) | 526 | if (GNUNET_YES == in_shutdown) |
552 | { | 527 | { |
553 | #if DEBUG_ARM | 528 | #if DEBUG_ARM |
554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
555 | "Termination request already sent to `%s' (since ARM is in shutdown).\n", | 530 | "Termination request already sent to `%s' (since ARM is in shutdown).\n", |
556 | servicename); | 531 | servicename); |
557 | #endif | 532 | #endif |
558 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 533 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
559 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 534 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
560 | return; | 535 | return; |
561 | } | 536 | } |
562 | if (pos->proc == NULL) | 537 | if (pos->proc == NULL) |
563 | { | 538 | { |
564 | /* process is in delayed restart, simply remove it! */ | 539 | /* process is in delayed restart, simply remove it! */ |
565 | free_service (pos); | 540 | free_service (pos); |
566 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 541 | signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
567 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 542 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
568 | return; | 543 | return; |
569 | } | 544 | } |
570 | #if DEBUG_ARM | 545 | #if DEBUG_ARM |
571 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
572 | "Sending kill signal to service `%s', waiting for process to die.\n", | 547 | "Sending kill signal to service `%s', waiting for process to die.\n", |
573 | servicename); | 548 | servicename); |
574 | #endif | 549 | #endif |
575 | if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) | 550 | if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) |
576 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 551 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
@@ -590,8 +565,8 @@ stop_service (struct GNUNET_SERVER_Client *client, | |||
590 | */ | 565 | */ |
591 | static void | 566 | static void |
592 | handle_start (void *cls, | 567 | handle_start (void *cls, |
593 | struct GNUNET_SERVER_Client *client, | 568 | struct GNUNET_SERVER_Client *client, |
594 | const struct GNUNET_MessageHeader *message) | 569 | const struct GNUNET_MessageHeader *message) |
595 | { | 570 | { |
596 | const char *servicename; | 571 | const char *servicename; |
597 | uint16_t size; | 572 | uint16_t size; |
@@ -600,11 +575,11 @@ handle_start (void *cls, | |||
600 | size -= sizeof (struct GNUNET_MessageHeader); | 575 | size -= sizeof (struct GNUNET_MessageHeader); |
601 | servicename = (const char *) &message[1]; | 576 | servicename = (const char *) &message[1]; |
602 | if ((size == 0) || (servicename[size - 1] != '\0')) | 577 | if ((size == 0) || (servicename[size - 1] != '\0')) |
603 | { | 578 | { |
604 | GNUNET_break (0); | 579 | GNUNET_break (0); |
605 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 580 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
606 | return; | 581 | return; |
607 | } | 582 | } |
608 | start_service (client, servicename, NULL); | 583 | start_service (client, servicename, NULL); |
609 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 584 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
610 | } | 585 | } |
@@ -621,8 +596,8 @@ handle_start (void *cls, | |||
621 | */ | 596 | */ |
622 | static void | 597 | static void |
623 | handle_stop (void *cls, | 598 | handle_stop (void *cls, |
624 | struct GNUNET_SERVER_Client *client, | 599 | struct GNUNET_SERVER_Client *client, |
625 | const struct GNUNET_MessageHeader *message) | 600 | const struct GNUNET_MessageHeader *message) |
626 | { | 601 | { |
627 | const char *servicename; | 602 | const char *servicename; |
628 | uint16_t size; | 603 | uint16_t size; |
@@ -631,11 +606,11 @@ handle_stop (void *cls, | |||
631 | size -= sizeof (struct GNUNET_MessageHeader); | 606 | size -= sizeof (struct GNUNET_MessageHeader); |
632 | servicename = (const char *) &message[1]; | 607 | servicename = (const char *) &message[1]; |
633 | if ((size == 0) || (servicename[size - 1] != '\0')) | 608 | if ((size == 0) || (servicename[size - 1] != '\0')) |
634 | { | 609 | { |
635 | GNUNET_break (0); | 610 | GNUNET_break (0); |
636 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 611 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
637 | return; | 612 | return; |
638 | } | 613 | } |
639 | stop_service (client, servicename); | 614 | stop_service (client, servicename); |
640 | } | 615 | } |
641 | 616 | ||
@@ -650,14 +625,14 @@ clean_up_running () | |||
650 | { | 625 | { |
651 | struct ServiceList *pos; | 626 | struct ServiceList *pos; |
652 | struct ServiceList *next; | 627 | struct ServiceList *next; |
653 | 628 | ||
654 | next = running_head; | 629 | next = running_head; |
655 | while (NULL != (pos = next)) | 630 | while (NULL != (pos = next)) |
656 | { | 631 | { |
657 | next = pos->next; | 632 | next = pos->next; |
658 | if (pos->proc == NULL) | 633 | if (pos->proc == NULL) |
659 | free_service (pos); | 634 | free_service (pos); |
660 | } | 635 | } |
661 | } | 636 | } |
662 | 637 | ||
663 | 638 | ||
@@ -669,15 +644,15 @@ static void | |||
669 | do_shutdown () | 644 | do_shutdown () |
670 | { | 645 | { |
671 | if (NULL != server) | 646 | if (NULL != server) |
672 | { | 647 | { |
673 | GNUNET_SERVER_destroy (server); | 648 | GNUNET_SERVER_destroy (server); |
674 | server = NULL; | 649 | server = NULL; |
675 | } | 650 | } |
676 | if (GNUNET_SCHEDULER_NO_TASK != child_death_task) | 651 | if (GNUNET_SCHEDULER_NO_TASK != child_death_task) |
677 | { | 652 | { |
678 | GNUNET_SCHEDULER_cancel (child_death_task); | 653 | GNUNET_SCHEDULER_cancel (child_death_task); |
679 | child_death_task = GNUNET_SCHEDULER_NO_TASK; | 654 | child_death_task = GNUNET_SCHEDULER_NO_TASK; |
680 | } | 655 | } |
681 | } | 656 | } |
682 | 657 | ||
683 | 658 | ||
@@ -688,35 +663,31 @@ do_shutdown () | |||
688 | * @param tc context | 663 | * @param tc context |
689 | */ | 664 | */ |
690 | static void | 665 | static void |
691 | shutdown_task (void *cls, | 666 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
692 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
693 | { | 667 | { |
694 | struct ServiceList *pos; | 668 | struct ServiceList *pos; |
695 | 669 | ||
696 | #if DEBUG_ARM | 670 | #if DEBUG_ARM |
697 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Stopping all services\n")); |
698 | _("Stopping all services\n")); | ||
699 | #endif | 672 | #endif |
700 | if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) | 673 | if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) |
701 | { | 674 | { |
702 | GNUNET_SCHEDULER_cancel (child_restart_task); | 675 | GNUNET_SCHEDULER_cancel (child_restart_task); |
703 | child_restart_task = GNUNET_SCHEDULER_NO_TASK; | 676 | child_restart_task = GNUNET_SCHEDULER_NO_TASK; |
704 | } | 677 | } |
705 | in_shutdown = GNUNET_YES; | 678 | in_shutdown = GNUNET_YES; |
706 | stop_listening (NULL); | 679 | stop_listening (NULL); |
707 | pos = running_head; | 680 | pos = running_head; |
708 | while (NULL != pos) | 681 | while (NULL != pos) |
682 | { | ||
683 | if (pos->proc != NULL) | ||
709 | { | 684 | { |
710 | if (pos->proc != NULL) | 685 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n", pos->name); |
711 | { | 686 | if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) |
712 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 687 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
713 | "Stopping service `%s'\n", | ||
714 | pos->name); | ||
715 | if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) | ||
716 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
717 | } | ||
718 | pos = pos->next; | ||
719 | } | 688 | } |
689 | pos = pos->next; | ||
690 | } | ||
720 | if (running_head == NULL) | 691 | if (running_head == NULL) |
721 | do_shutdown (); | 692 | do_shutdown (); |
722 | } | 693 | } |
@@ -741,40 +712,39 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
741 | lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL; | 712 | lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL; |
742 | 713 | ||
743 | /* check for services that need to be restarted due to | 714 | /* check for services that need to be restarted due to |
744 | configuration changes or because the last restart failed */ | 715 | * configuration changes or because the last restart failed */ |
745 | pos = running_head; | 716 | pos = running_head; |
746 | while (pos != NULL) | 717 | while (pos != NULL) |
718 | { | ||
719 | if (pos->proc == NULL) | ||
747 | { | 720 | { |
748 | if (pos->proc == NULL) | 721 | if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0) |
749 | { | 722 | { |
750 | if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0) | 723 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
751 | { | 724 | _("Restarting service `%s'.\n"), pos->name); |
752 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 725 | start_process (pos, NULL); |
753 | _("Restarting service `%s'.\n"), pos->name); | 726 | } |
754 | start_process (pos, NULL); | 727 | else |
755 | } | 728 | { |
756 | else | 729 | lowestRestartDelay |
757 | { | 730 | = GNUNET_TIME_relative_min (lowestRestartDelay, |
758 | lowestRestartDelay | 731 | GNUNET_TIME_absolute_get_remaining |
759 | = GNUNET_TIME_relative_min (lowestRestartDelay, | 732 | (pos->restartAt)); |
760 | GNUNET_TIME_absolute_get_remaining | 733 | } |
761 | (pos->restartAt)); | 734 | } |
762 | } | 735 | pos = pos->next; |
763 | } | 736 | } |
764 | pos = pos->next; | ||
765 | } | ||
766 | if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) | 737 | if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value) |
767 | { | 738 | { |
768 | #if DEBUG_ARM | 739 | #if DEBUG_ARM |
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
770 | "Will restart process in %llums\n", | 741 | "Will restart process in %llums\n", |
771 | (unsigned long long) lowestRestartDelay.rel_value); | 742 | (unsigned long long) lowestRestartDelay.rel_value); |
772 | #endif | 743 | #endif |
773 | child_restart_task | 744 | child_restart_task |
774 | = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay, | 745 | = GNUNET_SCHEDULER_add_delayed (lowestRestartDelay, |
775 | &delayed_restart_task, | 746 | &delayed_restart_task, NULL); |
776 | NULL); | 747 | } |
777 | } | ||
778 | } | 748 | } |
779 | 749 | ||
780 | 750 | ||
@@ -786,8 +756,7 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
786 | * @param tc context | 756 | * @param tc context |
787 | */ | 757 | */ |
788 | static void | 758 | static void |
789 | maint_child_death (void *cls, | 759 | maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
790 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
791 | { | 760 | { |
792 | struct ServiceList *pos; | 761 | struct ServiceList *pos; |
793 | struct ServiceList *next; | 762 | struct ServiceList *next; |
@@ -800,93 +769,89 @@ maint_child_death (void *cls, | |||
800 | 769 | ||
801 | child_death_task = GNUNET_SCHEDULER_NO_TASK; | 770 | child_death_task = GNUNET_SCHEDULER_NO_TASK; |
802 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) | 771 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
803 | { | 772 | { |
804 | /* shutdown scheduled us, ignore! */ | 773 | /* shutdown scheduled us, ignore! */ |
805 | child_death_task = | 774 | child_death_task = |
806 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, | 775 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, |
807 | &maint_child_death, NULL); | 776 | &maint_child_death, NULL); |
808 | return; | 777 | return; |
809 | } | 778 | } |
810 | /* consume the signal */ | 779 | /* consume the signal */ |
811 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); | 780 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); |
812 | 781 | ||
813 | /* check for services that died (WAITPID) */ | 782 | /* check for services that died (WAITPID) */ |
814 | next = running_head; | 783 | next = running_head; |
815 | while (NULL != (pos = next)) | 784 | while (NULL != (pos = next)) |
785 | { | ||
786 | next = pos->next; | ||
787 | if (pos->proc == NULL) | ||
788 | continue; | ||
789 | if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc, | ||
790 | &statusType, | ||
791 | &statusCode))) || | ||
792 | ((ret == GNUNET_NO) || | ||
793 | (statusType == GNUNET_OS_PROCESS_STOPPED) || | ||
794 | (statusType == GNUNET_OS_PROCESS_RUNNING))) | ||
795 | continue; | ||
796 | |||
797 | if (statusType == GNUNET_OS_PROCESS_EXITED) | ||
816 | { | 798 | { |
817 | next = pos->next; | 799 | statstr = _( /* process termination method */ "exit"); |
818 | if (pos->proc == NULL) | 800 | statcode = statusCode; |
819 | continue; | 801 | } |
820 | if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc, | 802 | else if (statusType == GNUNET_OS_PROCESS_SIGNALED) |
821 | &statusType, | 803 | { |
822 | &statusCode))) || | 804 | statstr = _( /* process termination method */ "signal"); |
823 | ( (ret == GNUNET_NO) || | 805 | statcode = statusCode; |
824 | (statusType == GNUNET_OS_PROCESS_STOPPED) || | 806 | } |
825 | (statusType == GNUNET_OS_PROCESS_RUNNING)) ) | 807 | else |
826 | continue; | 808 | { |
827 | 809 | statstr = _( /* process termination method */ "unknown"); | |
828 | if (statusType == GNUNET_OS_PROCESS_EXITED) | 810 | statcode = 0; |
829 | { | 811 | } |
830 | statstr = _( /* process termination method */ "exit"); | 812 | GNUNET_OS_process_close (pos->proc); |
831 | statcode = statusCode; | 813 | pos->proc = NULL; |
832 | } | 814 | if (NULL != pos->killing_client) |
833 | else if (statusType == GNUNET_OS_PROCESS_SIGNALED) | 815 | { |
834 | { | 816 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
835 | statstr = _( /* process termination method */ "signal"); | 817 | _("Service `%s' stopped\n"), pos->name); |
836 | statcode = statusCode; | 818 | signal_result (pos->killing_client, |
837 | } | 819 | pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
838 | else | 820 | GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK); |
839 | { | 821 | GNUNET_SERVER_client_drop (pos->killing_client); |
840 | statstr = _( /* process termination method */ "unknown"); | 822 | free_service (pos); |
841 | statcode = 0; | 823 | continue; |
842 | } | 824 | } |
843 | GNUNET_OS_process_close (pos->proc); | 825 | if (GNUNET_YES != in_shutdown) |
844 | pos->proc = NULL; | 826 | { |
845 | if (NULL != pos->killing_client) | 827 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
846 | { | 828 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
847 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 829 | _ |
848 | _("Service `%s' stopped\n"), | 830 | ("Service `%s' terminated with status %s/%d, will try to restart it!\n"), |
849 | pos->name); | 831 | pos->name, statstr, statcode); |
850 | signal_result (pos->killing_client, | 832 | /* schedule restart */ |
851 | pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 833 | pos->restartAt = GNUNET_TIME_relative_to_absolute (pos->backoff); |
852 | GNUNET_SERVER_receive_done (pos->killing_client, GNUNET_OK); | 834 | if (pos->backoff.rel_value < EXPONENTIAL_BACKOFF_THRESHOLD) |
853 | GNUNET_SERVER_client_drop (pos->killing_client); | 835 | pos->backoff = GNUNET_TIME_relative_multiply (pos->backoff, 2); |
854 | free_service (pos); | 836 | if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) |
855 | continue; | 837 | GNUNET_SCHEDULER_cancel (child_restart_task); |
856 | } | 838 | child_restart_task |
857 | if (GNUNET_YES != in_shutdown) | 839 | = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
858 | { | 840 | &delayed_restart_task, NULL); |
859 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 841 | } |
860 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
861 | _("Service `%s' terminated with status %s/%d, will try to restart it!\n"), | ||
862 | pos->name, statstr, statcode); | ||
863 | /* schedule restart */ | ||
864 | pos->restartAt | ||
865 | = GNUNET_TIME_relative_to_absolute (pos->backoff); | ||
866 | if (pos->backoff.rel_value < EXPONENTIAL_BACKOFF_THRESHOLD) | ||
867 | pos->backoff | ||
868 | = GNUNET_TIME_relative_multiply (pos->backoff, 2); | ||
869 | if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) | ||
870 | GNUNET_SCHEDULER_cancel (child_restart_task); | ||
871 | child_restart_task | ||
872 | = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
873 | &delayed_restart_task, | ||
874 | NULL); | ||
875 | } | ||
876 | #if DEBUG_ARM | 842 | #if DEBUG_ARM |
877 | else | 843 | else |
878 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 844 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
879 | "Service `%s' terminated with status %s/%d\n", | 845 | "Service `%s' terminated with status %s/%d\n", |
880 | pos->name, statstr, statcode); | 846 | pos->name, statstr, statcode); |
881 | #endif | 847 | #endif |
882 | } | 848 | } |
883 | child_death_task = | 849 | child_death_task = |
884 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, | 850 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, |
885 | &maint_child_death, NULL); | 851 | &maint_child_death, NULL); |
886 | if (GNUNET_YES == in_shutdown) | 852 | if (GNUNET_YES == in_shutdown) |
887 | clean_up_running (); | 853 | clean_up_running (); |
888 | if ( (NULL == running_head) && | 854 | if ((NULL == running_head) && (GNUNET_YES == in_shutdown)) |
889 | (GNUNET_YES == in_shutdown) ) | ||
890 | do_shutdown (); | 855 | do_shutdown (); |
891 | } | 856 | } |
892 | 857 | ||
@@ -898,25 +863,24 @@ transmit_shutdown_ack (void *cls, size_t size, void *buf) | |||
898 | struct GNUNET_MessageHeader *msg; | 863 | struct GNUNET_MessageHeader *msg; |
899 | 864 | ||
900 | if (size < sizeof (struct GNUNET_MessageHeader)) | 865 | if (size < sizeof (struct GNUNET_MessageHeader)) |
901 | { | 866 | { |
902 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 867 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
903 | _("Failed to transmit shutdown ACK.\n")); | 868 | _("Failed to transmit shutdown ACK.\n")); |
904 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 869 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
905 | return 0; /* client disconnected */ | 870 | return 0; /* client disconnected */ |
906 | } | 871 | } |
907 | 872 | ||
908 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 873 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting shutdown ACK.\n")); |
909 | _("Transmitting shutdown ACK.\n")); | ||
910 | 874 | ||
911 | /* Make the connection flushing for the purpose of ACK transmitting, | 875 | /* Make the connection flushing for the purpose of ACK transmitting, |
912 | needed on W32 to ensure that the message is even received, harmless | 876 | * needed on W32 to ensure that the message is even received, harmless |
913 | on other platforms... */ | 877 | * on other platforms... */ |
914 | GNUNET_break (GNUNET_OK == GNUNET_SERVER_client_disable_corking (client)); | 878 | GNUNET_break (GNUNET_OK == GNUNET_SERVER_client_disable_corking (client)); |
915 | msg = (struct GNUNET_MessageHeader *) buf; | 879 | msg = (struct GNUNET_MessageHeader *) buf; |
916 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK); | 880 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK); |
917 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 881 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
918 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 882 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
919 | GNUNET_SERVER_client_drop(client); | 883 | GNUNET_SERVER_client_drop (client); |
920 | return sizeof (struct GNUNET_MessageHeader); | 884 | return sizeof (struct GNUNET_MessageHeader); |
921 | } | 885 | } |
922 | 886 | ||
@@ -933,11 +897,11 @@ handle_shutdown (void *cls, | |||
933 | struct GNUNET_SERVER_Client *client, | 897 | struct GNUNET_SERVER_Client *client, |
934 | const struct GNUNET_MessageHeader *message) | 898 | const struct GNUNET_MessageHeader *message) |
935 | { | 899 | { |
936 | GNUNET_SERVER_client_keep(client); | 900 | GNUNET_SERVER_client_keep (client); |
937 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 901 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
938 | _("Initiating shutdown as requested by client.\n")); | 902 | _("Initiating shutdown as requested by client.\n")); |
939 | GNUNET_SERVER_notify_transmit_ready (client, | 903 | GNUNET_SERVER_notify_transmit_ready (client, |
940 | sizeof(struct GNUNET_MessageHeader), | 904 | sizeof (struct GNUNET_MessageHeader), |
941 | GNUNET_TIME_UNIT_FOREVER_REL, | 905 | GNUNET_TIME_UNIT_FOREVER_REL, |
942 | &transmit_shutdown_ack, client); | 906 | &transmit_shutdown_ack, client); |
943 | GNUNET_SERVER_client_persist_ (client); | 907 | GNUNET_SERVER_client_persist_ (client); |
@@ -953,12 +917,13 @@ static void | |||
953 | sighandler_child_death () | 917 | sighandler_child_death () |
954 | { | 918 | { |
955 | static char c; | 919 | static char c; |
956 | int old_errno = errno; /* back-up errno */ | 920 | int old_errno = errno; /* back-up errno */ |
957 | GNUNET_break (1 == | 921 | |
958 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle | 922 | GNUNET_break (1 == |
959 | (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c, | 923 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle |
960 | sizeof (c))); | 924 | (sigpipe, GNUNET_DISK_PIPE_END_WRITE), |
961 | errno = old_errno; /* restore errno */ | 925 | &c, sizeof (c))); |
926 | errno = old_errno; /* restore errno */ | ||
962 | } | 927 | } |
963 | 928 | ||
964 | 929 | ||
@@ -991,63 +956,59 @@ run (void *cls, | |||
991 | GNUNET_assert (pr != NULL); | 956 | GNUNET_assert (pr != NULL); |
992 | GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES); | 957 | GNUNET_SERVER_ignore_shutdown (serv, GNUNET_YES); |
993 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 958 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
994 | &shutdown_task, | 959 | &shutdown_task, NULL); |
995 | NULL); | ||
996 | child_death_task = | 960 | child_death_task = |
997 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, | 961 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, pr, |
998 | &maint_child_death, NULL); | 962 | &maint_child_death, NULL); |
999 | 963 | ||
1000 | if (GNUNET_OK != | 964 | if (GNUNET_OK != |
1001 | GNUNET_CONFIGURATION_get_value_string (cfg, | 965 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1002 | "ARM", | 966 | "ARM", |
1003 | "GLOBAL_PREFIX", | 967 | "GLOBAL_PREFIX", &prefix_command)) |
1004 | &prefix_command)) | ||
1005 | prefix_command = GNUNET_strdup (""); | 968 | prefix_command = GNUNET_strdup (""); |
1006 | if (GNUNET_OK != | 969 | if (GNUNET_OK != |
1007 | GNUNET_CONFIGURATION_get_value_string (cfg, | 970 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1008 | "ARM", | 971 | "ARM", |
1009 | "GLOBAL_POSTFIX", | 972 | "GLOBAL_POSTFIX", &final_option)) |
1010 | &final_option)) | ||
1011 | final_option = GNUNET_strdup (""); | 973 | final_option = GNUNET_strdup (""); |
1012 | /* start default services... */ | 974 | /* start default services... */ |
1013 | if (GNUNET_OK == | 975 | if (GNUNET_OK == |
1014 | GNUNET_CONFIGURATION_get_value_string (cfg, | 976 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1015 | "ARM", | 977 | "ARM", |
1016 | "DEFAULTSERVICES", | 978 | "DEFAULTSERVICES", |
1017 | &defaultservices)) | 979 | &defaultservices)) |
1018 | { | 980 | { |
1019 | #if DEBUG_ARM | 981 | #if DEBUG_ARM |
1020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1021 | "Starting default services `%s'\n", defaultservices); | 983 | "Starting default services `%s'\n", defaultservices); |
1022 | #endif | 984 | #endif |
1023 | if (0 < strlen (defaultservices)) | 985 | if (0 < strlen (defaultservices)) |
1024 | { | 986 | { |
1025 | pos = strtok (defaultservices, " "); | 987 | pos = strtok (defaultservices, " "); |
1026 | while (pos != NULL) | 988 | while (pos != NULL) |
1027 | { | 989 | { |
1028 | start_service (NULL, pos, NULL); | 990 | start_service (NULL, pos, NULL); |
1029 | pos = strtok (NULL, " "); | 991 | pos = strtok (NULL, " "); |
1030 | } | 992 | } |
1031 | } | ||
1032 | GNUNET_free (defaultservices); | ||
1033 | } | 993 | } |
994 | GNUNET_free (defaultservices); | ||
995 | } | ||
1034 | else | 996 | else |
1035 | { | 997 | { |
1036 | #if DEBUG_ARM | 998 | #if DEBUG_ARM |
1037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 999 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No default services configured.\n"); |
1038 | "No default services configured.\n"); | ||
1039 | #endif | 1000 | #endif |
1040 | } | 1001 | } |
1041 | 1002 | ||
1042 | /* create listening sockets for future services*/ | 1003 | /* create listening sockets for future services */ |
1043 | prepareServices (cfg); | 1004 | prepareServices (cfg); |
1044 | 1005 | ||
1045 | /* process client requests */ | 1006 | /* process client requests */ |
1046 | GNUNET_SERVER_add_handlers (server, handlers); | 1007 | GNUNET_SERVER_add_handlers (server, handlers); |
1047 | 1008 | ||
1048 | /* manage services */ | 1009 | /* manage services */ |
1049 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1010 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1050 | &config_change_task, NULL); | 1011 | &config_change_task, NULL); |
1051 | } | 1012 | } |
1052 | 1013 | ||
1053 | 1014 | ||
@@ -1066,10 +1027,11 @@ main (int argc, char *const *argv) | |||
1066 | 1027 | ||
1067 | sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); | 1028 | sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO); |
1068 | GNUNET_assert (sigpipe != NULL); | 1029 | GNUNET_assert (sigpipe != NULL); |
1069 | shc_chld = GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 1030 | shc_chld = |
1070 | ret = (GNUNET_OK == | 1031 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); |
1071 | GNUNET_SERVICE_run (argc, | 1032 | ret = |
1072 | argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1; | 1033 | (GNUNET_OK == |
1034 | GNUNET_SERVICE_run (argc, argv, "arm", GNUNET_YES, &run, NULL)) ? 0 : 1; | ||
1073 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 1035 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
1074 | shc_chld = NULL; | 1036 | shc_chld = NULL; |
1075 | GNUNET_DISK_pipe_close (sigpipe); | 1037 | GNUNET_DISK_pipe_close (sigpipe); |
@@ -1085,8 +1047,8 @@ main (int argc, char *const *argv) | |||
1085 | */ | 1047 | */ |
1086 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | 1048 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () |
1087 | { | 1049 | { |
1088 | mallopt (M_TRIM_THRESHOLD, 4*1024); | 1050 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); |
1089 | mallopt (M_TOP_PAD, 1*1024); | 1051 | mallopt (M_TOP_PAD, 1 * 1024); |
1090 | malloc_trim (0); | 1052 | malloc_trim (0); |
1091 | } | 1053 | } |
1092 | #endif | 1054 | #endif |
diff --git a/src/arm/gnunet-service-arm.h b/src/arm/gnunet-service-arm.h index 0ef557157..a9f72b512 100644 --- a/src/arm/gnunet-service-arm.h +++ b/src/arm/gnunet-service-arm.h | |||
@@ -36,8 +36,7 @@ | |||
36 | * @return GNUNET_OK on success | 36 | * @return GNUNET_OK on success |
37 | */ | 37 | */ |
38 | int start_service (struct GNUNET_SERVER_Client *client, | 38 | int start_service (struct GNUNET_SERVER_Client *client, |
39 | const char *servicename, | 39 | const char *servicename, const int *lsocks); |
40 | const int *lsocks); | ||
41 | 40 | ||
42 | /** | 41 | /** |
43 | * Stop listening for connections to a service. | 42 | * Stop listening for connections to a service. |
@@ -49,6 +48,6 @@ int start_service (struct GNUNET_SERVER_Client *client, | |||
49 | int stop_listening (const char *serviceName); | 48 | int stop_listening (const char *serviceName); |
50 | 49 | ||
51 | void prepareServices (const struct GNUNET_CONFIGURATION_Handle | 50 | void prepareServices (const struct GNUNET_CONFIGURATION_Handle |
52 | *configurationHandle); | 51 | *configurationHandle); |
53 | 52 | ||
54 | #endif | 53 | #endif |
diff --git a/src/arm/gnunet-service-arm_interceptor.c b/src/arm/gnunet-service-arm_interceptor.c index 8f4a4731c..b99b076da 100644 --- a/src/arm/gnunet-service-arm_interceptor.c +++ b/src/arm/gnunet-service-arm_interceptor.c | |||
@@ -153,12 +153,12 @@ struct ForwardedConnection | |||
153 | * Timeout for forwarding. | 153 | * Timeout for forwarding. |
154 | */ | 154 | */ |
155 | struct GNUNET_TIME_Absolute timeout; | 155 | struct GNUNET_TIME_Absolute timeout; |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * Current back-off value. | 158 | * Current back-off value. |
159 | */ | 159 | */ |
160 | struct GNUNET_TIME_Relative back_off; | 160 | struct GNUNET_TIME_Relative back_off; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * Task that tries to initiate forwarding. | 163 | * Task that tries to initiate forwarding. |
164 | */ | 164 | */ |
@@ -243,10 +243,10 @@ addDefaultServicesToList (const char *services) | |||
243 | s = GNUNET_strdup (services); | 243 | s = GNUNET_strdup (services); |
244 | token = strtok (s, " "); | 244 | token = strtok (s, " "); |
245 | while (NULL != token) | 245 | while (NULL != token) |
246 | { | 246 | { |
247 | numDefaultServices++; | 247 | numDefaultServices++; |
248 | token = strtok (NULL, " "); | 248 | token = strtok (NULL, " "); |
249 | } | 249 | } |
250 | GNUNET_free (s); | 250 | GNUNET_free (s); |
251 | 251 | ||
252 | defaultServicesList = GNUNET_malloc (numDefaultServices * sizeof (char *)); | 252 | defaultServicesList = GNUNET_malloc (numDefaultServices * sizeof (char *)); |
@@ -254,10 +254,10 @@ addDefaultServicesToList (const char *services) | |||
254 | s = GNUNET_strdup (services); | 254 | s = GNUNET_strdup (services); |
255 | token = strtok (s, " "); | 255 | token = strtok (s, " "); |
256 | while (NULL != token) | 256 | while (NULL != token) |
257 | { | 257 | { |
258 | defaultServicesList[i++] = GNUNET_strdup (token); | 258 | defaultServicesList[i++] = GNUNET_strdup (token); |
259 | token = strtok (NULL, " "); | 259 | token = strtok (NULL, " "); |
260 | } | 260 | } |
261 | GNUNET_free (s); | 261 | GNUNET_free (s); |
262 | GNUNET_assert (i == numDefaultServices); | 262 | GNUNET_assert (i == numDefaultServices); |
263 | } | 263 | } |
@@ -272,9 +272,10 @@ static int | |||
272 | isInDefaultList (const char *serviceName) | 272 | isInDefaultList (const char *serviceName) |
273 | { | 273 | { |
274 | unsigned int i; | 274 | unsigned int i; |
275 | |||
275 | for (i = 0; i < numDefaultServices; i++) | 276 | for (i = 0; i < numDefaultServices; i++) |
276 | if (strcmp (serviceName, defaultServicesList[i]) == 0) | 277 | if (strcmp (serviceName, defaultServicesList[i]) == 0) |
277 | return GNUNET_YES; | 278 | return GNUNET_YES; |
278 | return GNUNET_NO; | 279 | return GNUNET_NO; |
279 | } | 280 | } |
280 | 281 | ||
@@ -286,52 +287,45 @@ isInDefaultList (const char *serviceName) | |||
286 | * @param reason which direction to close | 287 | * @param reason which direction to close |
287 | */ | 288 | */ |
288 | static void | 289 | static void |
289 | closeClientAndServiceSockets (struct ForwardedConnection *fc, | 290 | closeClientAndServiceSockets (struct ForwardedConnection *fc, int reason) |
290 | int reason) | ||
291 | { | 291 | { |
292 | if (0 != (REASON_SERVICE_TO_CLIENT & reason)) | 292 | if (0 != (REASON_SERVICE_TO_CLIENT & reason)) |
293 | { | 293 | { |
294 | #if DEBUG_SERVICE_MANAGER | 294 | #if DEBUG_SERVICE_MANAGER |
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Stopping forwarding from service to client\n"); | 296 | "Stopping forwarding from service to client\n"); |
297 | #endif | 297 | #endif |
298 | if (fc->armClientSocket != NULL) | 298 | if (fc->armClientSocket != NULL) |
299 | GNUNET_NETWORK_socket_shutdown (fc->armClientSocket, | 299 | GNUNET_NETWORK_socket_shutdown (fc->armClientSocket, SHUT_WR); |
300 | SHUT_WR); | 300 | if (fc->armServiceSocket != NULL) |
301 | if (fc->armServiceSocket != NULL) | 301 | GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket, SHUT_RD); |
302 | GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket, | 302 | } |
303 | SHUT_RD); | 303 | if (0 != (REASON_CLIENT_TO_SERVICE & reason)) |
304 | } | 304 | { |
305 | if (0 != (REASON_CLIENT_TO_SERVICE & reason)) | ||
306 | { | ||
307 | #if DEBUG_SERVICE_MANAGER | 305 | #if DEBUG_SERVICE_MANAGER |
308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
309 | "Stopping forwarding from client to service\n"); | 307 | "Stopping forwarding from client to service\n"); |
310 | #endif | 308 | #endif |
311 | if (fc->armClientSocket != NULL) | 309 | if (fc->armClientSocket != NULL) |
312 | GNUNET_NETWORK_socket_shutdown (fc->armClientSocket, | 310 | GNUNET_NETWORK_socket_shutdown (fc->armClientSocket, SHUT_RD); |
313 | SHUT_RD); | 311 | if (fc->armServiceSocket != NULL) |
314 | if (fc->armServiceSocket != NULL) | 312 | GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket, SHUT_WR); |
315 | GNUNET_NETWORK_socket_shutdown (fc->armServiceSocket, | 313 | } |
316 | SHUT_WR); | ||
317 | } | ||
318 | #if DEBUG_SERVICE_MANAGER | 314 | #if DEBUG_SERVICE_MANAGER |
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
320 | "Closing forwarding connection (done with both directions)\n"); | 316 | "Closing forwarding connection (done with both directions)\n"); |
321 | #endif | 317 | #endif |
322 | fc->reference_count -= 1; | 318 | fc->reference_count -= 1; |
323 | if (fc->reference_count <= 0) | 319 | if (fc->reference_count <= 0) |
324 | { | 320 | { |
325 | if ( (NULL != fc->armClientSocket) && | 321 | if ((NULL != fc->armClientSocket) && |
326 | (GNUNET_SYSERR == | 322 | (GNUNET_SYSERR == GNUNET_NETWORK_socket_close (fc->armClientSocket))) |
327 | GNUNET_NETWORK_socket_close (fc->armClientSocket)) ) | ||
328 | { | 323 | { |
329 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close"); | 324 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close"); |
330 | fc->armClientSocket = NULL; | 325 | fc->armClientSocket = NULL; |
331 | } | 326 | } |
332 | if ( (NULL != fc->armServiceSocket) && | 327 | if ((NULL != fc->armServiceSocket) && |
333 | (GNUNET_SYSERR == | 328 | (GNUNET_SYSERR == GNUNET_NETWORK_socket_close (fc->armServiceSocket))) |
334 | GNUNET_NETWORK_socket_close (fc->armServiceSocket)) ) | ||
335 | { | 329 | { |
336 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close"); | 330 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "close"); |
337 | fc->armServiceSocket = NULL; | 331 | fc->armServiceSocket = NULL; |
@@ -380,8 +374,7 @@ receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
380 | * | 374 | * |
381 | */ | 375 | */ |
382 | static void | 376 | static void |
383 | start_forwarding (void *cls, | 377 | start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
384 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
385 | 378 | ||
386 | 379 | ||
387 | 380 | ||
@@ -399,54 +392,46 @@ forwardToClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
399 | 392 | ||
400 | fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK; | 393 | fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK; |
401 | if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready, | 394 | if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready, |
402 | fc->armClientSocket)) | 395 | fc->armClientSocket)) |
403 | { | 396 | { |
404 | fc->service_to_client_task = | 397 | fc->service_to_client_task = |
405 | GNUNET_SCHEDULER_add_write_net ( | 398 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
406 | GNUNET_TIME_UNIT_FOREVER_REL, | 399 | fc->armClientSocket, |
407 | fc->armClientSocket, | 400 | &forwardToClient, fc); |
408 | &forwardToClient, fc); | 401 | return; |
409 | return; | 402 | } |
410 | } | ||
411 | /* Forwarding service response to client */ | 403 | /* Forwarding service response to client */ |
412 | numberOfBytesSent = | 404 | numberOfBytesSent = |
413 | GNUNET_NETWORK_socket_send (fc->armClientSocket, | 405 | GNUNET_NETWORK_socket_send (fc->armClientSocket, |
414 | fc->service_to_client_bufferPos, | 406 | fc->service_to_client_bufferPos, |
415 | fc->service_to_client_bufferDataLength); | 407 | fc->service_to_client_bufferDataLength); |
416 | if (numberOfBytesSent <= 0) | 408 | if (numberOfBytesSent <= 0) |
417 | { | 409 | { |
418 | if ( (errno != EPIPE) && | 410 | if ((errno != EPIPE) && (errno != ECONNRESET)) |
419 | (errno != ECONNRESET) ) | 411 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
420 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 412 | "Failed to forward %u bytes of data to client: %s\n", |
421 | "Failed to forward %u bytes of data to client: %s\n", | 413 | fc->service_to_client_bufferDataLength, STRERROR (errno)); |
422 | fc->service_to_client_bufferDataLength, | 414 | closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT); |
423 | STRERROR (errno)); | 415 | return; |
424 | closeClientAndServiceSockets (fc, | 416 | } |
425 | REASON_SERVICE_TO_CLIENT); | ||
426 | return; | ||
427 | } | ||
428 | #if DEBUG_SERVICE_MANAGER | 417 | #if DEBUG_SERVICE_MANAGER |
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
430 | "Forwarded %d bytes to client\n", | 419 | "Forwarded %d bytes to client\n", numberOfBytesSent); |
431 | numberOfBytesSent); | ||
432 | #endif | 420 | #endif |
433 | if (numberOfBytesSent < fc->service_to_client_bufferDataLength) | 421 | if (numberOfBytesSent < fc->service_to_client_bufferDataLength) |
434 | { | 422 | { |
435 | fc->service_to_client_bufferPos += numberOfBytesSent; | 423 | fc->service_to_client_bufferPos += numberOfBytesSent; |
436 | fc->service_to_client_bufferDataLength -= numberOfBytesSent; | 424 | fc->service_to_client_bufferDataLength -= numberOfBytesSent; |
437 | fc->service_to_client_task = | 425 | fc->service_to_client_task = |
438 | GNUNET_SCHEDULER_add_write_net ( | 426 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
439 | GNUNET_TIME_UNIT_FOREVER_REL, | 427 | fc->armClientSocket, |
440 | fc->armClientSocket, | 428 | &forwardToClient, fc); |
441 | &forwardToClient, | 429 | return; |
442 | fc); | 430 | } |
443 | return; | ||
444 | } | ||
445 | fc->service_to_client_task = | 431 | fc->service_to_client_task = |
446 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 432 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
447 | fc->armServiceSocket, | 433 | fc->armServiceSocket, |
448 | &receiveFromService, | 434 | &receiveFromService, fc); |
449 | fc); | ||
450 | } | 435 | } |
451 | 436 | ||
452 | 437 | ||
@@ -457,98 +442,92 @@ forwardToClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
457 | * @param tc scheduler context | 442 | * @param tc scheduler context |
458 | */ | 443 | */ |
459 | static void | 444 | static void |
460 | receiveFromService (void *cls, | 445 | receiveFromService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
461 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
462 | { | 446 | { |
463 | struct ForwardedConnection *fc = cls; | 447 | struct ForwardedConnection *fc = cls; |
464 | struct GNUNET_TIME_Relative rem; | 448 | struct GNUNET_TIME_Relative rem; |
465 | 449 | ||
466 | fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK; | 450 | fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK; |
467 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) && | 451 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) && |
468 | (fc->first_write_done != GNUNET_YES) ) | 452 | (fc->first_write_done != GNUNET_YES)) |
469 | { | 453 | { |
470 | closeClientAndServiceSockets (fc, REASON_ERROR); | 454 | closeClientAndServiceSockets (fc, REASON_ERROR); |
471 | return; | 455 | return; |
472 | } | 456 | } |
473 | if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready, | 457 | if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready, |
474 | fc->armServiceSocket)) | 458 | fc->armServiceSocket)) |
475 | { | 459 | { |
476 | fc->service_to_client_task = | 460 | fc->service_to_client_task = |
477 | GNUNET_SCHEDULER_add_read_net ( | 461 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
478 | GNUNET_TIME_UNIT_FOREVER_REL, | 462 | fc->armServiceSocket, |
479 | fc->armServiceSocket, | 463 | &receiveFromService, fc); |
480 | &receiveFromService, fc); | 464 | return; |
481 | return; | 465 | } |
482 | } | ||
483 | fc->service_to_client_bufferPos = fc->service_to_client_buffer; | 466 | fc->service_to_client_bufferPos = fc->service_to_client_buffer; |
484 | fc->service_to_client_bufferDataLength = | 467 | fc->service_to_client_bufferDataLength = |
485 | GNUNET_NETWORK_socket_recv (fc->armServiceSocket, | 468 | GNUNET_NETWORK_socket_recv (fc->armServiceSocket, |
486 | fc->service_to_client_buffer, | 469 | fc->service_to_client_buffer, BUFFER_SIZE); |
487 | BUFFER_SIZE); | ||
488 | if (fc->service_to_client_bufferDataLength <= 0) | 470 | if (fc->service_to_client_bufferDataLength <= 0) |
489 | { | 471 | { |
490 | #if DEBUG_SERVICE_MANAGER | 472 | #if DEBUG_SERVICE_MANAGER |
491 | if (fc->service_to_client_bufferDataLength == 0) | 473 | if (fc->service_to_client_bufferDataLength == 0) |
492 | { | 474 | { |
493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
494 | "Service `%s' stopped sending data.\n", | 476 | "Service `%s' stopped sending data.\n", |
495 | fc->listen_info->serviceName); | 477 | fc->listen_info->serviceName); |
496 | } | 478 | } |
497 | #endif | 479 | #endif |
498 | if (fc->first_write_done != GNUNET_YES) | 480 | if (fc->first_write_done != GNUNET_YES) |
499 | { | 481 | { |
500 | fc->service_to_client_bufferDataLength = 0; | 482 | fc->service_to_client_bufferDataLength = 0; |
501 | GNUNET_break (GNUNET_OK == | 483 | GNUNET_break (GNUNET_OK == |
502 | GNUNET_NETWORK_socket_close (fc->armServiceSocket)); | 484 | GNUNET_NETWORK_socket_close (fc->armServiceSocket)); |
503 | fc->armServiceSocket = NULL; | 485 | fc->armServiceSocket = NULL; |
504 | if ( (fc->client_to_service_bufferDataLength > 0) && | 486 | if ((fc->client_to_service_bufferDataLength > 0) && |
505 | (fc->client_to_service_task != GNUNET_SCHEDULER_NO_TASK) ) | 487 | (fc->client_to_service_task != GNUNET_SCHEDULER_NO_TASK)) |
506 | { | 488 | { |
507 | GNUNET_SCHEDULER_cancel (fc->client_to_service_task); | 489 | GNUNET_SCHEDULER_cancel (fc->client_to_service_task); |
508 | fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK; | 490 | fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK; |
509 | } | 491 | } |
510 | fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2); | 492 | fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2); |
511 | #if DEBUG_SERVICE_MANAGER | 493 | #if DEBUG_SERVICE_MANAGER |
512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
513 | "Failed to connected to service `%s' at `%s', will try again in %llu ms\n", | 495 | "Failed to connected to service `%s' at `%s', will try again in %llu ms\n", |
514 | fc->listen_info->serviceName, | 496 | fc->listen_info->serviceName, |
515 | GNUNET_a2s (fc->listen_info->service_addr, | 497 | GNUNET_a2s (fc->listen_info->service_addr, |
516 | fc->listen_info->service_addr_len), | 498 | fc->listen_info->service_addr_len), |
517 | (unsigned long long) GNUNET_TIME_relative_min (fc->back_off, | 499 | (unsigned long long) GNUNET_TIME_relative_min (fc->back_off, |
518 | rem).rel_value); | 500 | rem).rel_value); |
519 | #endif | 501 | #endif |
520 | rem = GNUNET_TIME_absolute_get_remaining (fc->timeout); | 502 | rem = GNUNET_TIME_absolute_get_remaining (fc->timeout); |
521 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); | 503 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); |
522 | fc->start_task | 504 | fc->start_task |
523 | = GNUNET_SCHEDULER_add_delayed ( | 505 | = |
524 | GNUNET_TIME_relative_min (fc->back_off, | 506 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min |
525 | rem), | 507 | (fc->back_off, rem), &start_forwarding, |
526 | &start_forwarding, | 508 | fc); |
527 | fc); | 509 | } |
528 | } | 510 | else |
529 | else | 511 | { |
530 | { | ||
531 | #if DEBUG_SERVICE_MANAGER | 512 | #if DEBUG_SERVICE_MANAGER |
532 | if (fc->service_to_client_bufferDataLength != 0) | 513 | if (fc->service_to_client_bufferDataLength != 0) |
533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 514 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
534 | "Error receiving from service: %s\n", | 515 | "Error receiving from service: %s\n", STRERROR (errno)); |
535 | STRERROR (errno)); | ||
536 | #endif | 516 | #endif |
537 | closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT); | 517 | closeClientAndServiceSockets (fc, REASON_SERVICE_TO_CLIENT); |
538 | } | ||
539 | return; | ||
540 | } | 518 | } |
519 | return; | ||
520 | } | ||
541 | fc->first_write_done = GNUNET_YES; | 521 | fc->first_write_done = GNUNET_YES; |
542 | #if DEBUG_SERVICE_MANAGER | 522 | #if DEBUG_SERVICE_MANAGER |
543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
544 | "Received %d bytes for client\n", | 524 | "Received %d bytes for client\n", |
545 | fc->service_to_client_bufferDataLength); | 525 | fc->service_to_client_bufferDataLength); |
546 | #endif | 526 | #endif |
547 | fc->service_to_client_task = | 527 | fc->service_to_client_task = |
548 | GNUNET_SCHEDULER_add_write_net ( | 528 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
549 | GNUNET_TIME_UNIT_FOREVER_REL, | 529 | fc->armClientSocket, |
550 | fc->armClientSocket, | 530 | &forwardToClient, fc); |
551 | &forwardToClient, fc); | ||
552 | } | 531 | } |
553 | 532 | ||
554 | 533 | ||
@@ -559,98 +538,92 @@ receiveFromService (void *cls, | |||
559 | * @param tc scheduler context | 538 | * @param tc scheduler context |
560 | */ | 539 | */ |
561 | static void | 540 | static void |
562 | forwardToService (void *cls, | 541 | forwardToService (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
563 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
564 | { | 542 | { |
565 | struct ForwardedConnection *fc = cls; | 543 | struct ForwardedConnection *fc = cls; |
566 | ssize_t numberOfBytesSent; | 544 | ssize_t numberOfBytesSent; |
567 | struct GNUNET_TIME_Relative rem; | 545 | struct GNUNET_TIME_Relative rem; |
568 | 546 | ||
569 | fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK; | 547 | fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK; |
570 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) && | 548 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) && |
571 | (fc->first_write_done != GNUNET_YES) ) | 549 | (fc->first_write_done != GNUNET_YES)) |
572 | { | 550 | { |
573 | closeClientAndServiceSockets (fc, REASON_ERROR); | 551 | closeClientAndServiceSockets (fc, REASON_ERROR); |
574 | return; | 552 | return; |
575 | } | 553 | } |
576 | if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready, | 554 | if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->write_ready, |
577 | fc->armServiceSocket)) | 555 | fc->armServiceSocket)) |
578 | { | 556 | { |
579 | fc->client_to_service_task = | 557 | fc->client_to_service_task = |
580 | GNUNET_SCHEDULER_add_write_net ( | 558 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
581 | GNUNET_TIME_UNIT_FOREVER_REL, | 559 | fc->armServiceSocket, |
582 | fc->armServiceSocket, | 560 | &forwardToService, fc); |
583 | &forwardToService, fc); | 561 | return; |
584 | return; | 562 | } |
585 | } | ||
586 | numberOfBytesSent = | 563 | numberOfBytesSent = |
587 | GNUNET_NETWORK_socket_send (fc->armServiceSocket, | 564 | GNUNET_NETWORK_socket_send (fc->armServiceSocket, |
588 | fc->client_to_service_bufferPos, | 565 | fc->client_to_service_bufferPos, |
589 | fc->client_to_service_bufferDataLength); | 566 | fc->client_to_service_bufferDataLength); |
590 | if (numberOfBytesSent <= 0) | 567 | if (numberOfBytesSent <= 0) |
568 | { | ||
569 | if (GNUNET_YES != fc->first_write_done) | ||
591 | { | 570 | { |
592 | if (GNUNET_YES != fc->first_write_done) | 571 | GNUNET_break (GNUNET_OK == |
593 | { | 572 | GNUNET_NETWORK_socket_close (fc->armServiceSocket)); |
594 | GNUNET_break (GNUNET_OK == | 573 | fc->armServiceSocket = NULL; |
595 | GNUNET_NETWORK_socket_close (fc->armServiceSocket)); | 574 | if ((fc->service_to_client_bufferDataLength == 0) && |
596 | fc->armServiceSocket = NULL; | 575 | (fc->service_to_client_task != GNUNET_SCHEDULER_NO_TASK)) |
597 | if ( (fc->service_to_client_bufferDataLength == 0) && | 576 | { |
598 | (fc->service_to_client_task != GNUNET_SCHEDULER_NO_TASK) ) | 577 | GNUNET_SCHEDULER_cancel (fc->service_to_client_task); |
599 | { | 578 | fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK; |
600 | GNUNET_SCHEDULER_cancel (fc->service_to_client_task); | 579 | } |
601 | fc->service_to_client_task = GNUNET_SCHEDULER_NO_TASK; | 580 | fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2); |
602 | } | ||
603 | fc->back_off = GNUNET_TIME_relative_multiply (fc->back_off, 2); | ||
604 | #if DEBUG_SERVICE_MANAGER | 581 | #if DEBUG_SERVICE_MANAGER |
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
606 | "Failed to connect to service `%s' at `%s', will try again in %llu ms\n", | 583 | "Failed to connect to service `%s' at `%s', will try again in %llu ms\n", |
607 | fc->listen_info->serviceName, | 584 | fc->listen_info->serviceName, |
608 | GNUNET_a2s (fc->listen_info->service_addr, | 585 | GNUNET_a2s (fc->listen_info->service_addr, |
609 | fc->listen_info->service_addr_len), | 586 | fc->listen_info->service_addr_len), |
610 | (unsigned long long) GNUNET_TIME_relative_min (fc->back_off, | 587 | (unsigned long long) GNUNET_TIME_relative_min (fc->back_off, |
611 | rem).rel_value); | 588 | rem).rel_value); |
612 | #endif | 589 | #endif |
613 | rem = GNUNET_TIME_absolute_get_remaining (fc->timeout); | 590 | rem = GNUNET_TIME_absolute_get_remaining (fc->timeout); |
614 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); | 591 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); |
615 | fc->start_task | 592 | fc->start_task |
616 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min (fc->back_off, | 593 | = |
617 | rem), | 594 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_min |
618 | &start_forwarding, | 595 | (fc->back_off, rem), &start_forwarding, |
619 | fc); | 596 | fc); |
620 | } | 597 | } |
621 | else | 598 | else |
622 | { | 599 | { |
623 | if ( (errno != EPIPE) && | 600 | if ((errno != EPIPE) && (errno != ECONNRESET)) |
624 | (errno != ECONNRESET) ) | 601 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
625 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 602 | "Failed to forward data to service: %s\n", |
626 | "Failed to forward data to service: %s\n", | 603 | STRERROR (errno)); |
627 | STRERROR (errno)); | 604 | closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE); |
628 | closeClientAndServiceSockets (fc, | ||
629 | REASON_CLIENT_TO_SERVICE); | ||
630 | } | ||
631 | return; | ||
632 | } | 605 | } |
606 | return; | ||
607 | } | ||
633 | #if DEBUG_SERVICE_MANAGER | 608 | #if DEBUG_SERVICE_MANAGER |
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 609 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
635 | "Forwarded %d bytes to service\n", | 610 | "Forwarded %d bytes to service\n", numberOfBytesSent); |
636 | numberOfBytesSent); | ||
637 | #endif | 611 | #endif |
638 | fc->first_write_done = GNUNET_YES; | 612 | fc->first_write_done = GNUNET_YES; |
639 | if (numberOfBytesSent < fc->client_to_service_bufferDataLength) | 613 | if (numberOfBytesSent < fc->client_to_service_bufferDataLength) |
640 | { | 614 | { |
641 | fc->client_to_service_bufferPos += numberOfBytesSent; | 615 | fc->client_to_service_bufferPos += numberOfBytesSent; |
642 | fc->client_to_service_bufferDataLength -= numberOfBytesSent; | 616 | fc->client_to_service_bufferDataLength -= numberOfBytesSent; |
643 | fc->client_to_service_task = | 617 | fc->client_to_service_task = |
644 | GNUNET_SCHEDULER_add_write_net ( | 618 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
645 | GNUNET_TIME_UNIT_FOREVER_REL, | 619 | fc->armServiceSocket, |
646 | fc->armServiceSocket, | 620 | &forwardToService, fc); |
647 | &forwardToService, fc); | 621 | return; |
648 | return; | 622 | } |
649 | } | ||
650 | fc->client_to_service_task = | 623 | fc->client_to_service_task = |
651 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 624 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
652 | fc->armClientSocket, | 625 | fc->armClientSocket, |
653 | &receiveFromClient, fc); | 626 | &receiveFromClient, fc); |
654 | } | 627 | } |
655 | 628 | ||
656 | 629 | ||
@@ -667,76 +640,73 @@ receiveFromClient (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
667 | 640 | ||
668 | fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK; | 641 | fc->client_to_service_task = GNUNET_SCHEDULER_NO_TASK; |
669 | if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready, | 642 | if (GNUNET_YES != GNUNET_NETWORK_fdset_isset (tc->read_ready, |
670 | fc->armClientSocket)) | 643 | fc->armClientSocket)) |
671 | { | 644 | { |
672 | fc->client_to_service_task = | 645 | fc->client_to_service_task = |
673 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 646 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
674 | fc->armClientSocket, | 647 | fc->armClientSocket, |
675 | &receiveFromClient, fc); | 648 | &receiveFromClient, fc); |
676 | return; | 649 | return; |
677 | } | 650 | } |
678 | fc->client_to_service_bufferPos = fc->client_to_service_buffer; | 651 | fc->client_to_service_bufferPos = fc->client_to_service_buffer; |
679 | fc->client_to_service_bufferDataLength = | 652 | fc->client_to_service_bufferDataLength = |
680 | GNUNET_NETWORK_socket_recv (fc->armClientSocket, | 653 | GNUNET_NETWORK_socket_recv (fc->armClientSocket, |
681 | fc->client_to_service_buffer, | 654 | fc->client_to_service_buffer, BUFFER_SIZE); |
682 | BUFFER_SIZE); | ||
683 | if (fc->client_to_service_bufferDataLength <= 0) | 655 | if (fc->client_to_service_bufferDataLength <= 0) |
656 | { | ||
657 | if (fc->client_to_service_bufferDataLength == 0) | ||
684 | { | 658 | { |
685 | if (fc->client_to_service_bufferDataLength == 0) | ||
686 | { | ||
687 | #if DEBUG_SERVICE_MANAGER | 659 | #if DEBUG_SERVICE_MANAGER |
688 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
689 | "Client closed connection with service `%s'\n", | 661 | "Client closed connection with service `%s'\n", |
690 | fc->listen_info->serviceName); | 662 | fc->listen_info->serviceName); |
691 | #endif | 663 | #endif |
692 | } | 664 | } |
693 | else | 665 | else |
694 | { | 666 | { |
695 | #if DEBUG_SERVICE_MANAGER | 667 | #if DEBUG_SERVICE_MANAGER |
696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
697 | "Error receiving from client: %s\n", | 669 | "Error receiving from client: %s\n", STRERROR (errno)); |
698 | STRERROR (errno)); | ||
699 | #endif | 670 | #endif |
700 | } | ||
701 | closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE); | ||
702 | return; | ||
703 | } | 671 | } |
672 | closeClientAndServiceSockets (fc, REASON_CLIENT_TO_SERVICE); | ||
673 | return; | ||
674 | } | ||
704 | #if DEBUG_SERVICE_MANAGER | 675 | #if DEBUG_SERVICE_MANAGER |
705 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
706 | "Received %d bytes for service\n", | 677 | "Received %d bytes for service\n", |
707 | fc->client_to_service_bufferDataLength); | 678 | fc->client_to_service_bufferDataLength); |
708 | #endif | 679 | #endif |
709 | if (fc->armServiceSocket != NULL) | 680 | if (fc->armServiceSocket != NULL) |
710 | fc->client_to_service_task = | 681 | fc->client_to_service_task = |
711 | GNUNET_SCHEDULER_add_write_net ( | 682 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
712 | GNUNET_TIME_UNIT_FOREVER_REL, | 683 | fc->armServiceSocket, |
713 | fc->armServiceSocket, | 684 | &forwardToService, fc); |
714 | &forwardToService, fc); | ||
715 | else | 685 | else |
716 | /* We have not added any task with fc as a closure, so we're | 686 | /* We have not added any task with fc as a closure, so we're |
717 | * dropping our reference to fc | 687 | * dropping our reference to fc |
718 | */ | 688 | */ |
719 | fc->reference_count -= 1; | 689 | fc->reference_count -= 1; |
720 | } | 690 | } |
721 | 691 | ||
722 | 692 | ||
723 | static void | 693 | static void |
724 | fc_acceptConnection (void *cls, | 694 | fc_acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
725 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
726 | { | 695 | { |
727 | struct ServiceListeningInfo *sli = cls; | 696 | struct ServiceListeningInfo *sli = cls; |
728 | struct ForwardedConnection *fc = sli->fc; | 697 | struct ForwardedConnection *fc = sli->fc; |
729 | 698 | ||
730 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) | 699 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) |
731 | { | 700 | { |
732 | GNUNET_assert (GNUNET_OK == GNUNET_NETWORK_socket_close (sli->listeningSocket)); | 701 | GNUNET_assert (GNUNET_OK == |
733 | closeClientAndServiceSockets (fc, REASON_ERROR); | 702 | GNUNET_NETWORK_socket_close (sli->listeningSocket)); |
734 | GNUNET_free (sli); | 703 | closeClientAndServiceSockets (fc, REASON_ERROR); |
735 | return; | 704 | GNUNET_free (sli); |
736 | } | 705 | return; |
706 | } | ||
737 | #if DEBUG_SERVICE_MANAGER | 707 | #if DEBUG_SERVICE_MANAGER |
738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
739 | "Connected to service, now starting forwarding\n"); | 709 | "Connected to service, now starting forwarding\n"); |
740 | #endif | 710 | #endif |
741 | fc->armServiceSocket = sli->listeningSocket; | 711 | fc->armServiceSocket = sli->listeningSocket; |
742 | GNUNET_free (fc->listen_info->service_addr); | 712 | GNUNET_free (fc->listen_info->service_addr); |
@@ -749,72 +719,70 @@ fc_acceptConnection (void *cls, | |||
749 | */ | 719 | */ |
750 | fc->reference_count -= 1; | 720 | fc->reference_count -= 1; |
751 | if (fc->client_to_service_task == GNUNET_SCHEDULER_NO_TASK) | 721 | if (fc->client_to_service_task == GNUNET_SCHEDULER_NO_TASK) |
752 | { | 722 | { |
753 | if (fc->client_to_service_bufferDataLength == 0) | 723 | if (fc->client_to_service_bufferDataLength == 0) |
754 | fc->client_to_service_task = | 724 | fc->client_to_service_task = |
755 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 725 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
756 | fc->armClientSocket, | 726 | fc->armClientSocket, |
757 | &receiveFromClient, fc); | 727 | &receiveFromClient, fc); |
758 | else | 728 | else |
759 | fc->client_to_service_task = | 729 | fc->client_to_service_task = |
760 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 730 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
761 | fc->armServiceSocket, | 731 | fc->armServiceSocket, |
762 | &forwardToService, fc); | 732 | &forwardToService, fc); |
763 | fc->reference_count += 1; | 733 | fc->reference_count += 1; |
764 | } | 734 | } |
765 | if (fc->service_to_client_task == GNUNET_SCHEDULER_NO_TASK) | 735 | if (fc->service_to_client_task == GNUNET_SCHEDULER_NO_TASK) |
766 | { | 736 | { |
767 | if (fc->service_to_client_bufferDataLength == 0) | 737 | if (fc->service_to_client_bufferDataLength == 0) |
768 | fc->service_to_client_task = | 738 | fc->service_to_client_task = |
769 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 739 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
770 | fc->armServiceSocket, | 740 | fc->armServiceSocket, |
771 | &receiveFromService, fc); | 741 | &receiveFromService, fc); |
772 | else | 742 | else |
773 | fc->service_to_client_task = | 743 | fc->service_to_client_task = |
774 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 744 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
775 | fc->armClientSocket, | 745 | fc->armClientSocket, |
776 | &forwardToClient, fc); | 746 | &forwardToClient, fc); |
777 | fc->reference_count += 1; | 747 | fc->reference_count += 1; |
778 | } | 748 | } |
779 | GNUNET_free (sli); | 749 | GNUNET_free (sli); |
780 | } | 750 | } |
781 | 751 | ||
782 | 752 | ||
783 | static struct ServiceListeningInfo * | 753 | static struct ServiceListeningInfo * |
784 | service_try_to_connect (const struct sockaddr *addr, | 754 | service_try_to_connect (const struct sockaddr *addr, |
785 | int pf, | 755 | int pf, |
786 | socklen_t addrlen, | 756 | socklen_t addrlen, struct ForwardedConnection *fc) |
787 | struct ForwardedConnection *fc) | ||
788 | { | 757 | { |
789 | struct GNUNET_NETWORK_Handle *sock; | 758 | struct GNUNET_NETWORK_Handle *sock; |
790 | struct ServiceListeningInfo *serviceListeningInfo; | 759 | struct ServiceListeningInfo *serviceListeningInfo; |
791 | 760 | ||
792 | sock = GNUNET_NETWORK_socket_create (pf, SOCK_STREAM, 0); | 761 | sock = GNUNET_NETWORK_socket_create (pf, SOCK_STREAM, 0); |
793 | if (sock == NULL) | 762 | if (sock == NULL) |
794 | { | 763 | { |
795 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); | 764 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); |
796 | return NULL; | 765 | return NULL; |
797 | } | 766 | } |
798 | if ( (GNUNET_SYSERR == GNUNET_NETWORK_socket_connect (sock, addr, addrlen)) && | 767 | if ((GNUNET_SYSERR == GNUNET_NETWORK_socket_connect (sock, addr, addrlen)) && |
799 | (errno != EINPROGRESS) ) | 768 | (errno != EINPROGRESS)) |
800 | { | 769 | { |
801 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect"); | 770 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "connect"); |
802 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 771 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
803 | return NULL; | 772 | return NULL; |
804 | } | 773 | } |
805 | serviceListeningInfo = GNUNET_malloc (sizeof (struct ServiceListeningInfo)); | 774 | serviceListeningInfo = GNUNET_malloc (sizeof (struct ServiceListeningInfo)); |
806 | serviceListeningInfo->serviceName = NULL; | 775 | serviceListeningInfo->serviceName = NULL; |
807 | serviceListeningInfo->service_addr = GNUNET_malloc (addrlen); | 776 | serviceListeningInfo->service_addr = GNUNET_malloc (addrlen); |
808 | memcpy (serviceListeningInfo->service_addr, | 777 | memcpy (serviceListeningInfo->service_addr, addr, addrlen); |
809 | addr, | ||
810 | addrlen); | ||
811 | serviceListeningInfo->service_addr_len = addrlen; | 778 | serviceListeningInfo->service_addr_len = addrlen; |
812 | serviceListeningInfo->listeningSocket = sock; | 779 | serviceListeningInfo->listeningSocket = sock; |
813 | serviceListeningInfo->fc = fc; | 780 | serviceListeningInfo->fc = fc; |
814 | serviceListeningInfo->acceptTask = | 781 | serviceListeningInfo->acceptTask = |
815 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 782 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
816 | serviceListeningInfo->listeningSocket, | 783 | serviceListeningInfo->listeningSocket, |
817 | &fc_acceptConnection, serviceListeningInfo); | 784 | &fc_acceptConnection, |
785 | serviceListeningInfo); | ||
818 | return serviceListeningInfo; | 786 | return serviceListeningInfo; |
819 | } | 787 | } |
820 | 788 | ||
@@ -823,8 +791,7 @@ service_try_to_connect (const struct sockaddr *addr, | |||
823 | * | 791 | * |
824 | */ | 792 | */ |
825 | static void | 793 | static void |
826 | start_forwarding (void *cls, | 794 | start_forwarding (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
827 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
828 | { | 795 | { |
829 | struct ForwardedConnection *fc = cls; | 796 | struct ForwardedConnection *fc = cls; |
830 | struct ServiceListeningInfo *sc; | 797 | struct ServiceListeningInfo *sc; |
@@ -835,91 +802,80 @@ start_forwarding (void *cls, | |||
835 | char listen_address[INET6_ADDRSTRLEN]; | 802 | char listen_address[INET6_ADDRSTRLEN]; |
836 | 803 | ||
837 | fc->start_task = GNUNET_SCHEDULER_NO_TASK; | 804 | fc->start_task = GNUNET_SCHEDULER_NO_TASK; |
838 | if ( (NULL != tc) && | 805 | if ((NULL != tc) && (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) |
839 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) ) | 806 | { |
840 | { | 807 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
841 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 808 | _("Unable to forward to service `%s': shutdown\n"), |
842 | _("Unable to forward to service `%s': shutdown\n"), | 809 | fc->listen_info->serviceName); |
843 | fc->listen_info->serviceName); | 810 | closeClientAndServiceSockets (fc, REASON_ERROR); |
844 | closeClientAndServiceSockets (fc, REASON_ERROR); | 811 | return; |
845 | return; | 812 | } |
846 | } | ||
847 | if (0 == GNUNET_TIME_absolute_get_remaining (fc->timeout).rel_value) | 813 | if (0 == GNUNET_TIME_absolute_get_remaining (fc->timeout).rel_value) |
848 | { | 814 | { |
849 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 815 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
850 | _("Unable to forward to service `%s': timeout before connect\n"), | 816 | _ |
851 | fc->listen_info->serviceName); | 817 | ("Unable to forward to service `%s': timeout before connect\n"), |
852 | closeClientAndServiceSockets (fc, REASON_ERROR); | 818 | fc->listen_info->serviceName); |
853 | return; | 819 | closeClientAndServiceSockets (fc, REASON_ERROR); |
854 | } | 820 | return; |
821 | } | ||
855 | switch (fc->listen_info->service_addr->sa_family) | 822 | switch (fc->listen_info->service_addr->sa_family) |
823 | { | ||
824 | case AF_UNSPEC: | ||
825 | GNUNET_break (0); | ||
826 | closeClientAndServiceSockets (fc, REASON_ERROR); | ||
827 | return; | ||
828 | case AF_INET: | ||
829 | v4 = (const struct sockaddr_in *) fc->listen_info->service_addr; | ||
830 | inet_ntop (fc->listen_info->service_addr->sa_family, | ||
831 | (const void *) &v4->sin_addr, listen_address, INET_ADDRSTRLEN); | ||
832 | if (0 == strncmp (listen_address, "0.0.0.0", 7)) | ||
856 | { | 833 | { |
857 | case AF_UNSPEC: | 834 | /* connect to [::1] and 127.0.0.1 instead of [::] and 0.0.0.0 */ |
858 | GNUNET_break (0); | 835 | memset (&target_ipv4, 0, sizeof (target_ipv4)); |
859 | closeClientAndServiceSockets (fc, REASON_ERROR); | 836 | GNUNET_assert (1 == |
860 | return; | 837 | inet_pton (AF_INET, "127.0.0.1", &target_ipv4.sin_addr)); |
861 | case AF_INET: | 838 | target_ipv4.sin_family = AF_INET; |
862 | v4 = (const struct sockaddr_in *) fc->listen_info->service_addr; | 839 | target_ipv4.sin_port = v4->sin_port; |
863 | inet_ntop (fc->listen_info->service_addr->sa_family, | 840 | v4 = &target_ipv4; |
864 | (const void *) &v4->sin_addr, | 841 | } |
865 | listen_address, | 842 | sc = service_try_to_connect ((const struct sockaddr *) v4, |
866 | INET_ADDRSTRLEN); | 843 | PF_INET, sizeof (struct sockaddr_in), fc); |
867 | if (0 == strncmp (listen_address, "0.0.0.0", 7)) | 844 | break; |
868 | { | 845 | case AF_INET6: |
869 | /* connect to [::1] and 127.0.0.1 instead of [::] and 0.0.0.0 */ | 846 | v6 = (struct sockaddr_in6 *) fc->listen_info->service_addr; |
870 | memset (&target_ipv4, 0, sizeof (target_ipv4)); | 847 | inet_ntop (fc->listen_info->service_addr->sa_family, |
871 | GNUNET_assert (1 == | 848 | (const void *) &v6->sin6_addr, listen_address, INET6_ADDRSTRLEN); |
872 | inet_pton (AF_INET, | 849 | if ((strncmp (listen_address, "[::]:", 5) == 0) || |
873 | "127.0.0.1", | 850 | (strncmp (listen_address, "::", 2) == 0)) |
874 | &target_ipv4.sin_addr)); | ||
875 | target_ipv4.sin_family = AF_INET; | ||
876 | target_ipv4.sin_port = v4->sin_port; | ||
877 | v4 = &target_ipv4; | ||
878 | } | ||
879 | sc = service_try_to_connect ((const struct sockaddr*) v4, | ||
880 | PF_INET, | ||
881 | sizeof (struct sockaddr_in), | ||
882 | fc); | ||
883 | break; | ||
884 | case AF_INET6: | ||
885 | v6 = (struct sockaddr_in6 *)fc->listen_info->service_addr; | ||
886 | inet_ntop (fc->listen_info->service_addr->sa_family, | ||
887 | (const void *) &v6->sin6_addr, | ||
888 | listen_address, | ||
889 | INET6_ADDRSTRLEN); | ||
890 | if ( (strncmp (listen_address, "[::]:", 5) == 0) || (strncmp (listen_address, "::", 2) == 0) ) | ||
891 | { | ||
892 | memset (&target_ipv6, 0, sizeof (target_ipv6)); | ||
893 | target_ipv6.sin6_addr = in6addr_loopback; | ||
894 | target_ipv6.sin6_family = AF_INET6; | ||
895 | target_ipv6.sin6_port = v6->sin6_port; | ||
896 | v6 = &target_ipv6; | ||
897 | } | ||
898 | sc = service_try_to_connect ((const struct sockaddr*) v6, | ||
899 | PF_INET6, | ||
900 | sizeof (struct sockaddr_in6), | ||
901 | fc); | ||
902 | break; | ||
903 | case AF_UNIX: | ||
904 | sc = service_try_to_connect (fc->listen_info->service_addr, | ||
905 | PF_UNIX, | ||
906 | fc->listen_info->service_addr_len, | ||
907 | fc); | ||
908 | break; | ||
909 | default: | ||
910 | GNUNET_break (0); | ||
911 | closeClientAndServiceSockets (fc, REASON_ERROR); | ||
912 | return; | ||
913 | } | ||
914 | if (NULL == sc) | ||
915 | { | 851 | { |
916 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 852 | memset (&target_ipv6, 0, sizeof (target_ipv6)); |
917 | _ ("Unable to start service `%s': %s\n"), | 853 | target_ipv6.sin6_addr = in6addr_loopback; |
918 | fc->listen_info->serviceName, | 854 | target_ipv6.sin6_family = AF_INET6; |
919 | STRERROR (errno)); | 855 | target_ipv6.sin6_port = v6->sin6_port; |
920 | closeClientAndServiceSockets (fc, REASON_ERROR); | 856 | v6 = &target_ipv6; |
921 | return; | ||
922 | } | 857 | } |
858 | sc = service_try_to_connect ((const struct sockaddr *) v6, | ||
859 | PF_INET6, sizeof (struct sockaddr_in6), fc); | ||
860 | break; | ||
861 | case AF_UNIX: | ||
862 | sc = service_try_to_connect (fc->listen_info->service_addr, | ||
863 | PF_UNIX, | ||
864 | fc->listen_info->service_addr_len, fc); | ||
865 | break; | ||
866 | default: | ||
867 | GNUNET_break (0); | ||
868 | closeClientAndServiceSockets (fc, REASON_ERROR); | ||
869 | return; | ||
870 | } | ||
871 | if (NULL == sc) | ||
872 | { | ||
873 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
874 | _("Unable to start service `%s': %s\n"), | ||
875 | fc->listen_info->serviceName, STRERROR (errno)); | ||
876 | closeClientAndServiceSockets (fc, REASON_ERROR); | ||
877 | return; | ||
878 | } | ||
923 | } | 879 | } |
924 | 880 | ||
925 | 881 | ||
@@ -932,27 +888,25 @@ stop_listening (const char *serviceName) | |||
932 | struct ServiceListeningInfo *pos; | 888 | struct ServiceListeningInfo *pos; |
933 | struct ServiceListeningInfo *next; | 889 | struct ServiceListeningInfo *next; |
934 | int ret; | 890 | int ret; |
935 | 891 | ||
936 | ret = GNUNET_NO; | 892 | ret = GNUNET_NO; |
937 | next = serviceListeningInfoList_head; | 893 | next = serviceListeningInfoList_head; |
938 | while (NULL != (pos = next)) | 894 | while (NULL != (pos = next)) |
939 | { | 895 | { |
940 | next = pos->next; | 896 | next = pos->next; |
941 | if ( (serviceName != NULL) && | 897 | if ((serviceName != NULL) && (strcmp (pos->serviceName, serviceName) != 0)) |
942 | (strcmp (pos->serviceName, serviceName) != 0) ) | 898 | continue; |
943 | continue; | 899 | if (pos->acceptTask != GNUNET_SCHEDULER_NO_TASK) |
944 | if (pos->acceptTask != GNUNET_SCHEDULER_NO_TASK) | 900 | GNUNET_SCHEDULER_cancel (pos->acceptTask); |
945 | GNUNET_SCHEDULER_cancel (pos->acceptTask); | 901 | GNUNET_break (GNUNET_OK == |
946 | GNUNET_break (GNUNET_OK == | 902 | GNUNET_NETWORK_socket_close (pos->listeningSocket)); |
947 | GNUNET_NETWORK_socket_close (pos->listeningSocket)); | 903 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, |
948 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, | 904 | serviceListeningInfoList_tail, pos); |
949 | serviceListeningInfoList_tail, | 905 | GNUNET_free (pos->serviceName); |
950 | pos); | 906 | GNUNET_free (pos->service_addr); |
951 | GNUNET_free (pos->serviceName); | 907 | GNUNET_free (pos); |
952 | GNUNET_free (pos->service_addr); | 908 | ret = GNUNET_OK; |
953 | GNUNET_free (pos); | 909 | } |
954 | ret = GNUNET_OK; | ||
955 | } | ||
956 | return ret; | 910 | return ret; |
957 | } | 911 | } |
958 | 912 | ||
@@ -978,46 +932,44 @@ accept_and_forward (struct ServiceListeningInfo *serviceListeningInfo) | |||
978 | fc->service_to_client_bufferPos = fc->service_to_client_buffer; | 932 | fc->service_to_client_bufferPos = fc->service_to_client_buffer; |
979 | fc->client_to_service_bufferPos = fc->client_to_service_buffer; | 933 | fc->client_to_service_bufferPos = fc->client_to_service_buffer; |
980 | fc->client_addr_len = sizeof (fc->client_addr); | 934 | fc->client_addr_len = sizeof (fc->client_addr); |
981 | fc->armClientSocket = GNUNET_NETWORK_socket_accept (serviceListeningInfo->listeningSocket, | 935 | fc->armClientSocket = |
982 | (struct sockaddr*) fc->client_addr, | 936 | GNUNET_NETWORK_socket_accept (serviceListeningInfo->listeningSocket, |
983 | &fc->client_addr_len); | 937 | (struct sockaddr *) fc->client_addr, |
938 | &fc->client_addr_len); | ||
984 | if (NULL == fc->armClientSocket) | 939 | if (NULL == fc->armClientSocket) |
985 | { | 940 | { |
986 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 941 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
987 | _("Unable to accept connection for service `%s': %s\n"), | 942 | _("Unable to accept connection for service `%s': %s\n"), |
988 | serviceListeningInfo->serviceName, | 943 | serviceListeningInfo->serviceName, STRERROR (errno)); |
989 | STRERROR (errno)); | 944 | GNUNET_free (fc); |
990 | GNUNET_free (fc); | 945 | GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head, |
991 | GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head, | 946 | serviceListeningInfoList_tail, |
992 | serviceListeningInfoList_tail, | 947 | serviceListeningInfo); |
993 | serviceListeningInfo); | 948 | serviceListeningInfo->acceptTask = |
994 | serviceListeningInfo->acceptTask = | 949 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
995 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 950 | serviceListeningInfo->listeningSocket, |
996 | serviceListeningInfo->listeningSocket, | 951 | &acceptConnection, serviceListeningInfo); |
997 | &acceptConnection, | 952 | return; |
998 | serviceListeningInfo); | 953 | } |
999 | return; | ||
1000 | } | ||
1001 | GNUNET_break (GNUNET_OK == | 954 | GNUNET_break (GNUNET_OK == |
1002 | GNUNET_NETWORK_socket_close (serviceListeningInfo->listeningSocket)); | 955 | GNUNET_NETWORK_socket_close |
956 | (serviceListeningInfo->listeningSocket)); | ||
1003 | start_service (NULL, serviceListeningInfo->serviceName, NULL); | 957 | start_service (NULL, serviceListeningInfo->serviceName, NULL); |
1004 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 958 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1005 | _("Service `%s' started\n"), | 959 | _("Service `%s' started\n"), fc->listen_info->serviceName); |
1006 | fc->listen_info->serviceName); | 960 | fc->timeout = |
1007 | fc->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_SERVICE_TIMEOUT); | 961 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_SERVICE_TIMEOUT); |
1008 | fc->back_off = GNUNET_TIME_UNIT_MILLISECONDS; | 962 | fc->back_off = GNUNET_TIME_UNIT_MILLISECONDS; |
1009 | fc->client_to_service_task = | 963 | fc->client_to_service_task = |
1010 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 964 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1011 | fc->armClientSocket, | 965 | fc->armClientSocket, |
1012 | &receiveFromClient, fc); | 966 | &receiveFromClient, fc); |
1013 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); | 967 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == fc->start_task); |
1014 | /* We're creating another chain of tasks for this fc that | 968 | /* We're creating another chain of tasks for this fc that |
1015 | * will have its own reference to it. | 969 | * will have its own reference to it. |
1016 | */ | 970 | */ |
1017 | fc->reference_count += 1; | 971 | fc->reference_count += 1; |
1018 | fc->start_task | 972 | fc->start_task = GNUNET_SCHEDULER_add_now (&start_forwarding, fc); |
1019 | = GNUNET_SCHEDULER_add_now (&start_forwarding, | ||
1020 | fc); | ||
1021 | } | 973 | } |
1022 | 974 | ||
1023 | 975 | ||
@@ -1042,59 +994,54 @@ acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1042 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | 994 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) |
1043 | return; | 995 | return; |
1044 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, | 996 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, |
1045 | serviceListeningInfoList_tail, | 997 | serviceListeningInfoList_tail, sli); |
1046 | sli); | ||
1047 | #ifndef MINGW | 998 | #ifndef MINGW |
1048 | use_lsocks = GNUNET_NO; | 999 | use_lsocks = GNUNET_NO; |
1049 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, | 1000 | if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, |
1050 | sli->serviceName, | 1001 | sli->serviceName, |
1051 | "DISABLE_SOCKET_FORWARDING")) | 1002 | "DISABLE_SOCKET_FORWARDING")) |
1052 | use_lsocks = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1003 | use_lsocks = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1053 | sli->serviceName, | 1004 | sli->serviceName, |
1054 | "DISABLE_SOCKET_FORWARDING"); | 1005 | "DISABLE_SOCKET_FORWARDING"); |
1055 | #else | 1006 | #else |
1056 | use_lsocks = GNUNET_YES; | 1007 | use_lsocks = GNUNET_YES; |
1057 | #endif | 1008 | #endif |
1058 | if (GNUNET_NO != use_lsocks) | 1009 | if (GNUNET_NO != use_lsocks) |
1059 | { | 1010 | { |
1060 | accept_and_forward (sli); | 1011 | accept_and_forward (sli); |
1061 | return; | 1012 | return; |
1062 | } | 1013 | } |
1063 | lsocks = NULL; | 1014 | lsocks = NULL; |
1064 | ls = 0; | 1015 | ls = 0; |
1065 | next = serviceListeningInfoList_head; | 1016 | next = serviceListeningInfoList_head; |
1066 | while (NULL != (pos = next)) | 1017 | while (NULL != (pos = next)) |
1018 | { | ||
1019 | next = pos->next; | ||
1020 | if (0 == strcmp (pos->serviceName, sli->serviceName)) | ||
1067 | { | 1021 | { |
1068 | next = pos->next; | 1022 | GNUNET_array_append (lsocks, ls, |
1069 | if (0 == strcmp (pos->serviceName, | 1023 | GNUNET_NETWORK_get_fd (pos->listeningSocket)); |
1070 | sli->serviceName)) | 1024 | GNUNET_free (pos->listeningSocket); /* deliberately no closing! */ |
1071 | { | 1025 | GNUNET_free (pos->service_addr); |
1072 | GNUNET_array_append (lsocks, ls, | 1026 | GNUNET_free (pos->serviceName); |
1073 | GNUNET_NETWORK_get_fd (pos->listeningSocket)); | 1027 | GNUNET_SCHEDULER_cancel (pos->acceptTask); |
1074 | GNUNET_free (pos->listeningSocket); /* deliberately no closing! */ | 1028 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, |
1075 | GNUNET_free (pos->service_addr); | 1029 | serviceListeningInfoList_tail, pos); |
1076 | GNUNET_free (pos->serviceName); | 1030 | GNUNET_free (pos); |
1077 | GNUNET_SCHEDULER_cancel (pos->acceptTask); | ||
1078 | GNUNET_CONTAINER_DLL_remove (serviceListeningInfoList_head, | ||
1079 | serviceListeningInfoList_tail, | ||
1080 | pos); | ||
1081 | GNUNET_free (pos); | ||
1082 | } | ||
1083 | } | 1031 | } |
1084 | GNUNET_array_append (lsocks, ls, | 1032 | } |
1085 | GNUNET_NETWORK_get_fd (sli->listeningSocket)); | 1033 | GNUNET_array_append (lsocks, ls, |
1086 | GNUNET_free (sli->listeningSocket); /* deliberately no closing! */ | 1034 | GNUNET_NETWORK_get_fd (sli->listeningSocket)); |
1035 | GNUNET_free (sli->listeningSocket); /* deliberately no closing! */ | ||
1087 | GNUNET_free (sli->service_addr); | 1036 | GNUNET_free (sli->service_addr); |
1088 | GNUNET_array_append (lsocks, ls, -1); | 1037 | GNUNET_array_append (lsocks, ls, -1); |
1089 | start_service (NULL, | 1038 | start_service (NULL, sli->serviceName, lsocks); |
1090 | sli->serviceName, | ||
1091 | lsocks); | ||
1092 | ls = 0; | 1039 | ls = 0; |
1093 | while (lsocks[ls] != -1) | 1040 | while (lsocks[ls] != -1) |
1094 | GNUNET_break (0 == close (lsocks[ls++])); | 1041 | GNUNET_break (0 == close (lsocks[ls++])); |
1095 | GNUNET_array_grow (lsocks, ls, 0); | 1042 | GNUNET_array_grow (lsocks, ls, 0); |
1096 | GNUNET_free (sli->serviceName); | 1043 | GNUNET_free (sli->serviceName); |
1097 | GNUNET_free (sli); | 1044 | GNUNET_free (sli); |
1098 | } | 1045 | } |
1099 | 1046 | ||
1100 | 1047 | ||
@@ -1107,89 +1054,84 @@ acceptConnection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1107 | * @param serviceName the name of the service in question | 1054 | * @param serviceName the name of the service in question |
1108 | */ | 1055 | */ |
1109 | static void | 1056 | static void |
1110 | createListeningSocket(struct sockaddr *sa, socklen_t addr_len, | 1057 | createListeningSocket (struct sockaddr *sa, socklen_t addr_len, |
1111 | const char *serviceName) | 1058 | const char *serviceName) |
1112 | { | 1059 | { |
1113 | const static int on = 1; | 1060 | const static int on = 1; |
1114 | struct GNUNET_NETWORK_Handle *sock; | 1061 | struct GNUNET_NETWORK_Handle *sock; |
1115 | struct ServiceListeningInfo *serviceListeningInfo; | 1062 | struct ServiceListeningInfo *serviceListeningInfo; |
1116 | 1063 | ||
1117 | switch (sa->sa_family) | 1064 | switch (sa->sa_family) |
1118 | { | 1065 | { |
1119 | case AF_INET: | 1066 | case AF_INET: |
1120 | sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0); | 1067 | sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0); |
1121 | break; | 1068 | break; |
1122 | case AF_INET6: | 1069 | case AF_INET6: |
1123 | sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | 1070 | sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); |
1124 | break; | 1071 | break; |
1125 | case AF_UNIX: | 1072 | case AF_UNIX: |
1126 | if (strcmp(GNUNET_a2s (sa, addr_len), "@") == 0) /* Do not bind to blank UNIX path! */ | 1073 | if (strcmp (GNUNET_a2s (sa, addr_len), "@") == 0) /* Do not bind to blank UNIX path! */ |
1127 | return; | ||
1128 | sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); | ||
1129 | break; | ||
1130 | default: | ||
1131 | GNUNET_break (0); | ||
1132 | sock = NULL; | ||
1133 | errno = EAFNOSUPPORT; | ||
1134 | break; | ||
1135 | } | ||
1136 | if (NULL == sock) | ||
1137 | { | ||
1138 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1139 | _("Unable to create socket for service `%s': %s\n"), | ||
1140 | serviceName, | ||
1141 | STRERROR (errno)); | ||
1142 | GNUNET_free (sa); | ||
1143 | return; | 1074 | return; |
1144 | } | 1075 | sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0); |
1076 | break; | ||
1077 | default: | ||
1078 | GNUNET_break (0); | ||
1079 | sock = NULL; | ||
1080 | errno = EAFNOSUPPORT; | ||
1081 | break; | ||
1082 | } | ||
1083 | if (NULL == sock) | ||
1084 | { | ||
1085 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1086 | _("Unable to create socket for service `%s': %s\n"), | ||
1087 | serviceName, STRERROR (errno)); | ||
1088 | GNUNET_free (sa); | ||
1089 | return; | ||
1090 | } | ||
1145 | if (GNUNET_NETWORK_socket_setsockopt | 1091 | if (GNUNET_NETWORK_socket_setsockopt |
1146 | (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 1092 | (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
1147 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1093 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1148 | "setsockopt"); | 1094 | "setsockopt"); |
1149 | #ifdef IPV6_V6ONLY | 1095 | #ifdef IPV6_V6ONLY |
1150 | if ( (sa->sa_family == AF_INET6) && | 1096 | if ((sa->sa_family == AF_INET6) && |
1151 | (GNUNET_NETWORK_socket_setsockopt | 1097 | (GNUNET_NETWORK_socket_setsockopt |
1152 | (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK)) | 1098 | (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK)) |
1153 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1099 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
1154 | "setsockopt"); | 1100 | "setsockopt"); |
1155 | #endif | 1101 | #endif |
1156 | 1102 | ||
1157 | if (GNUNET_NETWORK_socket_bind | 1103 | if (GNUNET_NETWORK_socket_bind |
1158 | (sock, (const struct sockaddr *) sa, addr_len) != GNUNET_OK) | 1104 | (sock, (const struct sockaddr *) sa, addr_len) != GNUNET_OK) |
1159 | { | 1105 | { |
1160 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1106 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1161 | _("Unable to bind listening socket for service `%s' to address `%s': %s\n"), | 1107 | _ |
1162 | serviceName, | 1108 | ("Unable to bind listening socket for service `%s' to address `%s': %s\n"), |
1163 | GNUNET_a2s (sa, addr_len), | 1109 | serviceName, GNUNET_a2s (sa, addr_len), STRERROR (errno)); |
1164 | STRERROR (errno)); | 1110 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
1165 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 1111 | GNUNET_free (sa); |
1166 | GNUNET_free (sa); | 1112 | return; |
1167 | return; | 1113 | } |
1168 | } | ||
1169 | if (GNUNET_NETWORK_socket_listen (sock, 5) != GNUNET_OK) | 1114 | if (GNUNET_NETWORK_socket_listen (sock, 5) != GNUNET_OK) |
1170 | { | 1115 | { |
1171 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 1116 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); |
1172 | "listen"); | 1117 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
1173 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 1118 | GNUNET_free (sa); |
1174 | GNUNET_free (sa); | 1119 | return; |
1175 | return; | 1120 | } |
1176 | } | ||
1177 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1121 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1178 | _("ARM now monitors connections to service `%s' at `%s'\n"), | 1122 | _("ARM now monitors connections to service `%s' at `%s'\n"), |
1179 | serviceName, | 1123 | serviceName, GNUNET_a2s (sa, addr_len)); |
1180 | GNUNET_a2s (sa, addr_len)); | ||
1181 | serviceListeningInfo = GNUNET_malloc (sizeof (struct ServiceListeningInfo)); | 1124 | serviceListeningInfo = GNUNET_malloc (sizeof (struct ServiceListeningInfo)); |
1182 | serviceListeningInfo->serviceName = GNUNET_strdup (serviceName); | 1125 | serviceListeningInfo->serviceName = GNUNET_strdup (serviceName); |
1183 | serviceListeningInfo->service_addr = sa; | 1126 | serviceListeningInfo->service_addr = sa; |
1184 | serviceListeningInfo->service_addr_len = addr_len; | 1127 | serviceListeningInfo->service_addr_len = addr_len; |
1185 | serviceListeningInfo->listeningSocket = sock; | 1128 | serviceListeningInfo->listeningSocket = sock; |
1186 | serviceListeningInfo->acceptTask = | 1129 | serviceListeningInfo->acceptTask = |
1187 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock, | 1130 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock, |
1188 | &acceptConnection, | 1131 | &acceptConnection, serviceListeningInfo); |
1189 | serviceListeningInfo); | ||
1190 | GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head, | 1132 | GNUNET_CONTAINER_DLL_insert (serviceListeningInfoList_head, |
1191 | serviceListeningInfoList_tail, | 1133 | serviceListeningInfoList_tail, |
1192 | serviceListeningInfo); | 1134 | serviceListeningInfo); |
1193 | } | 1135 | } |
1194 | 1136 | ||
1195 | 1137 | ||
@@ -1204,22 +1146,20 @@ createListeningSocket(struct sockaddr *sa, socklen_t addr_len, | |||
1204 | */ | 1146 | */ |
1205 | static void | 1147 | static void |
1206 | checkPortNumberCB (void *cls, | 1148 | checkPortNumberCB (void *cls, |
1207 | const char *section, | 1149 | const char *section, const char *option, const char *value) |
1208 | const char *option, | ||
1209 | const char *value) | ||
1210 | { | 1150 | { |
1211 | struct sockaddr **addrs; | 1151 | struct sockaddr **addrs; |
1212 | socklen_t *addr_lens; | 1152 | socklen_t *addr_lens; |
1213 | int ret; | 1153 | int ret; |
1214 | unsigned int i; | 1154 | unsigned int i; |
1215 | 1155 | ||
1216 | if ( (strcasecmp (section, "arm") == 0) || | 1156 | if ((strcasecmp (section, "arm") == 0) || |
1217 | (strcasecmp (option, "AUTOSTART") != 0) || | 1157 | (strcasecmp (option, "AUTOSTART") != 0) || |
1218 | (strcasecmp (value, "YES") != 0) || | 1158 | (strcasecmp (value, "YES") != 0) || |
1219 | (isInDefaultList (section) == GNUNET_YES) ) | 1159 | (isInDefaultList (section) == GNUNET_YES)) |
1220 | return; | 1160 | return; |
1221 | if (0 >= (ret = GNUNET_SERVICE_get_server_addresses (section, cfg, &addrs, | 1161 | if (0 >= (ret = GNUNET_SERVICE_get_server_addresses (section, cfg, &addrs, |
1222 | &addr_lens))) | 1162 | &addr_lens))) |
1223 | return; | 1163 | return; |
1224 | /* this will free (or capture) addrs[i] */ | 1164 | /* this will free (or capture) addrs[i] */ |
1225 | for (i = 0; i < ret; i++) | 1165 | for (i = 0; i < ret; i++) |
@@ -1235,8 +1175,7 @@ checkPortNumberCB (void *cls, | |||
1235 | * @param configurationHandle configuration to use to get services | 1175 | * @param configurationHandle configuration to use to get services |
1236 | */ | 1176 | */ |
1237 | void | 1177 | void |
1238 | prepareServices (const struct GNUNET_CONFIGURATION_Handle | 1178 | prepareServices (const struct GNUNET_CONFIGURATION_Handle *configurationHandle) |
1239 | *configurationHandle) | ||
1240 | { | 1179 | { |
1241 | char *defaultServicesString; | 1180 | char *defaultServicesString; |
1242 | 1181 | ||
@@ -1244,13 +1183,13 @@ prepareServices (const struct GNUNET_CONFIGURATION_Handle | |||
1244 | /* Split the default services into a list */ | 1183 | /* Split the default services into a list */ |
1245 | if (GNUNET_OK == | 1184 | if (GNUNET_OK == |
1246 | GNUNET_CONFIGURATION_get_value_string (cfg, "arm", "DEFAULTSERVICES", | 1185 | GNUNET_CONFIGURATION_get_value_string (cfg, "arm", "DEFAULTSERVICES", |
1247 | &defaultServicesString)) | 1186 | &defaultServicesString)) |
1248 | { | 1187 | { |
1249 | addDefaultServicesToList (defaultServicesString); | 1188 | addDefaultServicesToList (defaultServicesString); |
1250 | GNUNET_free (defaultServicesString); | 1189 | GNUNET_free (defaultServicesString); |
1251 | } | 1190 | } |
1252 | /* Spot the services from the configuration and create a listening | 1191 | /* Spot the services from the configuration and create a listening |
1253 | socket for each */ | 1192 | * socket for each */ |
1254 | GNUNET_CONFIGURATION_iterate (cfg, &checkPortNumberCB, NULL); | 1193 | GNUNET_CONFIGURATION_iterate (cfg, &checkPortNumberCB, NULL); |
1255 | } | 1194 | } |
1256 | 1195 | ||
diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c index 4dae8ffb4..0a0e1de5a 100644 --- a/src/arm/mockup-service.c +++ b/src/arm/mockup-service.c | |||
@@ -36,21 +36,20 @@ transmit_shutdown_ack (void *cls, size_t size, void *buf) | |||
36 | struct GNUNET_MessageHeader *msg; | 36 | struct GNUNET_MessageHeader *msg; |
37 | 37 | ||
38 | if (size < sizeof (struct GNUNET_MessageHeader)) | 38 | if (size < sizeof (struct GNUNET_MessageHeader)) |
39 | { | 39 | { |
40 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 40 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
41 | _("Failed to transmit shutdown ACK.\n")); | 41 | _("Failed to transmit shutdown ACK.\n")); |
42 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 42 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
43 | return 0; /* client disconnected */ | 43 | return 0; /* client disconnected */ |
44 | } | 44 | } |
45 | 45 | ||
46 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 46 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transmitting shutdown ACK.\n")); |
47 | _("Transmitting shutdown ACK.\n")); | ||
48 | 47 | ||
49 | msg = (struct GNUNET_MessageHeader *) buf; | 48 | msg = (struct GNUNET_MessageHeader *) buf; |
50 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK); | 49 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK); |
51 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 50 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
52 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 51 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
53 | GNUNET_SERVER_client_drop(client); | 52 | GNUNET_SERVER_client_drop (client); |
54 | return sizeof (struct GNUNET_MessageHeader); | 53 | return sizeof (struct GNUNET_MessageHeader); |
55 | } | 54 | } |
56 | 55 | ||
@@ -66,12 +65,12 @@ handle_shutdown (void *cls, | |||
66 | struct GNUNET_SERVER_Client *client, | 65 | struct GNUNET_SERVER_Client *client, |
67 | const struct GNUNET_MessageHeader *message) | 66 | const struct GNUNET_MessageHeader *message) |
68 | { | 67 | { |
69 | GNUNET_SERVER_client_keep(client); | 68 | GNUNET_SERVER_client_keep (client); |
70 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 69 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
71 | _("Initiating shutdown as requested by client.\n")); | 70 | _("Initiating shutdown as requested by client.\n")); |
72 | 71 | ||
73 | GNUNET_SERVER_notify_transmit_ready (client, | 72 | GNUNET_SERVER_notify_transmit_ready (client, |
74 | sizeof(struct GNUNET_MessageHeader), | 73 | sizeof (struct GNUNET_MessageHeader), |
75 | GNUNET_TIME_UNIT_FOREVER_REL, | 74 | GNUNET_TIME_UNIT_FOREVER_REL, |
76 | &transmit_shutdown_ack, client); | 75 | &transmit_shutdown_ack, client); |
77 | GNUNET_SERVER_client_persist_ (client); | 76 | GNUNET_SERVER_client_persist_ (client); |
@@ -95,14 +94,15 @@ run (void *cls, | |||
95 | } | 94 | } |
96 | 95 | ||
97 | 96 | ||
98 | int main(int argc, char *const *argv) | 97 | int |
98 | main (int argc, char *const *argv) | ||
99 | { | 99 | { |
100 | int ret; | 100 | int ret; |
101 | 101 | ||
102 | ret = (GNUNET_OK == | 102 | ret = (GNUNET_OK == |
103 | GNUNET_SERVICE_run (argc, | 103 | GNUNET_SERVICE_run (argc, |
104 | argv, | 104 | argv, |
105 | "do-nothing", GNUNET_SERVICE_OPTION_NONE, | 105 | "do-nothing", GNUNET_SERVICE_OPTION_NONE, |
106 | &run, NULL)) ? 0 : 1; | 106 | &run, NULL)) ? 0 : 1; |
107 | return ret; | 107 | return ret; |
108 | } | 108 | } |
diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index cce5867f1..1e9d84202 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.c | |||
@@ -47,7 +47,7 @@ static int ok = 1; | |||
47 | static void | 47 | static void |
48 | arm_stopped (void *cls, int success) | 48 | arm_stopped (void *cls, int success) |
49 | { | 49 | { |
50 | if (success != GNUNET_NO) | 50 | if (success != GNUNET_NO) |
51 | ok = 3; | 51 | ok = 3; |
52 | else if (ok == 1) | 52 | else if (ok == 1) |
53 | ok = 0; | 53 | ok = 0; |
@@ -67,15 +67,15 @@ static void | |||
67 | dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) | 67 | dns_notify (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
68 | { | 68 | { |
69 | if (addr == NULL) | 69 | if (addr == NULL) |
70 | { | ||
71 | if (ok != 0) | ||
70 | { | 72 | { |
71 | if (ok != 0) | 73 | GNUNET_break (0); |
72 | { | 74 | ok = 2; |
73 | GNUNET_break (0); | ||
74 | ok = 2; | ||
75 | } | ||
76 | GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, NULL); | ||
77 | return; | ||
78 | } | 75 | } |
76 | GNUNET_ARM_stop_service (arm, "resolver", TIMEOUT, &arm_notify_stop, NULL); | ||
77 | return; | ||
78 | } | ||
79 | GNUNET_assert (addr != NULL); | 79 | GNUNET_assert (addr != NULL); |
80 | ok = 0; | 80 | ok = 0; |
81 | } | 81 | } |
@@ -85,14 +85,14 @@ static void | |||
85 | resolver_notify (void *cls, int success) | 85 | resolver_notify (void *cls, int success) |
86 | { | 86 | { |
87 | if (success != GNUNET_YES) | 87 | if (success != GNUNET_YES) |
88 | { | 88 | { |
89 | GNUNET_break (0); | 89 | GNUNET_break (0); |
90 | ok = 2; | 90 | ok = 2; |
91 | #if START_ARM | 91 | #if START_ARM |
92 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | 92 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); |
93 | #endif | 93 | #endif |
94 | return; | 94 | return; |
95 | } | 95 | } |
96 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL); | 96 | GNUNET_RESOLVER_ip_get ("localhost", AF_INET, TIMEOUT, &dns_notify, NULL); |
97 | } | 97 | } |
98 | 98 | ||
@@ -101,22 +101,22 @@ static void | |||
101 | arm_notify (void *cls, int success) | 101 | arm_notify (void *cls, int success) |
102 | { | 102 | { |
103 | if (success != GNUNET_YES) | 103 | if (success != GNUNET_YES) |
104 | { | 104 | { |
105 | GNUNET_break (0); | 105 | GNUNET_break (0); |
106 | ok = 2; | 106 | ok = 2; |
107 | #if START_ARM | 107 | #if START_ARM |
108 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | 108 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); |
109 | #endif | 109 | #endif |
110 | } | 110 | } |
111 | GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify, NULL); | 111 | GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify, |
112 | NULL); | ||
112 | } | 113 | } |
113 | 114 | ||
114 | 115 | ||
115 | static void | 116 | static void |
116 | task (void *cls, | 117 | task (void *cls, |
117 | char *const *args, | 118 | char *const *args, |
118 | const char *cfgfile, | 119 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
119 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
120 | { | 120 | { |
121 | cfg = c; | 121 | cfg = c; |
122 | arm = GNUNET_ARM_connect (cfg, NULL); | 122 | arm = GNUNET_ARM_connect (cfg, NULL); |
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index f40252a03..eb6421d5f 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c | |||
@@ -102,58 +102,55 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
102 | { | 102 | { |
103 | struct ShutdownContext *shutdown_ctx = cls; | 103 | struct ShutdownContext *shutdown_ctx = cls; |
104 | 104 | ||
105 | if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES)) | 105 | if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES)) |
106 | { | 106 | { |
107 | /* Means the other side closed the connection and never confirmed a shutdown */ | 107 | /* Means the other side closed the connection and never confirmed a shutdown */ |
108 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
109 | "Service handle shutdown before ACK!\n"); | 109 | "Service handle shutdown before ACK!\n"); |
110 | if (shutdown_ctx->cont != NULL) | 110 | if (shutdown_ctx->cont != NULL) |
111 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 111 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
112 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 112 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
113 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 113 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
114 | GNUNET_free(shutdown_ctx); | 114 | GNUNET_free (shutdown_ctx); |
115 | } | 115 | } |
116 | else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES)) | 116 | else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES)) |
117 | { | 117 | { |
118 | #if VERBOSE | 118 | #if VERBOSE |
119 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); |
120 | "Service shutdown complete.\n"); | ||
121 | #endif | 120 | #endif |
122 | if (shutdown_ctx->cont != NULL) | 121 | if (shutdown_ctx->cont != NULL) |
123 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO); | 122 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO); |
124 | 123 | ||
125 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 124 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
126 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 125 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
127 | GNUNET_free(shutdown_ctx); | 126 | GNUNET_free (shutdown_ctx); |
128 | } | 127 | } |
129 | else | 128 | else |
129 | { | ||
130 | GNUNET_assert (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader)); | ||
131 | switch (ntohs (msg->type)) | ||
130 | { | 132 | { |
131 | GNUNET_assert(ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader)); | 133 | case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK: |
132 | switch (ntohs(msg->type)) | ||
133 | { | ||
134 | case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN_ACK: | ||
135 | #if VERBOSE | 134 | #if VERBOSE |
136 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
137 | "Received confirmation for service shutdown.\n"); | 136 | "Received confirmation for service shutdown.\n"); |
138 | #endif | 137 | #endif |
139 | shutdown_ctx->confirmed = GNUNET_YES; | 138 | shutdown_ctx->confirmed = GNUNET_YES; |
140 | GNUNET_CLIENT_receive (shutdown_ctx->sock, | 139 | GNUNET_CLIENT_receive (shutdown_ctx->sock, |
141 | &service_shutdown_handler, | 140 | &service_shutdown_handler, |
142 | shutdown_ctx, | 141 | shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL); |
143 | GNUNET_TIME_UNIT_FOREVER_REL); | 142 | break; |
144 | break; | 143 | default: /* Fall through */ |
145 | default: /* Fall through */ | 144 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Service shutdown refused!\n"); |
146 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 145 | if (shutdown_ctx->cont != NULL) |
147 | "Service shutdown refused!\n"); | 146 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES); |
148 | if (shutdown_ctx->cont != NULL) | 147 | |
149 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES); | 148 | GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); |
150 | 149 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | |
151 | GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); | 150 | GNUNET_free (shutdown_ctx); |
152 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 151 | break; |
153 | GNUNET_free(shutdown_ctx); | ||
154 | break; | ||
155 | } | ||
156 | } | 152 | } |
153 | } | ||
157 | } | 154 | } |
158 | 155 | ||
159 | /** | 156 | /** |
@@ -162,14 +159,16 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
162 | * @param cls closure | 159 | * @param cls closure |
163 | * @param tc context information (why was this task triggered now) | 160 | * @param tc context information (why was this task triggered now) |
164 | */ | 161 | */ |
165 | void service_shutdown_cancel (void *cls, | 162 | void |
166 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 163 | service_shutdown_cancel (void *cls, |
164 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
167 | { | 165 | { |
168 | struct ShutdownContext *shutdown_ctx = cls; | 166 | struct ShutdownContext *shutdown_ctx = cls; |
169 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n"); | 167 | |
170 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 168 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n"); |
169 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); | ||
171 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 170 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
172 | GNUNET_free(shutdown_ctx); | 171 | GNUNET_free (shutdown_ctx); |
173 | } | 172 | } |
174 | 173 | ||
175 | 174 | ||
@@ -189,21 +188,22 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
189 | struct ShutdownContext *shutdown_ctx = cls; | 188 | struct ShutdownContext *shutdown_ctx = cls; |
190 | 189 | ||
191 | if (size < sizeof (struct GNUNET_MessageHeader)) | 190 | if (size < sizeof (struct GNUNET_MessageHeader)) |
192 | { | 191 | { |
193 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 192 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
194 | _("Failed to transmit shutdown request to client.\n")); | 193 | _("Failed to transmit shutdown request to client.\n")); |
195 | shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); | 194 | shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR); |
196 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); | 195 | GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); |
197 | GNUNET_free(shutdown_ctx); | 196 | GNUNET_free (shutdown_ctx); |
198 | return 0; /* client disconnected */ | 197 | return 0; /* client disconnected */ |
199 | } | 198 | } |
200 | 199 | ||
201 | GNUNET_CLIENT_receive (shutdown_ctx->sock, | 200 | GNUNET_CLIENT_receive (shutdown_ctx->sock, |
202 | &service_shutdown_handler, shutdown_ctx, | 201 | &service_shutdown_handler, shutdown_ctx, |
203 | GNUNET_TIME_UNIT_FOREVER_REL); | 202 | GNUNET_TIME_UNIT_FOREVER_REL); |
204 | shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout), | 203 | shutdown_ctx->cancel_task = |
205 | &service_shutdown_cancel, | 204 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining |
206 | shutdown_ctx); | 205 | (shutdown_ctx->timeout), |
206 | &service_shutdown_cancel, shutdown_ctx); | ||
207 | msg = (struct GNUNET_MessageHeader *) buf; | 207 | msg = (struct GNUNET_MessageHeader *) buf; |
208 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); | 208 | msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); |
209 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 209 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
@@ -226,22 +226,22 @@ write_shutdown (void *cls, size_t size, void *buf) | |||
226 | */ | 226 | */ |
227 | static void | 227 | static void |
228 | arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock, | 228 | arm_service_shutdown (struct GNUNET_CLIENT_Connection *sock, |
229 | struct GNUNET_TIME_Relative timeout, | 229 | struct GNUNET_TIME_Relative timeout, |
230 | GNUNET_CLIENT_ShutdownTask cont, | 230 | GNUNET_CLIENT_ShutdownTask cont, void *cont_cls) |
231 | void *cont_cls) | ||
232 | { | 231 | { |
233 | struct ShutdownContext *shutdown_ctx; | 232 | struct ShutdownContext *shutdown_ctx; |
234 | shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); | 233 | |
234 | shutdown_ctx = GNUNET_malloc (sizeof (struct ShutdownContext)); | ||
235 | shutdown_ctx->cont = cont; | 235 | shutdown_ctx->cont = cont; |
236 | shutdown_ctx->cont_cls = cont_cls; | 236 | shutdown_ctx->cont_cls = cont_cls; |
237 | shutdown_ctx->sock = sock; | 237 | shutdown_ctx->sock = sock; |
238 | shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout); | 238 | shutdown_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
239 | GNUNET_CLIENT_notify_transmit_ready (sock, | 239 | GNUNET_CLIENT_notify_transmit_ready (sock, |
240 | sizeof (struct | 240 | sizeof (struct |
241 | GNUNET_MessageHeader), | 241 | GNUNET_MessageHeader), |
242 | timeout, | 242 | timeout, |
243 | GNUNET_NO, | 243 | GNUNET_NO, |
244 | &write_shutdown, shutdown_ctx); | 244 | &write_shutdown, shutdown_ctx); |
245 | } | 245 | } |
246 | 246 | ||
247 | 247 | ||
@@ -256,8 +256,7 @@ arm_notify_stop (void *cls, int success) | |||
256 | 256 | ||
257 | 257 | ||
258 | static void | 258 | static void |
259 | kill_task (void *cbData, | 259 | kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc); |
260 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
261 | 260 | ||
262 | 261 | ||
263 | static void | 262 | static void |
@@ -265,65 +264,55 @@ do_nothing_notify (void *cls, int success) | |||
265 | { | 264 | { |
266 | GNUNET_assert (success == GNUNET_YES); | 265 | GNUNET_assert (success == GNUNET_YES); |
267 | ok = 1; | 266 | ok = 1; |
268 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 267 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL); |
269 | &kill_task, NULL); | ||
270 | } | 268 | } |
271 | 269 | ||
272 | 270 | ||
273 | static void | 271 | static void |
274 | arm_notify (void *cls, int success) | 272 | arm_notify (void *cls, int success) |
275 | { | 273 | { |
276 | GNUNET_assert (success == GNUNET_YES); | 274 | GNUNET_assert (success == GNUNET_YES); |
277 | GNUNET_ARM_start_service (arm, | 275 | GNUNET_ARM_start_service (arm, |
278 | "do-nothing", TIMEOUT, | 276 | "do-nothing", TIMEOUT, &do_nothing_notify, NULL); |
279 | &do_nothing_notify, NULL); | ||
280 | } | 277 | } |
281 | 278 | ||
282 | 279 | ||
283 | static void | 280 | static void |
284 | kill_task (void *cbData, | 281 | kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc); |
285 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
286 | 282 | ||
287 | 283 | ||
288 | static void | 284 | static void |
289 | do_nothing_restarted_notify_task (void *cls, | 285 | do_nothing_restarted_notify_task (void *cls, |
290 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 286 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
291 | { | 287 | { |
292 | static char a; | 288 | static char a; |
293 | 289 | ||
294 | trialCount++; | 290 | trialCount++; |
295 | 291 | ||
296 | #if LOG_BACKOFF | 292 | #if LOG_BACKOFF |
297 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | 293 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
298 | { | 294 | { |
299 | fprintf(killLogFilePtr, | 295 | fprintf (killLogFilePtr, "%d.Reason is shutdown!\n", trialCount); |
300 | "%d.Reason is shutdown!\n", | 296 | } |
301 | trialCount); | 297 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) |
302 | } | 298 | { |
303 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) | 299 | fprintf (killLogFilePtr, "%d.Reason is timeout!\n", trialCount); |
304 | { | 300 | } |
305 | fprintf(killLogFilePtr, | 301 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0) |
306 | "%d.Reason is timeout!\n", | 302 | { |
307 | trialCount); | 303 | fprintf (killLogFilePtr, "%d.Service is running!\n", trialCount); |
308 | } | 304 | } |
309 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0) | ||
310 | { | ||
311 | fprintf(killLogFilePtr, | ||
312 | "%d.Service is running!\n", | ||
313 | trialCount); | ||
314 | } | ||
315 | #endif | 305 | #endif |
316 | GNUNET_SCHEDULER_add_now (&kill_task, &a); | 306 | GNUNET_SCHEDULER_add_now (&kill_task, &a); |
317 | } | 307 | } |
318 | 308 | ||
319 | 309 | ||
320 | static void | 310 | static void |
321 | do_test (void *cbData, | 311 | do_test (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc) |
322 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 312 | { |
323 | { | 313 | GNUNET_CLIENT_service_test ("do-nothing", |
324 | GNUNET_CLIENT_service_test("do-nothing", | 314 | cfg, TIMEOUT, |
325 | cfg, TIMEOUT, | 315 | &do_nothing_restarted_notify_task, NULL); |
326 | &do_nothing_restarted_notify_task, NULL); | ||
327 | } | 316 | } |
328 | 317 | ||
329 | 318 | ||
@@ -331,63 +320,56 @@ static void | |||
331 | shutdown_cont (void *cls, int reason) | 320 | shutdown_cont (void *cls, int reason) |
332 | { | 321 | { |
333 | trialCount++; | 322 | trialCount++; |
334 | startedWaitingAt = GNUNET_TIME_absolute_get(); | 323 | startedWaitingAt = GNUNET_TIME_absolute_get (); |
335 | GNUNET_SCHEDULER_add_delayed (waitedFor, | 324 | GNUNET_SCHEDULER_add_delayed (waitedFor, &do_test, NULL); |
336 | &do_test, | ||
337 | NULL); | ||
338 | } | 325 | } |
339 | 326 | ||
340 | 327 | ||
341 | static void | 328 | static void |
342 | kill_task (void *cbData, | 329 | kill_task (void *cbData, const struct GNUNET_SCHEDULER_TaskContext *tc) |
343 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
344 | { | 330 | { |
345 | static struct GNUNET_CLIENT_Connection * doNothingConnection = NULL; | 331 | static struct GNUNET_CLIENT_Connection *doNothingConnection = NULL; |
332 | |||
333 | if (NULL != cbData) | ||
334 | { | ||
335 | waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); | ||
346 | 336 | ||
347 | if (NULL != cbData) | ||
348 | { | ||
349 | waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); | ||
350 | |||
351 | #if LOG_BACKOFF | 337 | #if LOG_BACKOFF |
352 | fprintf(killLogFilePtr, | 338 | fprintf (killLogFilePtr, |
353 | "Waited for: %llu ms\n", | 339 | "Waited for: %llu ms\n", (unsigned long long) waitedFor.rel_value); |
354 | (unsigned long long) waitedFor.rel_value); | ||
355 | #endif | 340 | #endif |
356 | } | 341 | } |
357 | else | 342 | else |
358 | { | 343 | { |
359 | waitedFor.rel_value = 0; | 344 | waitedFor.rel_value = 0; |
360 | } | 345 | } |
361 | /* Connect to the doNothing task */ | 346 | /* Connect to the doNothing task */ |
362 | doNothingConnection = GNUNET_CLIENT_connect ("do-nothing", cfg); | 347 | doNothingConnection = GNUNET_CLIENT_connect ("do-nothing", cfg); |
363 | GNUNET_assert (doNothingConnection != NULL); | 348 | GNUNET_assert (doNothingConnection != NULL); |
364 | if (trialCount == 12) { | 349 | if (trialCount == 12) |
350 | { | ||
365 | GNUNET_CLIENT_disconnect (doNothingConnection, GNUNET_NO); | 351 | GNUNET_CLIENT_disconnect (doNothingConnection, GNUNET_NO); |
366 | GNUNET_ARM_stop_service (arm, | 352 | GNUNET_ARM_stop_service (arm, |
367 | "do-nothing", | 353 | "do-nothing", TIMEOUT, &arm_notify_stop, NULL); |
368 | TIMEOUT, | ||
369 | &arm_notify_stop, NULL); | ||
370 | ok = 0; | 354 | ok = 0; |
371 | return; | 355 | return; |
372 | } | 356 | } |
373 | /* Use the created connection to kill the doNothingTask */ | 357 | /* Use the created connection to kill the doNothingTask */ |
374 | arm_service_shutdown(doNothingConnection, | 358 | arm_service_shutdown (doNothingConnection, TIMEOUT, &shutdown_cont, NULL); |
375 | TIMEOUT, | ||
376 | &shutdown_cont, NULL); | ||
377 | } | 359 | } |
378 | 360 | ||
379 | 361 | ||
380 | static void | 362 | static void |
381 | task (void *cls, | 363 | task (void *cls, |
382 | char *const *args, | 364 | char *const *args, |
383 | const char *cfgfile, | 365 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
384 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
385 | { | 366 | { |
386 | cfg = c; | 367 | cfg = c; |
387 | 368 | ||
388 | arm = GNUNET_ARM_connect (cfg,NULL); | 369 | arm = GNUNET_ARM_connect (cfg, NULL); |
389 | #if START_ARM | 370 | #if START_ARM |
390 | GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify, NULL); | 371 | GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify, |
372 | NULL); | ||
391 | #else | 373 | #else |
392 | arm_do_nothing (NULL, GNUNET_YES); | 374 | arm_do_nothing (NULL, GNUNET_YES); |
393 | #endif | 375 | #endif |
@@ -407,39 +389,41 @@ check () | |||
407 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 389 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
408 | GNUNET_GETOPT_OPTION_END | 390 | GNUNET_GETOPT_OPTION_END |
409 | }; | 391 | }; |
410 | 392 | ||
411 | /* Running ARM and running the do_nothing task */ | 393 | /* Running ARM and running the do_nothing task */ |
412 | GNUNET_assert (GNUNET_OK == | 394 | GNUNET_assert (GNUNET_OK == |
413 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 395 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
414 | argv, | 396 | argv, |
415 | "test-exponential-backoff", | 397 | "test-exponential-backoff", |
416 | "nohelp", options, &task, NULL)); | 398 | "nohelp", options, &task, NULL)); |
417 | 399 | ||
418 | 400 | ||
419 | return ok; | 401 | return ok; |
420 | } | 402 | } |
421 | 403 | ||
422 | static int | 404 | static int |
423 | init() | 405 | init () |
424 | { | 406 | { |
425 | #if LOG_BACKOFF | 407 | #if LOG_BACKOFF |
426 | killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log"); | 408 | killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log"); |
427 | if (NULL == (killLogFilePtr = FOPEN(killLogFileName, "w"))) { | 409 | if (NULL == (killLogFilePtr = FOPEN (killLogFileName, "w"))) |
428 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", killLogFileName); | 410 | { |
411 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", | ||
412 | killLogFileName); | ||
429 | GNUNET_free (killLogFileName); | 413 | GNUNET_free (killLogFileName); |
430 | return GNUNET_SYSERR; | 414 | return GNUNET_SYSERR; |
431 | } | 415 | } |
432 | #endif | 416 | #endif |
433 | return GNUNET_OK; | 417 | return GNUNET_OK; |
434 | } | 418 | } |
435 | 419 | ||
436 | 420 | ||
437 | static void | 421 | static void |
438 | houseKeep() | 422 | houseKeep () |
439 | { | 423 | { |
440 | #if LOG_BACKOFF | 424 | #if LOG_BACKOFF |
441 | GNUNET_assert (0 == fclose (killLogFilePtr)); | 425 | GNUNET_assert (0 == fclose (killLogFilePtr)); |
442 | GNUNET_free(killLogFileName); | 426 | GNUNET_free (killLogFileName); |
443 | #endif | 427 | #endif |
444 | } | 428 | } |
445 | 429 | ||
@@ -456,10 +440,10 @@ main (int argc, char *argv[]) | |||
456 | "WARNING", | 440 | "WARNING", |
457 | #endif | 441 | #endif |
458 | NULL); | 442 | NULL); |
459 | 443 | ||
460 | init(); | 444 | init (); |
461 | ret = check (); | 445 | ret = check (); |
462 | houseKeep(); | 446 | houseKeep (); |
463 | return ret; | 447 | return ret; |
464 | } | 448 | } |
465 | 449 | ||
diff --git a/src/arm/test_gnunet_service_manager.c b/src/arm/test_gnunet_service_manager.c index 087e01ccb..4c4de9242 100644 --- a/src/arm/test_gnunet_service_manager.c +++ b/src/arm/test_gnunet_service_manager.c | |||
@@ -53,41 +53,36 @@ static struct GNUNET_ARM_Handle *arm; | |||
53 | static void | 53 | static void |
54 | arm_stopped (void *cls, int success) | 54 | arm_stopped (void *cls, int success) |
55 | { | 55 | { |
56 | if (success != GNUNET_NO) | 56 | if (success != GNUNET_NO) |
57 | { | 57 | { |
58 | GNUNET_break (0); | 58 | GNUNET_break (0); |
59 | ret = 4; | 59 | ret = 4; |
60 | } | 60 | } |
61 | else | 61 | else |
62 | { | 62 | { |
63 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 63 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM stopped\n"); |
64 | "ARM stopped\n"); | 64 | } |
65 | } | ||
66 | #if START_ARM | 65 | #if START_ARM |
67 | GNUNET_ARM_disconnect (arm); | 66 | GNUNET_ARM_disconnect (arm); |
68 | arm = NULL; | 67 | arm = NULL; |
69 | #endif | 68 | #endif |
70 | } | 69 | } |
71 | 70 | ||
72 | static void | 71 | static void |
73 | hostNameResolveCB(void *cls, | 72 | hostNameResolveCB (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
74 | const struct sockaddr *addr, | ||
75 | socklen_t addrlen) | ||
76 | { | 73 | { |
77 | if ( (ret == 0) || (ret == 4) ) | 74 | if ((ret == 0) || (ret == 4)) |
78 | return; | 75 | return; |
79 | if (NULL == addr) | 76 | if (NULL == addr) |
80 | { | 77 | { |
81 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Name not resolved!\n"); |
82 | "Name not resolved!\n"); | ||
83 | #if START_ARM | 79 | #if START_ARM |
84 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | 80 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); |
85 | #endif | 81 | #endif |
86 | ret = 3; | 82 | ret = 3; |
87 | return; | 83 | return; |
88 | } | 84 | } |
89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolved hostname, now stopping ARM\n"); |
90 | "Resolved hostname, now stopping ARM\n"); | ||
91 | ret = 0; | 86 | ret = 0; |
92 | #if START_ARM | 87 | #if START_ARM |
93 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | 88 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); |
@@ -99,34 +94,31 @@ static void | |||
99 | arm_notify (void *cls, int success) | 94 | arm_notify (void *cls, int success) |
100 | { | 95 | { |
101 | if (success != GNUNET_YES) | 96 | if (success != GNUNET_YES) |
102 | { | 97 | { |
103 | GNUNET_break (0); | 98 | GNUNET_break (0); |
104 | ret = 1; | 99 | ret = 1; |
105 | return; | 100 | return; |
106 | } | 101 | } |
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to resolve our own hostname!\n"); |
108 | "Trying to resolve our own hostname!\n"); | ||
109 | /* connect to the resolver service */ | 103 | /* connect to the resolver service */ |
110 | if (NULL == GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, | 104 | if (NULL == GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, |
111 | TIMEOUT, | 105 | TIMEOUT, |
112 | &hostNameResolveCB, | 106 | &hostNameResolveCB, NULL)) |
113 | NULL)) | 107 | { |
114 | { | 108 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 109 | "Unable initiate connection to resolver service\n"); |
116 | "Unable initiate connection to resolver service\n"); | 110 | ret = 2; |
117 | ret = 2; | ||
118 | #if START_ARM | 111 | #if START_ARM |
119 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); | 112 | GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); |
120 | #endif | 113 | #endif |
121 | } | 114 | } |
122 | } | 115 | } |
123 | 116 | ||
124 | 117 | ||
125 | static void | 118 | static void |
126 | run(void *cls, | 119 | run (void *cls, |
127 | char * const *args, | 120 | char *const *args, |
128 | const char *cfgfile, | 121 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
129 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
130 | { | 122 | { |
131 | cfg = c; | 123 | cfg = c; |
132 | #if START_ARM | 124 | #if START_ARM |
@@ -139,7 +131,7 @@ run(void *cls, | |||
139 | 131 | ||
140 | 132 | ||
141 | static void | 133 | static void |
142 | check() | 134 | check () |
143 | { | 135 | { |
144 | char *const argv[] = { | 136 | char *const argv[] = { |
145 | "test-gnunet-service-manager", | 137 | "test-gnunet-service-manager", |
@@ -153,39 +145,40 @@ check() | |||
153 | GNUNET_GETOPT_OPTION_END | 145 | GNUNET_GETOPT_OPTION_END |
154 | }; | 146 | }; |
155 | GNUNET_assert (GNUNET_OK == | 147 | GNUNET_assert (GNUNET_OK == |
156 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 148 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
157 | argv, | 149 | argv, |
158 | "test-gnunet-service-manager", | 150 | "test-gnunet-service-manager", |
159 | "nohelp", options, &run, NULL)); | 151 | "nohelp", options, &run, NULL)); |
160 | } | 152 | } |
161 | 153 | ||
162 | 154 | ||
163 | int | 155 | int |
164 | main (int argc, char *argv[]) | 156 | main (int argc, char *argv[]) |
165 | { | 157 | { |
166 | char hostname[GNUNET_OS_get_hostname_max_length() + 1]; | 158 | char hostname[GNUNET_OS_get_hostname_max_length () + 1]; |
167 | 159 | ||
168 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) | 160 | if (0 != gethostname (hostname, sizeof (hostname) - 1)) |
169 | { | 161 | { |
170 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | | 162 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | |
171 | GNUNET_ERROR_TYPE_BULK, "gethostname"); | 163 | GNUNET_ERROR_TYPE_BULK, "gethostname"); |
172 | fprintf (stderr, "Failed to determine my own hostname, testcase not run.\n"); | 164 | fprintf (stderr, |
173 | return 0; | 165 | "Failed to determine my own hostname, testcase not run.\n"); |
174 | } | 166 | return 0; |
167 | } | ||
175 | if (NULL == gethostbyname (hostname)) | 168 | if (NULL == gethostbyname (hostname)) |
176 | { | 169 | { |
177 | fprintf (stderr, "Failed to resolve my hostname `%s', testcase not run.\n", | 170 | fprintf (stderr, "Failed to resolve my hostname `%s', testcase not run.\n", |
178 | hostname); | 171 | hostname); |
179 | return 0; | 172 | return 0; |
180 | } | 173 | } |
181 | 174 | ||
182 | GNUNET_log_setup("test-gnunet-service-manager", | 175 | GNUNET_log_setup ("test-gnunet-service-manager", |
183 | #if VERBOSE | 176 | #if VERBOSE |
184 | "DEBUG", | 177 | "DEBUG", |
185 | #else | 178 | #else |
186 | "WARNING", | 179 | "WARNING", |
187 | #endif | 180 | #endif |
188 | NULL); | 181 | NULL); |
189 | check(); | 182 | check (); |
190 | return ret; | 183 | return ret; |
191 | } | 184 | } |