aboutsummaryrefslogtreecommitdiff
path: root/src/arm/gnunet-arm.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-27 19:01:04 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-27 19:01:04 +0000
commit383eec1895fff4a83f26bb8244d86571dd5baef9 (patch)
treedc6eccf68932c71785ee86d688ebebeda2ac4025 /src/arm/gnunet-arm.c
parent195267a6ac380d106d9409aa296885251d102c8e (diff)
downloadgnunet-383eec1895fff4a83f26bb8244d86571dd5baef9.tar.gz
gnunet-383eec1895fff4a83f26bb8244d86571dd5baef9.zip
reducing error messages about missing configuration options by introducing new helper functions to print them uniformly
Diffstat (limited to 'src/arm/gnunet-arm.c')
-rw-r--r--src/arm/gnunet-arm.c208
1 files changed, 104 insertions, 104 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index d84de1c7a..c155577d0 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -125,7 +125,6 @@ static unsigned int phase;
125 */ 125 */
126static struct GNUNET_TIME_Relative timeout; 126static struct GNUNET_TIME_Relative timeout;
127 127
128
129/** 128/**
130 * Do we want to give our stdout to gnunet-service-arm? 129 * Do we want to give our stdout to gnunet-service-arm?
131 */ 130 */
@@ -136,6 +135,7 @@ static unsigned int no_stdout = 0;
136 */ 135 */
137static unsigned int no_stderr = 0; 136static unsigned int no_stderr = 0;
138 137
138
139/** 139/**
140 * Main continuation-passing-style loop. Runs the various 140 * Main continuation-passing-style loop. Runs the various
141 * jobs that we've been asked to do in order. 141 * jobs that we've been asked to do in order.
@@ -210,6 +210,7 @@ confirm_cb (void *cls,
210 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 210 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
211} 211}
212 212
213
213/** 214/**
214 * Callback invoked with the list of running services. 215 * Callback invoked with the list of running services.
215 * Reports to the user and then runs the next phase in the FSM. 216 * Reports to the user and then runs the next phase in the FSM.
@@ -234,6 +235,7 @@ list_cb (void *cls, int result, unsigned int count, const char *const*list)
234 FPRINTF (stdout, "%s\n", list[i]); 235 FPRINTF (stdout, "%s\n", list[i]);
235} 236}
236 237
238
237/** 239/**
238 * Main function that will be run by the scheduler. 240 * Main function that will be run by the scheduler.
239 * 241 *
@@ -250,25 +252,23 @@ run (void *cls, char *const *args, const char *cfgfile,
250 config_file = cfgfile; 252 config_file = cfgfile;
251 if (GNUNET_CONFIGURATION_get_value_string 253 if (GNUNET_CONFIGURATION_get_value_string
252 (cfg, "PATHS", "SERVICEHOME", &dir) != GNUNET_OK) 254 (cfg, "PATHS", "SERVICEHOME", &dir) != GNUNET_OK)
253 { 255 {
254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 256 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
255 _ 257 "PATHS", "SERVICEHOME");
256 ("Fatal configuration error: `%s' option in section `%s' missing.\n"), 258 return;
257 "SERVICEHOME", "PATHS");
258 return;
259 }
260 h = GNUNET_ARM_connect (cfg, NULL);
261 if (h == NULL)
262 {
263 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
264 _("Fatal error initializing ARM API.\n"));
265 ret = 1;
266 return;
267 } 259 }
260 if (NULL == (h = GNUNET_ARM_connect (cfg, NULL)))
261 {
262 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
263 _("Fatal error initializing ARM API.\n"));
264 ret = 1;
265 return;
266 }
268 GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL, 267 GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
269 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 268 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
270} 269}
271 270
271
272/** 272/**
273 * Attempts to delete configuration file and SERVICEHOME 273 * Attempts to delete configuration file and SERVICEHOME
274 * on arm shutdown provided the end and delete options 274 * on arm shutdown provided the end and delete options
@@ -295,6 +295,7 @@ delete_files ()
295 } 295 }
296} 296}
297 297
298
298/** 299/**
299 * Main continuation-passing-style loop. Runs the various 300 * Main continuation-passing-style loop. Runs the various
300 * jobs that we've been asked to do in order. 301 * jobs that we've been asked to do in order.
@@ -306,99 +307,98 @@ static void
306cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 307cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
307{ 308{
308 while (1) 309 while (1)
310 {
311 switch (phase++)
309 { 312 {
310 switch (phase++) 313 case 0:
314 if (NULL != term)
315 {
316 GNUNET_ARM_stop_service (h, term,
317 (0 ==
318 timeout.rel_value) ? STOP_TIMEOUT :
319 timeout, &confirm_cb, term);
320 return;
321 }
322 break;
323 case 1:
324 if ((end) || (restart))
325 {
326 GNUNET_ARM_stop_service (h, "arm",
327 (0 ==
328 timeout.rel_value) ? STOP_TIMEOUT_ARM
329 : timeout, &confirm_cb, "arm");
330 return;
331 }
332 break;
333 case 2:
334 if (start)
335 {
336 GNUNET_ARM_start_service (h, "arm",
337 (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
338 (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
339 (0 ==
340 timeout.rel_value) ? START_TIMEOUT :
341 timeout, &confirm_cb, "arm");
342 return;
343 }
344 break;
345 case 3:
346 if (NULL != init)
347 {
348 GNUNET_ARM_start_service (h, init,
349 (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
350 (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
351 (0 ==
352 timeout.rel_value) ? START_TIMEOUT :
353 timeout, &confirm_cb, init);
354 return;
355 }
356 break;
357 case 4:
358 if (restart)
359 {
360 GNUNET_ARM_disconnect (h);
361 phase = 0;
362 end = 0;
363 start = 1;
364 restart = 0;
365 if (NULL == (h = GNUNET_ARM_connect (cfg, NULL)))
311 { 366 {
312 case 0: 367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
313 if (term != NULL) 368 _("Fatal error initializing ARM API.\n"));
314 { 369 ret = 1;
315 GNUNET_ARM_stop_service (h, term,
316 (0 ==
317 timeout.rel_value) ? STOP_TIMEOUT :
318 timeout, &confirm_cb, term);
319 return;
320 }
321 break;
322 case 1:
323 if ((end) || (restart))
324 {
325 GNUNET_ARM_stop_service (h, "arm",
326 (0 ==
327 timeout.rel_value) ? STOP_TIMEOUT_ARM
328 : timeout, &confirm_cb, "arm");
329 return;
330 }
331 break;
332 case 2:
333 if (start)
334 {
335 GNUNET_ARM_start_service (h, "arm",
336 (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
337 (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
338 (0 ==
339 timeout.rel_value) ? START_TIMEOUT :
340 timeout, &confirm_cb, "arm");
341 return;
342 }
343 break;
344 case 3:
345 if (init != NULL)
346 {
347 GNUNET_ARM_start_service (h, init,
348 (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
349 (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
350 (0 ==
351 timeout.rel_value) ? START_TIMEOUT :
352 timeout, &confirm_cb, init);
353 return;
354 }
355 break;
356 case 4:
357 if (restart)
358 {
359 GNUNET_ARM_disconnect (h);
360 phase = 0;
361 end = 0;
362 start = 1;
363 restart = 0;
364 h = GNUNET_ARM_connect (cfg, NULL);
365 if (NULL == h)
366 {
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
368 _("Fatal error initializing ARM API.\n"));
369 ret = 1;
370 return;
371 }
372 GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
373 return;
374 }
375 break;
376 case 5:
377 if (list) {
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
379 "Going to list all running services controlled by ARM.\n");
380
381 if (NULL == h)
382 {
383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
384 _("Fatal error initializing ARM API.\n"));
385 return;
386 }
387
388 GNUNET_ARM_list_running_services (h,
389 (0 ==
390 timeout.rel_value) ? LIST_TIMEOUT :
391 timeout, &list_cb, NULL);
392 return;
393 }
394 /* Fall through */
395 default: /* last phase */
396 GNUNET_ARM_disconnect (h);
397 if ((end == GNUNET_YES) && (delete == GNUNET_YES))
398 delete_files ();
399 return; 370 return;
400 } 371 }
372 GNUNET_SCHEDULER_add_now (&cps_loop, NULL);
373 return;
374 }
375 break;
376 case 5:
377 if (list)
378 {
379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
380 "Going to list all running services controlled by ARM.\n");
381
382 if (NULL == h)
383 {
384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
385 _("Fatal error initializing ARM API.\n"));
386 return;
387 }
388 GNUNET_ARM_list_running_services (h,
389 (0 ==
390 timeout.rel_value) ? LIST_TIMEOUT :
391 timeout, &list_cb, NULL);
392 return;
393 }
394 /* Fall through */
395 default: /* last phase */
396 GNUNET_ARM_disconnect (h);
397 if ((end == GNUNET_YES) && (delete == GNUNET_YES))
398 delete_files ();
399 return;
401 } 400 }
401 }
402} 402}
403 403
404 404