diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-05-06 09:54:08 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-05-06 09:54:08 +0000 |
commit | 1948cedcb5e7c5017dcd18ef087f0f7e5aa5f27f (patch) | |
tree | 53048b78f1bec588db3c7f7d72a35e483ccf2795 /src/arm/gnunet-arm.c | |
parent | 031972ecd7ef2a767cbe8caf3c6fb649567a6b0d (diff) | |
download | gnunet-1948cedcb5e7c5017dcd18ef087f0f7e5aa5f27f.tar.gz gnunet-1948cedcb5e7c5017dcd18ef087f0f7e5aa5f27f.zip |
main change for gnunet-arm is that gnunet-arm now gets proper confirmation when called to start or stop services. This means that calling gnunet-arm to stop/start a process will return 0 only if the process is stopped/started. For gnunet-service-arm, this is implemented by leaking the client connection socket on a shutdown request, so that it is only closed when the arm service actually shuts down (indicating everything is really down).
Diffstat (limited to 'src/arm/gnunet-arm.c')
-rw-r--r-- | src/arm/gnunet-arm.c | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 2b438b30d..652c74e11 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c | |||
@@ -31,9 +31,16 @@ | |||
31 | #include "gnunet_time_lib.h" | 31 | #include "gnunet_time_lib.h" |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Timeout for all operations. | 34 | * Timeout for stopping services. Long to give some services a real chance. |
35 | */ | 35 | */ |
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50) | 36 | #define STOP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) |
37 | |||
38 | /** | ||
39 | * Timeout for starting services, very short because of the strange way start works | ||
40 | * (by checking if running before starting, so really this time is always waited on | ||
41 | * startup (annoying)). | ||
42 | */ | ||
43 | #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 50) | ||
37 | 44 | ||
38 | /** | 45 | /** |
39 | * Set if we are to shutdown all services (including ARM). | 46 | * Set if we are to shutdown all services (including ARM). |
@@ -46,6 +53,11 @@ static int end; | |||
46 | static int start; | 53 | static int start; |
47 | 54 | ||
48 | /** | 55 | /** |
56 | * Set if we are to stop/start default services (including ARM). | ||
57 | */ | ||
58 | static int restart; | ||
59 | |||
60 | /** | ||
49 | * Set if we should delete configuration and temp directory on exit. | 61 | * Set if we should delete configuration and temp directory on exit. |
50 | */ | 62 | */ |
51 | static int delete; | 63 | static int delete; |
@@ -134,17 +146,31 @@ confirm_cb (void *cls, int success) | |||
134 | case GNUNET_OK: | 146 | case GNUNET_OK: |
135 | if (quiet != GNUNET_YES) | 147 | if (quiet != GNUNET_YES) |
136 | fprintf(stdout, _("Service `%s' is now running.\n"), service); | 148 | fprintf(stdout, _("Service `%s' is now running.\n"), service); |
149 | if ((phase - 1 != 2) && (phase - 1 != 3)) | ||
150 | { | ||
151 | if (quiet != GNUNET_YES) | ||
152 | fprintf(stdout, _("Failed to stop service `%s'!\n"), service); | ||
153 | ret = 1; | ||
154 | } | ||
137 | break; | 155 | break; |
138 | case GNUNET_NO: | 156 | case GNUNET_NO: |
139 | if (quiet != GNUNET_YES) | 157 | if (quiet != GNUNET_YES) |
140 | fprintf(stdout, _("Service `%s' is not running.\n"), service); | 158 | fprintf(stdout, _("Service `%s' is not running.\n"), service); |
159 | if ((phase - 1 != 0) && (phase - 1 != 1)) | ||
160 | { | ||
161 | if (quiet != GNUNET_YES) | ||
162 | fprintf(stdout, _("Failed to start service `%s'!\n"), service); | ||
163 | ret = 1; | ||
164 | } | ||
141 | break; | 165 | break; |
142 | case GNUNET_SYSERR: | 166 | case GNUNET_SYSERR: |
143 | if (quiet != GNUNET_YES) | 167 | if (quiet != GNUNET_YES) |
144 | fprintf(stdout, | 168 | fprintf(stdout, |
145 | _("Error updating service `%s': ARM not running\n"), service); | 169 | _("Some error communicating with service `%s'.\n"), service); |
170 | ret = 1; | ||
146 | break; | 171 | break; |
147 | } | 172 | } |
173 | |||
148 | GNUNET_SCHEDULER_add_continuation (sched, | 174 | GNUNET_SCHEDULER_add_continuation (sched, |
149 | &cps_loop, | 175 | &cps_loop, |
150 | NULL, | 176 | NULL, |
@@ -260,38 +286,63 @@ cps_loop (void *cls, | |||
260 | case 0: | 286 | case 0: |
261 | if (term != NULL) | 287 | if (term != NULL) |
262 | { | 288 | { |
263 | GNUNET_ARM_stop_service (h, term, TIMEOUT, &confirm_cb, term); | 289 | GNUNET_ARM_stop_service (h, term, STOP_TIMEOUT, &confirm_cb, term); |
264 | return; | 290 | return; |
265 | } | 291 | } |
266 | break; | 292 | break; |
267 | case 1: | 293 | case 1: |
268 | if (end) | 294 | if ((end) || (restart)) |
269 | { | 295 | { |
270 | GNUNET_ARM_stop_service (h, "arm", TIMEOUT, &confirm_cb, "arm"); | 296 | GNUNET_ARM_stop_service (h, "arm", STOP_TIMEOUT, &confirm_cb, "arm"); |
271 | return; | 297 | return; |
272 | } | 298 | } |
273 | break; | 299 | break; |
274 | case 2: | 300 | case 2: |
275 | if (start) | 301 | if (start) |
276 | { | 302 | { |
277 | GNUNET_ARM_start_service (h, "arm", TIMEOUT, &confirm_cb, "arm"); | 303 | GNUNET_ARM_start_service (h, "arm", START_TIMEOUT, &confirm_cb, "arm"); |
278 | return; | 304 | return; |
279 | } | 305 | } |
280 | break; | 306 | break; |
281 | case 3: | 307 | case 3: |
282 | if (init != NULL) | 308 | if (init != NULL) |
283 | { | 309 | { |
284 | GNUNET_ARM_start_service (h, init, TIMEOUT, &confirm_cb, init); | 310 | GNUNET_ARM_start_service (h, init, START_TIMEOUT, &confirm_cb, init); |
285 | return; | 311 | return; |
286 | } | 312 | } |
287 | break; | 313 | break; |
288 | case 4: | 314 | case 4: |
289 | if (test != NULL) | 315 | if (test != NULL) |
290 | { | 316 | { |
291 | GNUNET_CLIENT_service_test (sched, test, cfg, TIMEOUT, &confirm_task, test); | 317 | GNUNET_CLIENT_service_test (sched, test, cfg, START_TIMEOUT, &confirm_task, test); |
292 | return; | 318 | return; |
293 | } | 319 | } |
294 | break; | 320 | break; |
321 | case 5: | ||
322 | if (restart) /* FIXME: | ||
323 | * Restart should be a legal option but this is a hack. | ||
324 | * The proper thing to do would be have gnunet-service-arm | ||
325 | * signal us when actually shut down, and then initiate | ||
326 | * the startup. Instead we just sleep for two seconds | ||
327 | * and hope that's enough time for shutdown to have happened. | ||
328 | */ | ||
329 | { | ||
330 | GNUNET_ARM_disconnect (h); | ||
331 | phase = 0; | ||
332 | end = 0; | ||
333 | start = 1; | ||
334 | restart = 0; | ||
335 | h = GNUNET_ARM_connect (cfg, sched, NULL); | ||
336 | if (h == NULL) | ||
337 | { | ||
338 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
339 | _("Fatal error initializing ARM API.\n")); | ||
340 | ret = 1; | ||
341 | return; | ||
342 | } | ||
343 | GNUNET_SCHEDULER_add_now(sched, &cps_loop, NULL); | ||
344 | return; | ||
345 | } | ||
295 | default: /* last phase */ | 346 | default: /* last phase */ |
296 | GNUNET_ARM_disconnect (h); | 347 | GNUNET_ARM_disconnect (h); |
297 | if ((end == GNUNET_YES) && (delete == GNUNET_YES)) | 348 | if ((end == GNUNET_YES) && (delete == GNUNET_YES)) |
@@ -314,6 +365,8 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
314 | GNUNET_YES, &GNUNET_GETOPT_set_string, &term}, | 365 | GNUNET_YES, &GNUNET_GETOPT_set_string, &term}, |
315 | {'s', "start", NULL, gettext_noop ("start all GNUnet default services"), | 366 | {'s', "start", NULL, gettext_noop ("start all GNUnet default services"), |
316 | GNUNET_NO, &GNUNET_GETOPT_set_one, &start}, | 367 | GNUNET_NO, &GNUNET_GETOPT_set_one, &start}, |
368 | {'r', "restart", NULL, gettext_noop ("stop and start all GNUnet default services"), | ||
369 | GNUNET_NO, &GNUNET_GETOPT_set_one, &restart}, | ||
317 | {'t', "test", "SERVICE", | 370 | {'t', "test", "SERVICE", |
318 | gettext_noop ("test if a particular service is running"), | 371 | gettext_noop ("test if a particular service is running"), |
319 | GNUNET_YES, &GNUNET_GETOPT_set_string, &test}, | 372 | GNUNET_YES, &GNUNET_GETOPT_set_string, &test}, |