aboutsummaryrefslogtreecommitdiff
path: root/src/arm/gnunet-arm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/gnunet-arm.c')
-rw-r--r--src/arm/gnunet-arm.c294
1 files changed, 155 insertions, 139 deletions
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 */
141static void 141static void cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
142cps_loop (void *cls,
143 const struct GNUNET_SCHEDULER_TaskContext *tc);
144 142
145 143
146/** 144/**
@@ -154,39 +152,39 @@ static void
154confirm_cb (void *cls, int success) 152confirm_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)
229static void 226static void
230run (void *cls, 227run (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 */
263static void delete_files() 259static void
260delete_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 */
288static void 287static void
289cps_loop (void *cls, 288cps_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 */