diff options
27 files changed, 268 insertions, 152 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index f2d2b293a..bc80b779f 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -163,12 +163,22 @@ arm_service_report (void *cls, | |||
163 | 163 | ||
164 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) | 164 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) |
165 | { | 165 | { |
166 | #if DEBUG_ARM | ||
167 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
168 | "Looks like `%s' is already running.\n", | ||
169 | "gnunet-service-arm"); | ||
170 | #endif | ||
166 | /* arm is running! */ | 171 | /* arm is running! */ |
167 | if (pos->callback != NULL) | 172 | if (pos->callback != NULL) |
168 | pos->callback (pos->cls, GNUNET_YES); | 173 | pos->callback (pos->cls, GNUNET_YES); |
169 | GNUNET_free (pos); | 174 | GNUNET_free (pos); |
170 | return; | 175 | return; |
171 | } | 176 | } |
177 | #if DEBUG_ARM | ||
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
179 | "Looks like `%s' is not running, will start it.\n", | ||
180 | "gnunet-service-arm"); | ||
181 | #endif | ||
172 | /* FIXME: should we check that HOSTNAME for 'arm' is localhost? */ | 182 | /* FIXME: should we check that HOSTNAME for 'arm' is localhost? */ |
173 | /* start service */ | 183 | /* start service */ |
174 | if (GNUNET_OK != | 184 | if (GNUNET_OK != |
@@ -236,7 +246,10 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
236 | if (msg == NULL) | 246 | if (msg == NULL) |
237 | { | 247 | { |
238 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 248 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
239 | _("Error receiving response from ARM service\n")); | 249 | _("Error receiving response to `%s' request from ARM service\n"), |
250 | (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) | ||
251 | ? "START" | ||
252 | : "STOP"); | ||
240 | GNUNET_CLIENT_disconnect (sc->h->client); | 253 | GNUNET_CLIENT_disconnect (sc->h->client); |
241 | sc->h->client = GNUNET_CLIENT_connect (sc->h->sched, | 254 | sc->h->client = GNUNET_CLIENT_connect (sc->h->sched, |
242 | "arm", | 255 | "arm", |
@@ -304,7 +317,10 @@ change_service (struct GNUNET_ARM_Handle *h, | |||
304 | } | 317 | } |
305 | #if DEBUG_ARM | 318 | #if DEBUG_ARM |
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
307 | _("ARM requests starting of service `%s'.\n"), service_name); | 320 | (type == GNUNET_MESSAGE_TYPE_ARM_START) |
321 | ? _("Requesting start of service `%s'.\n") | ||
322 | : _("Requesting termination of service `%s'.\n"), | ||
323 | service_name); | ||
308 | #endif | 324 | #endif |
309 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); | 325 | sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); |
310 | sctx->h = h; | 326 | sctx->h = h; |
@@ -355,7 +371,7 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, | |||
355 | 371 | ||
356 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 372 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
357 | _("Starting service `%s'\n"), service_name); | 373 | _("Starting service `%s'\n"), service_name); |
358 | if (0 == strcmp ("arm", service_name)) | 374 | if (0 == strcasecmp ("arm", service_name)) |
359 | { | 375 | { |
360 | sctx = GNUNET_malloc (sizeof (struct RequestContext)); | 376 | sctx = GNUNET_malloc (sizeof (struct RequestContext)); |
361 | sctx->h = h; | 377 | sctx->h = h; |
@@ -388,7 +404,7 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, | |||
388 | { | 404 | { |
389 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 405 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
390 | _("Stopping service `%s'\n"), service_name); | 406 | _("Stopping service `%s'\n"), service_name); |
391 | if (0 == strcmp ("arm", service_name)) | 407 | if (0 == strcasecmp ("arm", service_name)) |
392 | { | 408 | { |
393 | GNUNET_CLIENT_service_shutdown (h->client); | 409 | GNUNET_CLIENT_service_shutdown (h->client); |
394 | h->client = NULL; | 410 | h->client = NULL; |
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index f907d944f..4a30848eb 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -157,6 +157,17 @@ static char *prefix_command; | |||
157 | */ | 157 | */ |
158 | static int in_shutdown; | 158 | static int in_shutdown; |
159 | 159 | ||
160 | /** | ||
161 | * Handle to our server instance. Our server is a bit special in that | ||
162 | * its service is not immediately stopped once we get a shutdown | ||
163 | * request (since we need to continue service until all of our child | ||
164 | * processes are dead). This handle is used to shut down the server | ||
165 | * (and thus trigger process termination) once all child processes are | ||
166 | * also dead. A special option in the ARM configuration modifies the | ||
167 | * behaviour of the service implementation to not do the shutdown | ||
168 | * immediately. | ||
169 | */ | ||
170 | static struct GNUNET_SERVER_Handle *server; | ||
160 | 171 | ||
161 | /** | 172 | /** |
162 | * Background task doing maintenance. | 173 | * Background task doing maintenance. |
@@ -646,9 +657,16 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
646 | pos = running; | 657 | pos = running; |
647 | while (NULL != pos) | 658 | while (NULL != pos) |
648 | { | 659 | { |
649 | if ( (pos->pid != 0) && | 660 | if (pos->pid != 0) |
650 | (0 != PLIBC_KILL (pos->pid, SIGTERM)) ) | 661 | { |
651 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 662 | #if DEBUG_ARM |
663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
664 | "Sending SIGTERM to `%s'\n", | ||
665 | pos->name); | ||
666 | #endif | ||
667 | if (0 != PLIBC_KILL (pos->pid, SIGTERM)) | ||
668 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
669 | } | ||
652 | pos = pos->next; | 670 | pos = pos->next; |
653 | } | 671 | } |
654 | } | 672 | } |
@@ -656,7 +674,14 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
656 | { | 674 | { |
657 | if ( (in_shutdown == GNUNET_YES) && | 675 | if ( (in_shutdown == GNUNET_YES) && |
658 | (running == NULL) ) | 676 | (running == NULL) ) |
659 | return; /* we are done! */ | 677 | { |
678 | #if DEBUG_ARM | ||
679 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
680 | "ARM service terminates.\n"); | ||
681 | #endif | ||
682 | GNUNET_SERVER_destroy (server); | ||
683 | return; /* we are done! */ | ||
684 | } | ||
660 | GNUNET_SCHEDULER_add_delayed (tc->sched, | 685 | GNUNET_SCHEDULER_add_delayed (tc->sched, |
661 | (in_shutdown == GNUNET_YES) | 686 | (in_shutdown == GNUNET_YES) |
662 | ? MAINT_FAST_FREQUENCY | 687 | ? MAINT_FAST_FREQUENCY |
@@ -716,6 +741,12 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
716 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 741 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
717 | _("Service `%s' terminated with status %s/%d, will try to restart it!\n"), | 742 | _("Service `%s' terminated with status %s/%d, will try to restart it!\n"), |
718 | pos->name, statstr, statcode); | 743 | pos->name, statstr, statcode); |
744 | #if DEBUG_ARM | ||
745 | else | ||
746 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
747 | "Service `%s' terminated with status %s/%d\n", | ||
748 | pos->name, statstr, statcode); | ||
749 | #endif | ||
719 | /* schedule restart */ | 750 | /* schedule restart */ |
720 | pos->pid = 0; | 751 | pos->pid = 0; |
721 | prev = pos; | 752 | prev = pos; |
@@ -762,20 +793,22 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
762 | * | 793 | * |
763 | * @param cls closure | 794 | * @param cls closure |
764 | * @param s scheduler to use | 795 | * @param s scheduler to use |
765 | * @param server the initialized server | 796 | * @param serv the initialized server |
766 | * @param c configuration to use | 797 | * @param c configuration to use |
767 | */ | 798 | */ |
768 | static void | 799 | static void |
769 | run (void *cls, | 800 | run (void *cls, |
770 | struct GNUNET_SCHEDULER_Handle *s, | 801 | struct GNUNET_SCHEDULER_Handle *s, |
771 | struct GNUNET_SERVER_Handle *server, | 802 | struct GNUNET_SERVER_Handle *serv, |
772 | const struct GNUNET_CONFIGURATION_Handle *c) | 803 | const struct GNUNET_CONFIGURATION_Handle *c) |
773 | { | 804 | { |
774 | char *defaultservices; | 805 | char *defaultservices; |
775 | char *pos; | 806 | char *pos; |
776 | 807 | ||
808 | GNUNET_assert (serv != NULL); | ||
777 | cfg = c; | 809 | cfg = c; |
778 | sched = s; | 810 | sched = s; |
811 | server = serv; | ||
779 | if (GNUNET_OK != | 812 | if (GNUNET_OK != |
780 | GNUNET_CONFIGURATION_get_value_string (cfg, | 813 | GNUNET_CONFIGURATION_get_value_string (cfg, |
781 | "ARM", | 814 | "ARM", |
@@ -831,7 +864,9 @@ main (int argc, char *const *argv) | |||
831 | { | 864 | { |
832 | return (GNUNET_OK == | 865 | return (GNUNET_OK == |
833 | GNUNET_SERVICE_run (argc, | 866 | GNUNET_SERVICE_run (argc, |
834 | argv, "arm", &run, NULL)) ? 0 : 1; | 867 | argv, "arm", |
868 | GNUNET_YES, | ||
869 | &run, NULL)) ? 0 : 1; | ||
835 | } | 870 | } |
836 | 871 | ||
837 | /* end of gnunet-service-arm.c */ | 872 | /* end of gnunet-service-arm.c */ |
diff --git a/src/arm/test_gnunet_arm.sh b/src/arm/test_gnunet_arm.sh index d36c2ca38..4c3edb249 100755 --- a/src/arm/test_gnunet_arm.sh +++ b/src/arm/test_gnunet_arm.sh | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | exe="./gnunet-arm -c test_arm_api_data.conf" | 3 | exe="valgrind --trace-children=yes ./gnunet-arm -c test_arm_api_data.conf" |
4 | out=`mktemp /tmp/test-gnunet-arm-logXXXXXXXX` | 4 | out=`mktemp /tmp/test-gnunet-arm-logXXXXXXXX` |
5 | #DEBUG="-L DEBUG" | 5 | #DEBUG="-L DEBUG" |
6 | 6 | ||
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 839eb2727..9d9ba5690 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -3214,7 +3214,9 @@ main (int argc, char *const *argv) | |||
3214 | return (GNUNET_OK == | 3214 | return (GNUNET_OK == |
3215 | GNUNET_SERVICE_run (argc, | 3215 | GNUNET_SERVICE_run (argc, |
3216 | argv, | 3216 | argv, |
3217 | "core", &run, NULL)) ? 0 : 1; | 3217 | "core", |
3218 | GNUNET_SERVICE_OPTION_NONE, | ||
3219 | &run, NULL)) ? 0 : 1; | ||
3218 | } | 3220 | } |
3219 | 3221 | ||
3220 | /* end of gnunet-service-core.c */ | 3222 | /* end of gnunet-service-core.c */ |
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 27b1cd58e..d58f0f8d9 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c | |||
@@ -1341,7 +1341,9 @@ main (int argc, char *const *argv) | |||
1341 | ret = (GNUNET_OK == | 1341 | ret = (GNUNET_OK == |
1342 | GNUNET_SERVICE_run (argc, | 1342 | GNUNET_SERVICE_run (argc, |
1343 | argv, | 1343 | argv, |
1344 | "datastore", &run, NULL)) ? 0 : 1; | 1344 | "datastore", |
1345 | GNUNET_SERVICE_OPTION_NONE, | ||
1346 | &run, NULL)) ? 0 : 1; | ||
1345 | return ret; | 1347 | return ret; |
1346 | } | 1348 | } |
1347 | 1349 | ||
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 0e592e094..bec69f6ec 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -3358,7 +3358,9 @@ main (int argc, char *const *argv) | |||
3358 | return (GNUNET_OK == | 3358 | return (GNUNET_OK == |
3359 | GNUNET_SERVICE_run (argc, | 3359 | GNUNET_SERVICE_run (argc, |
3360 | argv, | 3360 | argv, |
3361 | "fs", &run, NULL)) ? 0 : 1; | 3361 | "fs", |
3362 | GNUNET_SERVICE_OPTION_NONE, | ||
3363 | &run, NULL)) ? 0 : 1; | ||
3362 | } | 3364 | } |
3363 | 3365 | ||
3364 | /* end of gnunet-service-fs.c */ | 3366 | /* end of gnunet-service-fs.c */ |
diff --git a/src/fs/test_fs_search_data.conf b/src/fs/test_fs_search_data.conf index fd82a15fc..cffe83f57 100644 --- a/src/fs/test_fs_search_data.conf +++ b/src/fs/test_fs_search_data.conf | |||
@@ -1,6 +1,6 @@ | |||
1 | [PATHS] | 1 | [PATHS] |
2 | SERVICEHOME = /tmp/gnunet-test-fs-search/ | 2 | SERVICEHOME = /tmp/gnunet-test-fs-search/ |
3 | DEFAULTCONFIG = test_fs_download_data.conf | 3 | DEFAULTCONFIG = test_fs_search_data.conf |
4 | 4 | ||
5 | [gnunetd] | 5 | [gnunetd] |
6 | HOSTKEY = $SERVICEHOME/.hostkey | 6 | HOSTKEY = $SERVICEHOME/.hostkey |
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h index 82089954e..66e4f0cd9 100644 --- a/src/include/gnunet_service_lib.h +++ b/src/include/gnunet_service_lib.h | |||
@@ -55,12 +55,31 @@ typedef void (*GNUNET_SERVICE_Main) (void *cls, | |||
55 | 55 | ||
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Options for the service (bitmask). | ||
59 | */ | ||
60 | enum GNUNET_SERVICE_Options | ||
61 | { | ||
62 | /** | ||
63 | * Use defaults. | ||
64 | */ | ||
65 | GNUNET_SERVICE_OPTION_NONE = 0, | ||
66 | |||
67 | /** | ||
68 | * Do not trigger server shutdown on signals, allow for the user | ||
69 | * to terminate the server explicitly when needed. | ||
70 | */ | ||
71 | GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1 | ||
72 | }; | ||
73 | |||
74 | |||
75 | /** | ||
58 | * Run a standard GNUnet service startup sequence (initialize loggers | 76 | * Run a standard GNUnet service startup sequence (initialize loggers |
59 | * and configuration, parse options). | 77 | * and configuration, parse options). |
60 | * | 78 | * |
61 | * @param argc number of command line arguments | 79 | * @param argc number of command line arguments |
62 | * @param argv command line arguments | 80 | * @param argv command line arguments |
63 | * @param serviceName our service name | 81 | * @param serviceName our service name |
82 | * @param opt service options | ||
64 | * @param task main task of the service | 83 | * @param task main task of the service |
65 | * @param task_cls closure for task | 84 | * @param task_cls closure for task |
66 | * @return GNUNET_SYSERR on error, GNUNET_OK | 85 | * @return GNUNET_SYSERR on error, GNUNET_OK |
@@ -69,6 +88,7 @@ typedef void (*GNUNET_SERVICE_Main) (void *cls, | |||
69 | int GNUNET_SERVICE_run (int argc, | 88 | int GNUNET_SERVICE_run (int argc, |
70 | char *const *argv, | 89 | char *const *argv, |
71 | const char *serviceName, | 90 | const char *serviceName, |
91 | enum GNUNET_SERVICE_Options opt, | ||
72 | GNUNET_SERVICE_Main task, | 92 | GNUNET_SERVICE_Main task, |
73 | void *task_cls); | 93 | void *task_cls); |
74 | 94 | ||
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index f5a60470e..ee1287831 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -711,7 +711,9 @@ main (int argc, char *const *argv) | |||
711 | ret = (GNUNET_OK == | 711 | ret = (GNUNET_OK == |
712 | GNUNET_SERVICE_run (argc, | 712 | GNUNET_SERVICE_run (argc, |
713 | argv, | 713 | argv, |
714 | "peerinfo", &run, NULL)) ? 0 : 1; | 714 | "peerinfo", |
715 | GNUNET_SERVICE_OPTION_NONE, | ||
716 | &run, NULL)) ? 0 : 1; | ||
715 | GNUNET_free_non_null (networkIdDirectory); | 717 | GNUNET_free_non_null (networkIdDirectory); |
716 | GNUNET_free_non_null (trustDirectory); | 718 | GNUNET_free_non_null (trustDirectory); |
717 | return ret; | 719 | return ret; |
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index 8de9a8047..c90038e03 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -486,7 +486,9 @@ main (int argc, char *const *argv) | |||
486 | return (GNUNET_OK == | 486 | return (GNUNET_OK == |
487 | GNUNET_SERVICE_run (argc, | 487 | GNUNET_SERVICE_run (argc, |
488 | argv, | 488 | argv, |
489 | "statistics", &run, NULL)) ? 0 : 1; | 489 | "statistics", |
490 | GNUNET_SERVICE_OPTION_NONE, | ||
491 | &run, NULL)) ? 0 : 1; | ||
490 | } | 492 | } |
491 | 493 | ||
492 | /* end of gnunet-service-statistics.c */ | 494 | /* end of gnunet-service-statistics.c */ |
diff --git a/src/template/gnunet-service-template.c b/src/template/gnunet-service-template.c index 15ba94b7d..39d332226 100644 --- a/src/template/gnunet-service-template.c +++ b/src/template/gnunet-service-template.c | |||
@@ -88,7 +88,9 @@ main (int argc, char *const *argv) | |||
88 | return (GNUNET_OK == | 88 | return (GNUNET_OK == |
89 | GNUNET_SERVICE_run (argc, | 89 | GNUNET_SERVICE_run (argc, |
90 | argv, | 90 | argv, |
91 | "template", &run, NULL)) ? 0 : 1; | 91 | "template", |
92 | GNUNET_SERVICE_OPTION_NONE, | ||
93 | &run, NULL)) ? 0 : 1; | ||
92 | } | 94 | } |
93 | 95 | ||
94 | /* end of gnunet-service-template.c */ | 96 | /* end of gnunet-service-template.c */ |
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c index 431b63963..ade3fed11 100644 --- a/src/testing/test_testing_connect.c +++ b/src/testing/test_testing_connect.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_testing_lib.h" | 25 | #include "gnunet_testing_lib.h" |
26 | 26 | ||
27 | #define VERBOSE GNUNET_NO | 27 | #define VERBOSE GNUNET_YES |
28 | 28 | ||
29 | 29 | ||
30 | /** | 30 | /** |
@@ -51,7 +51,7 @@ static void end2_cb(void *cls, | |||
51 | GNUNET_assert (emsg == NULL); | 51 | GNUNET_assert (emsg == NULL); |
52 | #if VERBOSE | 52 | #if VERBOSE |
53 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 53 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
54 | "Daemon terminated, will now exit.\n"); | 54 | "Both daemons terminated, will now exit.\n"); |
55 | #endif | 55 | #endif |
56 | ok = 0; | 56 | ok = 0; |
57 | } | 57 | } |
diff --git a/src/testing/test_testing_connect_peer1.conf b/src/testing/test_testing_connect_peer1.conf index 020504728..32ddbfc4d 100644 --- a/src/testing/test_testing_connect_peer1.conf +++ b/src/testing/test_testing_connect_peer1.conf | |||
@@ -17,6 +17,7 @@ PLUGINS = tcp | |||
17 | PORT = 12566 | 17 | PORT = 12566 |
18 | HOSTNAME = localhost | 18 | HOSTNAME = localhost |
19 | DEFAULTSERVICES = peerinfo transport core | 19 | DEFAULTSERVICES = peerinfo transport core |
20 | DEBUG = YES | ||
20 | 21 | ||
21 | [statistics] | 22 | [statistics] |
22 | PORT = 12567 | 23 | PORT = 12567 |
@@ -32,6 +33,7 @@ HOSTNAME = localhost | |||
32 | [core] | 33 | [core] |
33 | PORT = 12570 | 34 | PORT = 12570 |
34 | HOSTNAME = localhost | 35 | HOSTNAME = localhost |
36 | DEBUG = YES | ||
35 | 37 | ||
36 | [testing] | 38 | [testing] |
37 | WEAKRANDOM = YES | 39 | WEAKRANDOM = YES |
diff --git a/src/testing/test_testing_connect_peer2.conf b/src/testing/test_testing_connect_peer2.conf index 196e96a84..a152ff237 100644 --- a/src/testing/test_testing_connect_peer2.conf +++ b/src/testing/test_testing_connect_peer2.conf | |||
@@ -17,6 +17,7 @@ PLUGINS = tcp | |||
17 | PORT = 22566 | 17 | PORT = 22566 |
18 | DEFAULTSERVICES = peerinfo transport core | 18 | DEFAULTSERVICES = peerinfo transport core |
19 | HOSTNAME = localhost | 19 | HOSTNAME = localhost |
20 | DEBUG = YES | ||
20 | 21 | ||
21 | [statistics] | 22 | [statistics] |
22 | PORT = 22567 | 23 | PORT = 22567 |
@@ -32,6 +33,7 @@ HOSTNAME = localhost | |||
32 | [core] | 33 | [core] |
33 | PORT = 22570 | 34 | PORT = 22570 |
34 | HOSTNAME = localhost | 35 | HOSTNAME = localhost |
36 | DEBUG = YES | ||
35 | 37 | ||
36 | [testing] | 38 | [testing] |
37 | WEAKRANDOM = YES | 39 | WEAKRANDOM = YES |
diff --git a/src/testing/testing.c b/src/testing/testing.c index e34e7a9ac..6edefb14a 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -40,13 +40,13 @@ | |||
40 | #include "gnunet_testing_lib.h" | 40 | #include "gnunet_testing_lib.h" |
41 | #include "gnunet_transport_service.h" | 41 | #include "gnunet_transport_service.h" |
42 | 42 | ||
43 | #define DEBUG_TESTING GNUNET_NO | 43 | #define DEBUG_TESTING GNUNET_YES |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * How long do we wait after starting gnunet-service-arm | 46 | * How long do we wait after starting gnunet-service-arm |
47 | * for the core service to be alive? | 47 | * for the core service to be alive? |
48 | */ | 48 | */ |
49 | #define ARM_START_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 49 | #define ARM_START_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * How many times are we willing to try to wait for "scp" or | 52 | * How many times are we willing to try to wait for "scp" or |
@@ -236,6 +236,7 @@ testing_init (void *cls, | |||
236 | d->cb = NULL; | 236 | d->cb = NULL; |
237 | if (server == NULL) | 237 | if (server == NULL) |
238 | { | 238 | { |
239 | d->server = NULL; | ||
239 | if (GNUNET_YES == d->dead) | 240 | if (GNUNET_YES == d->dead) |
240 | GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); | 241 | GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls); |
241 | else if (NULL != cb) | 242 | else if (NULL != cb) |
@@ -428,15 +429,15 @@ start_fsm (void *cls, | |||
428 | "gnunet-service-arm"); | 429 | "gnunet-service-arm"); |
429 | #endif | 430 | #endif |
430 | d->phase = SP_START_CORE; | 431 | d->phase = SP_START_CORE; |
431 | GNUNET_CORE_connect (d->sched, | 432 | d->server = GNUNET_CORE_connect (d->sched, |
432 | d->cfg, | 433 | d->cfg, |
433 | ARM_START_WAIT, | 434 | ARM_START_WAIT, |
434 | d, | 435 | d, |
435 | &testing_init, | 436 | &testing_init, |
436 | NULL, NULL, NULL, | 437 | NULL, NULL, NULL, |
437 | NULL, GNUNET_NO, | 438 | NULL, GNUNET_NO, |
438 | NULL, GNUNET_NO, | 439 | NULL, GNUNET_NO, |
439 | no_handlers); | 440 | no_handlers); |
440 | break; | 441 | break; |
441 | case SP_START_CORE: | 442 | case SP_START_CORE: |
442 | GNUNET_break (0); | 443 | GNUNET_break (0); |
diff --git a/src/topology/test_gnunet_service_topology.c b/src/topology/test_gnunet_service_topology.c index 2536f5454..130f40629 100644 --- a/src/topology/test_gnunet_service_topology.c +++ b/src/topology/test_gnunet_service_topology.c | |||
@@ -66,7 +66,8 @@ notify_connect_complete(void *cls, | |||
66 | { | 66 | { |
67 | /* FIXME: check that topology adds a few more links | 67 | /* FIXME: check that topology adds a few more links |
68 | in addition to those that were seeded */ | 68 | in addition to those that were seeded */ |
69 | sleep (100); | 69 | /* For now, sleep so we can have the daemon do some work */ |
70 | sleep (10); | ||
70 | GNUNET_TESTING_daemons_stop (pg); | 71 | GNUNET_TESTING_daemons_stop (pg); |
71 | ok = 0; | 72 | ok = 0; |
72 | } | 73 | } |
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index efe53e021..5c5c64dbc 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -2709,6 +2709,7 @@ main (int argc, char *const *argv) | |||
2709 | GNUNET_SERVICE_run (argc, | 2709 | GNUNET_SERVICE_run (argc, |
2710 | argv, | 2710 | argv, |
2711 | "transport", | 2711 | "transport", |
2712 | GNUNET_SERVICE_OPTION_NONE, | ||
2712 | &run, NULL)) ? 0 : 1; | 2713 | &run, NULL)) ? 0 : 1; |
2713 | } | 2714 | } |
2714 | 2715 | ||
diff --git a/src/util/client.c b/src/util/client.c index 05f579b9f..664b06271 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -566,7 +566,9 @@ write_test (void *cls, size_t size, void *buf) | |||
566 | return 0; /* client disconnected */ | 566 | return 0; /* client disconnected */ |
567 | } | 567 | } |
568 | #if DEBUG_CLIENT | 568 | #if DEBUG_CLIENT |
569 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Transmitting TEST request.\n")); | 569 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
570 | "Transmitting `%s' request.\n", | ||
571 | "TEST"); | ||
570 | #endif | 572 | #endif |
571 | msg = (struct GNUNET_MessageHeader *) buf; | 573 | msg = (struct GNUNET_MessageHeader *) buf; |
572 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); | 574 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); |
@@ -642,7 +644,6 @@ GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched, | |||
642 | static size_t client_notify (void *cls, size_t size, void *buf); | 644 | static size_t client_notify (void *cls, size_t size, void *buf); |
643 | 645 | ||
644 | 646 | ||
645 | |||
646 | /** | 647 | /** |
647 | * This task is run if we should re-try connection to the | 648 | * This task is run if we should re-try connection to the |
648 | * service after a while. | 649 | * service after a while. |
@@ -657,6 +658,16 @@ client_delayed_retry (void *cls, | |||
657 | struct GNUNET_CLIENT_TransmitHandle *th = cls; | 658 | struct GNUNET_CLIENT_TransmitHandle *th = cls; |
658 | 659 | ||
659 | th->task = GNUNET_SCHEDULER_NO_TASK; | 660 | th->task = GNUNET_SCHEDULER_NO_TASK; |
661 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
662 | { | ||
663 | #if DEBUG_CLIENT | ||
664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
665 | "Transmission failed due to shutdown.\n"); | ||
666 | #endif | ||
667 | th->notify (th->notify_cls, 0, NULL); | ||
668 | GNUNET_free (th); | ||
669 | return; | ||
670 | } | ||
660 | th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, | 671 | th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, |
661 | th->size, | 672 | th->size, |
662 | GNUNET_TIME_absolute_get_remaining | 673 | GNUNET_TIME_absolute_get_remaining |
@@ -693,11 +704,19 @@ client_notify (void *cls, size_t size, void *buf) | |||
693 | th->sock->th = NULL; | 704 | th->sock->th = NULL; |
694 | if (buf == NULL) | 705 | if (buf == NULL) |
695 | { | 706 | { |
707 | // FIXME: need a way to check if the | ||
708 | // reason is SHUTDOWN (not timeout) and | ||
709 | // if so NOT retry! | ||
696 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); | 710 | delay = GNUNET_TIME_absolute_get_remaining (th->timeout); |
697 | delay.value /= 2; | 711 | delay.value /= 2; |
698 | if ((GNUNET_YES != th->auto_retry) || | 712 | if ((GNUNET_YES != th->auto_retry) || |
699 | (0 == --th->attempts_left) || (delay.value < 1)) | 713 | (0 == --th->attempts_left) || (delay.value < 1)) |
700 | { | 714 | { |
715 | #if DEBUG_CLIENT | ||
716 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
717 | "Transmission failed %u times, giving up.\n", | ||
718 | MAX_ATTEMPTS - th->attempts_left); | ||
719 | #endif | ||
701 | GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); | 720 | GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL)); |
702 | GNUNET_free (th); | 721 | GNUNET_free (th); |
703 | return 0; | 722 | return 0; |
@@ -708,6 +727,12 @@ client_notify (void *cls, size_t size, void *buf) | |||
708 | th->sock->service_name, th->sock->cfg); | 727 | th->sock->service_name, th->sock->cfg); |
709 | GNUNET_assert (NULL != th->sock->sock); | 728 | GNUNET_assert (NULL != th->sock->sock); |
710 | delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS); | 729 | delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS); |
730 | #if DEBUG_CLIENT | ||
731 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
732 | "Transmission failed %u times, trying again in %llums.\n", | ||
733 | MAX_ATTEMPTS - th->attempts_left, | ||
734 | (unsigned long long) delay.value); | ||
735 | #endif | ||
711 | th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched, | 736 | th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched, |
712 | delay, | 737 | delay, |
713 | &client_delayed_retry, th); | 738 | &client_delayed_retry, th); |
diff --git a/src/util/connection.c b/src/util/connection.c index 9bf2aa975..f88a7b5f2 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -1343,6 +1343,9 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1343 | /* no data ready for writing, terminate write loop */ | 1343 | /* no data ready for writing, terminate write loop */ |
1344 | return; | 1344 | return; |
1345 | } | 1345 | } |
1346 | GNUNET_assert (have <= sock->write_buffer_size); | ||
1347 | GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size); | ||
1348 | GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); | ||
1346 | RETRY: | 1349 | RETRY: |
1347 | ret = GNUNET_NETWORK_socket_send (sock->sock, | 1350 | ret = GNUNET_NETWORK_socket_send (sock->sock, |
1348 | &sock->write_buffer[sock-> | 1351 | &sock->write_buffer[sock-> |
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index 4dcabface..70f9128cc 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -516,7 +516,8 @@ main (int argc, char *const *argv) | |||
516 | ret = (GNUNET_OK == | 516 | ret = (GNUNET_OK == |
517 | GNUNET_SERVICE_run (argc, | 517 | GNUNET_SERVICE_run (argc, |
518 | argv, | 518 | argv, |
519 | "resolver", &run, NULL)) ? 0 : 1; | 519 | "resolver", GNUNET_SERVICE_OPTION_NONE, |
520 | &run, NULL)) ? 0 : 1; | ||
520 | 521 | ||
521 | while (head != NULL) | 522 | while (head != NULL) |
522 | { | 523 | { |
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 16f65b457..dc428e592 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -560,6 +560,13 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
560 | timeout = GNUNET_TIME_UNIT_ZERO; | 560 | timeout = GNUNET_TIME_UNIT_ZERO; |
561 | } | 561 | } |
562 | ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); | 562 | ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); |
563 | if (ret == GNUNET_SYSERR) | ||
564 | { | ||
565 | if (errno == EINTR) | ||
566 | continue; | ||
567 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select"); | ||
568 | break; | ||
569 | } | ||
563 | #ifndef MINGW | 570 | #ifndef MINGW |
564 | if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) | 571 | if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) |
565 | { | 572 | { |
@@ -584,13 +591,6 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) | |||
584 | _("Looks like we're busy waiting...\n")); | 591 | _("Looks like we're busy waiting...\n")); |
585 | sleep (1); /* mitigate */ | 592 | sleep (1); /* mitigate */ |
586 | } | 593 | } |
587 | if (ret == GNUNET_SYSERR) | ||
588 | { | ||
589 | if (errno == EINTR) | ||
590 | continue; | ||
591 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select"); | ||
592 | break; | ||
593 | } | ||
594 | check_ready (&sched, rs, ws); | 594 | check_ready (&sched, rs, ws); |
595 | run_ready (&sched); | 595 | run_ready (&sched); |
596 | } | 596 | } |
diff --git a/src/util/server.c b/src/util/server.c index ff9c8c192..af26d278c 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -123,20 +123,15 @@ struct GNUNET_SERVER_Handle | |||
123 | size_t maxbuf; | 123 | size_t maxbuf; |
124 | 124 | ||
125 | /** | 125 | /** |
126 | * Pipe used to signal shutdown of the server. | ||
127 | */ | ||
128 | struct GNUNET_DISK_PipeHandle *shutpipe; | ||
129 | |||
130 | /** | ||
131 | * Socket used to listen for new connections. Set to | 126 | * Socket used to listen for new connections. Set to |
132 | * "-1" by GNUNET_SERVER_destroy to initiate shutdown. | 127 | * "-1" by GNUNET_SERVER_destroy to initiate shutdown. |
133 | */ | 128 | */ |
134 | struct GNUNET_NETWORK_Handle *listen_socket; | 129 | struct GNUNET_NETWORK_Handle *listen_socket; |
135 | 130 | ||
136 | /** | 131 | /** |
137 | * Set to GNUNET_YES if we are shutting down. | 132 | * Task scheduled to do the listening. |
138 | */ | 133 | */ |
139 | int do_shutdown; | 134 | GNUNET_SCHEDULER_TaskIdentifier listen_task; |
140 | 135 | ||
141 | /** | 136 | /** |
142 | * Do we ignore messages of types that we do not | 137 | * Do we ignore messages of types that we do not |
@@ -262,42 +257,6 @@ struct GNUNET_SERVER_Client | |||
262 | 257 | ||
263 | 258 | ||
264 | /** | 259 | /** |
265 | * Server has been asked to shutdown, free resources. | ||
266 | */ | ||
267 | static void | ||
268 | destroy_server (struct GNUNET_SERVER_Handle *server) | ||
269 | { | ||
270 | struct GNUNET_SERVER_Client *pos; | ||
271 | struct HandlerList *hpos; | ||
272 | struct NotifyList *npos; | ||
273 | |||
274 | #if DEBUG_SERVER | ||
275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n"); | ||
276 | #endif | ||
277 | GNUNET_assert (server->listen_socket == NULL); | ||
278 | if (GNUNET_OK != GNUNET_DISK_pipe_close (server->shutpipe)) | ||
279 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "pipe-close"); | ||
280 | while (server->clients != NULL) | ||
281 | { | ||
282 | pos = server->clients; | ||
283 | server->clients = pos->next; | ||
284 | pos->server = NULL; | ||
285 | } | ||
286 | while (NULL != (hpos = server->handlers)) | ||
287 | { | ||
288 | server->handlers = hpos->next; | ||
289 | GNUNET_free (hpos); | ||
290 | } | ||
291 | while (NULL != (npos = server->disconnect_notify_list)) | ||
292 | { | ||
293 | server->disconnect_notify_list = npos->next; | ||
294 | GNUNET_free (npos); | ||
295 | } | ||
296 | GNUNET_free (server); | ||
297 | } | ||
298 | |||
299 | |||
300 | /** | ||
301 | * Scheduler says our listen socket is ready. | 260 | * Scheduler says our listen socket is ready. |
302 | * Process it! | 261 | * Process it! |
303 | */ | 262 | */ |
@@ -309,26 +268,23 @@ process_listen_socket (void *cls, | |||
309 | struct GNUNET_CONNECTION_Handle *sock; | 268 | struct GNUNET_CONNECTION_Handle *sock; |
310 | struct GNUNET_SERVER_Client *client; | 269 | struct GNUNET_SERVER_Client *client; |
311 | struct GNUNET_NETWORK_FDSet *r; | 270 | struct GNUNET_NETWORK_FDSet *r; |
312 | const struct GNUNET_DISK_FileHandle *shutpipe; | ||
313 | 271 | ||
314 | if ((server->do_shutdown) || | 272 | server->listen_task = GNUNET_SCHEDULER_NO_TASK; |
315 | ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)) | 273 | r = GNUNET_NETWORK_fdset_create (); |
274 | GNUNET_NETWORK_fdset_set (r, server->listen_socket); | ||
275 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
316 | { | 276 | { |
317 | /* shutdown was initiated */ | 277 | server->listen_task = GNUNET_SCHEDULER_add_select (server->sched, |
318 | GNUNET_assert (server->listen_socket != NULL); | 278 | GNUNET_SCHEDULER_PRIORITY_HIGH, |
319 | GNUNET_break (GNUNET_OK == | 279 | GNUNET_SCHEDULER_NO_TASK, |
320 | GNUNET_NETWORK_socket_close (server->listen_socket)); | 280 | GNUNET_TIME_UNIT_FOREVER_REL, |
321 | server->listen_socket = NULL; | 281 | r, NULL, &process_listen_socket, |
322 | if (server->do_shutdown) | 282 | server); |
323 | destroy_server (server); | 283 | GNUNET_NETWORK_fdset_destroy (r); |
324 | return; | 284 | return; /* ignore shutdown, someone else will take care of it! */ |
325 | } | 285 | } |
326 | shutpipe = GNUNET_DISK_pipe_handle (server->shutpipe, | ||
327 | GNUNET_DISK_PIPE_END_READ); | ||
328 | GNUNET_assert (GNUNET_NETWORK_fdset_isset | 286 | GNUNET_assert (GNUNET_NETWORK_fdset_isset |
329 | (tc->read_ready, server->listen_socket)); | 287 | (tc->read_ready, server->listen_socket)); |
330 | GNUNET_assert (!GNUNET_NETWORK_fdset_handle_isset | ||
331 | (tc->read_ready, shutpipe)); | ||
332 | sock = | 288 | sock = |
333 | GNUNET_CONNECTION_create_from_accept (tc->sched, server->access, | 289 | GNUNET_CONNECTION_create_from_accept (tc->sched, server->access, |
334 | server->access_cls, | 290 | server->access_cls, |
@@ -345,14 +301,11 @@ process_listen_socket (void *cls, | |||
345 | GNUNET_SERVER_client_drop (client); | 301 | GNUNET_SERVER_client_drop (client); |
346 | } | 302 | } |
347 | /* listen for more! */ | 303 | /* listen for more! */ |
348 | r = GNUNET_NETWORK_fdset_create (); | 304 | server->listen_task = GNUNET_SCHEDULER_add_select (server->sched, |
349 | GNUNET_NETWORK_fdset_set (r, server->listen_socket); | 305 | GNUNET_SCHEDULER_PRIORITY_HIGH, |
350 | GNUNET_NETWORK_fdset_handle_set (r, shutpipe); | 306 | GNUNET_SCHEDULER_NO_TASK, |
351 | GNUNET_SCHEDULER_add_select (server->sched, | 307 | GNUNET_TIME_UNIT_FOREVER_REL, |
352 | GNUNET_SCHEDULER_PRIORITY_HIGH, | 308 | r, NULL, &process_listen_socket, server); |
353 | GNUNET_SCHEDULER_NO_TASK, | ||
354 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
355 | r, NULL, &process_listen_socket, server); | ||
356 | GNUNET_NETWORK_fdset_destroy (r); | 309 | GNUNET_NETWORK_fdset_destroy (r); |
357 | } | 310 | } |
358 | 311 | ||
@@ -454,12 +407,6 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, | |||
454 | return NULL; | 407 | return NULL; |
455 | } | 408 | } |
456 | ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle)); | 409 | ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle)); |
457 | if (NULL == (ret->shutpipe = GNUNET_DISK_pipe (GNUNET_NO))) | ||
458 | { | ||
459 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsock)); | ||
460 | GNUNET_free (ret); | ||
461 | return NULL; | ||
462 | } | ||
463 | ret->sched = sched; | 410 | ret->sched = sched; |
464 | ret->maxbuf = maxbuf; | 411 | ret->maxbuf = maxbuf; |
465 | ret->idle_timeout = idle_timeout; | 412 | ret->idle_timeout = idle_timeout; |
@@ -471,14 +418,11 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, | |||
471 | { | 418 | { |
472 | r = GNUNET_NETWORK_fdset_create (); | 419 | r = GNUNET_NETWORK_fdset_create (); |
473 | GNUNET_NETWORK_fdset_set (r, ret->listen_socket); | 420 | GNUNET_NETWORK_fdset_set (r, ret->listen_socket); |
474 | GNUNET_NETWORK_fdset_handle_set (r, | 421 | ret->listen_task = GNUNET_SCHEDULER_add_select (sched, |
475 | GNUNET_DISK_pipe_handle (ret->shutpipe, | 422 | GNUNET_SCHEDULER_PRIORITY_HIGH, |
476 | GNUNET_DISK_PIPE_END_READ)); | 423 | GNUNET_SCHEDULER_NO_TASK, |
477 | GNUNET_SCHEDULER_add_select (sched, | 424 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, |
478 | GNUNET_SCHEDULER_PRIORITY_HIGH, | 425 | &process_listen_socket, ret); |
479 | GNUNET_SCHEDULER_NO_TASK, | ||
480 | GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, | ||
481 | &process_listen_socket, ret); | ||
482 | GNUNET_NETWORK_fdset_destroy (r); | 426 | GNUNET_NETWORK_fdset_destroy (r); |
483 | } | 427 | } |
484 | return ret; | 428 | return ret; |
@@ -491,18 +435,40 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, | |||
491 | void | 435 | void |
492 | GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) | 436 | GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) |
493 | { | 437 | { |
494 | static char c; | 438 | struct GNUNET_SERVER_Client *pos; |
495 | 439 | struct HandlerList *hpos; | |
496 | GNUNET_assert (s->do_shutdown == GNUNET_NO); | 440 | struct NotifyList *npos; |
497 | s->do_shutdown = GNUNET_YES; | 441 | |
498 | if (s->listen_socket == NULL) | 442 | #if DEBUG_SERVER |
499 | destroy_server (s); | 443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n"); |
500 | else | 444 | #endif |
501 | GNUNET_break (1 == | 445 | if (GNUNET_SCHEDULER_NO_TASK != s->listen_task) |
502 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle | 446 | { |
503 | (s->shutpipe, | 447 | GNUNET_SCHEDULER_cancel (s->sched, |
504 | GNUNET_DISK_PIPE_END_WRITE), &c, | 448 | s->listen_task); |
505 | sizeof (c))); | 449 | s->listen_task = GNUNET_SCHEDULER_NO_TASK; |
450 | } | ||
451 | GNUNET_break (GNUNET_OK == | ||
452 | GNUNET_NETWORK_socket_close (s->listen_socket)); | ||
453 | s->listen_socket = NULL; | ||
454 | while (s->clients != NULL) | ||
455 | { | ||
456 | pos = s->clients; | ||
457 | s->clients = pos->next; | ||
458 | pos->server = NULL; | ||
459 | } | ||
460 | while (NULL != (hpos = s->handlers)) | ||
461 | { | ||
462 | s->handlers = hpos->next; | ||
463 | GNUNET_free (hpos); | ||
464 | } | ||
465 | while (NULL != (npos = s->disconnect_notify_list)) | ||
466 | { | ||
467 | s->disconnect_notify_list = npos->next; | ||
468 | GNUNET_free (npos); | ||
469 | } | ||
470 | GNUNET_free (s); | ||
471 | |||
506 | } | 472 | } |
507 | 473 | ||
508 | 474 | ||
diff --git a/src/util/service.c b/src/util/service.c index 173c0f566..60da8788f 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -514,6 +514,11 @@ struct GNUNET_SERVICE_Context | |||
514 | int allow_shutdown; | 514 | int allow_shutdown; |
515 | 515 | ||
516 | /** | 516 | /** |
517 | * Our options. | ||
518 | */ | ||
519 | enum GNUNET_SERVICE_Options options; | ||
520 | |||
521 | /** | ||
517 | * Length of addr. | 522 | * Length of addr. |
518 | */ | 523 | */ |
519 | socklen_t addrlen; | 524 | socklen_t addrlen; |
@@ -1108,10 +1113,15 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1108 | sctx->ret = GNUNET_SYSERR; | 1113 | sctx->ret = GNUNET_SYSERR; |
1109 | return; | 1114 | return; |
1110 | } | 1115 | } |
1111 | GNUNET_SCHEDULER_add_delayed (tc->sched, | 1116 | if (0 == (sctx->options & GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN)) |
1112 | GNUNET_TIME_UNIT_FOREVER_REL, | 1117 | { |
1113 | &shutdown_task, | 1118 | /* install a task that will kill the server |
1114 | sctx->server); | 1119 | process if the scheduler ever gets a shutdown signal */ |
1120 | GNUNET_SCHEDULER_add_delayed (tc->sched, | ||
1121 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1122 | &shutdown_task, | ||
1123 | sctx->server); | ||
1124 | } | ||
1115 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); | 1125 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); |
1116 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); | 1126 | memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); |
1117 | i = 0; | 1127 | i = 0; |
@@ -1277,6 +1287,7 @@ pid_file_delete (struct GNUNET_SERVICE_Context *sctx) | |||
1277 | * @param argc number of command line arguments | 1287 | * @param argc number of command line arguments |
1278 | * @param argv command line arguments | 1288 | * @param argv command line arguments |
1279 | * @param serviceName our service name | 1289 | * @param serviceName our service name |
1290 | * @param opt service options | ||
1280 | * @param task main task of the service | 1291 | * @param task main task of the service |
1281 | * @param task_cls closure for task | 1292 | * @param task_cls closure for task |
1282 | * @return GNUNET_SYSERR on error, GNUNET_OK | 1293 | * @return GNUNET_SYSERR on error, GNUNET_OK |
@@ -1286,6 +1297,7 @@ int | |||
1286 | GNUNET_SERVICE_run (int argc, | 1297 | GNUNET_SERVICE_run (int argc, |
1287 | char *const *argv, | 1298 | char *const *argv, |
1288 | const char *serviceName, | 1299 | const char *serviceName, |
1300 | enum GNUNET_SERVICE_Options opt, | ||
1289 | GNUNET_SERVICE_Main task, | 1301 | GNUNET_SERVICE_Main task, |
1290 | void *task_cls) | 1302 | void *task_cls) |
1291 | { | 1303 | { |
@@ -1311,6 +1323,7 @@ GNUNET_SERVICE_run (int argc, | |||
1311 | loglev = GNUNET_strdup ("WARNING"); | 1323 | loglev = GNUNET_strdup ("WARNING"); |
1312 | cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_DAEMON_CONFIG_FILE); | 1324 | cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_DAEMON_CONFIG_FILE); |
1313 | memset (&sctx, 0, sizeof (sctx)); | 1325 | memset (&sctx, 0, sizeof (sctx)); |
1326 | sctx.options = opt; | ||
1314 | sctx.ready_confirm_fd = -1; | 1327 | sctx.ready_confirm_fd = -1; |
1315 | sctx.ret = GNUNET_OK; | 1328 | sctx.ret = GNUNET_OK; |
1316 | sctx.timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1329 | sctx.timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c index 9e6a29ea4..7a23855c5 100644 --- a/src/util/test_container_heap.c +++ b/src/util/test_container_heap.c | |||
@@ -45,6 +45,7 @@ iterator_callback (void *cls, void *element, GNUNET_CONTAINER_HeapCost cost) | |||
45 | return GNUNET_OK; | 45 | return GNUNET_OK; |
46 | } | 46 | } |
47 | 47 | ||
48 | |||
48 | int | 49 | int |
49 | main (int argc, char **argv) | 50 | main (int argc, char **argv) |
50 | { | 51 | { |
@@ -68,23 +69,23 @@ main (int argc, char **argv) | |||
68 | neighbor6.cost = 30; | 69 | neighbor6.cost = 30; |
69 | 70 | ||
70 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor1, neighbor1.cost); | 71 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor1, neighbor1.cost); |
71 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 72 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
72 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor2, neighbor2.cost); | 73 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor2, neighbor2.cost); |
73 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 74 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
74 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor3, neighbor3.cost); | 75 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor3, neighbor3.cost); |
75 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 76 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
76 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor4, neighbor4.cost); | 77 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor4, neighbor4.cost); |
77 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 78 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
78 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor5, neighbor5.cost); | 79 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor5, neighbor5.cost); |
79 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 80 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
80 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor6, neighbor6.cost); | 81 | GNUNET_CONTAINER_heap_insert (myHeap, &neighbor6, neighbor6.cost); |
81 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 82 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
82 | GNUNET_CONTAINER_heap_remove_node (myHeap, &neighbor5); | 83 | GNUNET_CONTAINER_heap_remove_node (myHeap, &neighbor5); |
83 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 84 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
84 | GNUNET_CONTAINER_heap_remove_root (myHeap); | 85 | GNUNET_CONTAINER_heap_remove_root (myHeap); |
85 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 86 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
86 | GNUNET_CONTAINER_heap_update_cost (myHeap, &neighbor6, 200); | 87 | GNUNET_CONTAINER_heap_update_cost (myHeap, &neighbor6, 200); |
87 | GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); | 88 | GNUNET_CONTAINER_heap_iterate (myHeap, &iterator_callback, NULL); |
88 | GNUNET_CONTAINER_heap_destroy (myHeap); | 89 | GNUNET_CONTAINER_heap_destroy (myHeap); |
89 | 90 | ||
90 | return 0; | 91 | return 0; |
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c index 30fc34b08..7b35647ea 100644 --- a/src/util/test_server_disconnect.c +++ b/src/util/test_server_disconnect.c | |||
@@ -120,8 +120,11 @@ disconnect_notify (void *cls, const struct GNUNET_MessageHeader *msg) | |||
120 | GNUNET_assert (ok == 7); | 120 | GNUNET_assert (ok == 7); |
121 | ok = 0; | 121 | ok = 0; |
122 | GNUNET_CLIENT_disconnect (client); | 122 | GNUNET_CLIENT_disconnect (client); |
123 | GNUNET_SCHEDULER_shutdown (sched); | 123 | client = NULL; |
124 | GNUNET_SERVER_destroy (server); | ||
125 | server = NULL; | ||
124 | GNUNET_CONFIGURATION_destroy (cfg); | 126 | GNUNET_CONFIGURATION_destroy (cfg); |
127 | cfg = NULL; | ||
125 | } | 128 | } |
126 | 129 | ||
127 | 130 | ||
diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c index 860ed3837..52b0addfa 100644 --- a/src/util/test_server_with_client.c +++ b/src/util/test_server_with_client.c | |||
@@ -103,6 +103,16 @@ recv_cb (void *cls, | |||
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
106 | static void | ||
107 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
108 | { | ||
109 | GNUNET_SERVER_destroy (server); | ||
110 | server = NULL; | ||
111 | GNUNET_CONFIGURATION_destroy (cfg); | ||
112 | cfg = NULL; | ||
113 | } | ||
114 | |||
115 | |||
106 | /** | 116 | /** |
107 | * Functions with this signature are called whenever a client | 117 | * Functions with this signature are called whenever a client |
108 | * is disconnected on the network level. | 118 | * is disconnected on the network level. |
@@ -115,8 +125,9 @@ notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
115 | { | 125 | { |
116 | GNUNET_assert (ok == 5); | 126 | GNUNET_assert (ok == 5); |
117 | ok = 0; | 127 | ok = 0; |
118 | GNUNET_SCHEDULER_shutdown (sched); | 128 | GNUNET_SCHEDULER_add_delayed (sched, |
119 | GNUNET_CONFIGURATION_destroy (cfg); | 129 | GNUNET_TIME_UNIT_ZERO, |
130 | &clean_up, NULL); | ||
120 | } | 131 | } |
121 | 132 | ||
122 | 133 | ||
diff --git a/src/util/test_service.c b/src/util/test_service.c index fa35da6e9..ab7011526 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -152,6 +152,7 @@ check () | |||
152 | GNUNET_SERVICE_run (5, | 152 | GNUNET_SERVICE_run (5, |
153 | argv, | 153 | argv, |
154 | "test_service", | 154 | "test_service", |
155 | GNUNET_SERVICE_OPTION_NONE, | ||
155 | &runner, &ok)); | 156 | &runner, &ok)); |
156 | GNUNET_assert (0 == ok); | 157 | GNUNET_assert (0 == ok); |
157 | return ok; | 158 | return ok; |
@@ -213,6 +214,7 @@ check6 () | |||
213 | GNUNET_SERVICE_run (5, | 214 | GNUNET_SERVICE_run (5, |
214 | argv, | 215 | argv, |
215 | "test_service6", | 216 | "test_service6", |
217 | GNUNET_SERVICE_OPTION_NONE, | ||
216 | &runner6, &ok)); | 218 | &runner6, &ok)); |
217 | GNUNET_assert (0 == ok); | 219 | GNUNET_assert (0 == ok); |
218 | return ok; | 220 | return ok; |
@@ -245,6 +247,7 @@ check6d () | |||
245 | GNUNET_SERVICE_run (6, | 247 | GNUNET_SERVICE_run (6, |
246 | argv, | 248 | argv, |
247 | "test_service6", | 249 | "test_service6", |
250 | GNUNET_SERVICE_OPTION_NONE, | ||
248 | &runner6, &ok)); | 251 | &runner6, &ok)); |
249 | GNUNET_break (0 == ok); | 252 | GNUNET_break (0 == ok); |
250 | return ok; | 253 | return ok; |