aboutsummaryrefslogtreecommitdiff
path: root/src/arm/gnunet-service-arm.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-06-16 10:38:29 +0200
committerChristian Grothoff <christian@grothoff.org>2018-06-16 10:38:29 +0200
commit50c2b2a28aba97efbbd51658f18afda6d6ff7faa (patch)
treeae45cd8a2101c4f9a9f6da9e7c0b42028a561af2 /src/arm/gnunet-service-arm.c
parenta7b9cb74b69e67dfcbaaaf0f31b264e6886e1374 (diff)
downloadgnunet-50c2b2a28aba97efbbd51658f18afda6d6ff7faa.tar.gz
gnunet-50c2b2a28aba97efbbd51658f18afda6d6ff7faa.zip
clean up arm, do not warn on missing port if autostart set
Diffstat (limited to 'src/arm/gnunet-service-arm.c')
-rw-r--r--src/arm/gnunet-service-arm.c148
1 files changed, 103 insertions, 45 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 6924ca676..f7f51b31d 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -346,11 +346,15 @@ get_server_addresses (const char *service_name,
346 *addrs = NULL; 346 *addrs = NULL;
347 *addr_lens = NULL; 347 *addr_lens = NULL;
348 desc = NULL; 348 desc = NULL;
349 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) 349 if (GNUNET_CONFIGURATION_have_value (cfg,
350 service_name,
351 "DISABLEV6"))
350 { 352 {
351 if (GNUNET_SYSERR == 353 if (GNUNET_SYSERR ==
352 (disablev6 = 354 (disablev6 =
353 GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6"))) 355 GNUNET_CONFIGURATION_get_value_yesno (cfg,
356 service_name,
357 "DISABLEV6")))
354 return GNUNET_SYSERR; 358 return GNUNET_SYSERR;
355 } 359 }
356 else 360 else
@@ -359,18 +363,24 @@ get_server_addresses (const char *service_name,
359 if (! disablev6) 363 if (! disablev6)
360 { 364 {
361 /* probe IPv6 support */ 365 /* probe IPv6 support */
362 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); 366 desc = GNUNET_NETWORK_socket_create (PF_INET6,
367 SOCK_STREAM,
368 0);
363 if (NULL == desc) 369 if (NULL == desc)
364 { 370 {
365 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || 371 if ( (ENOBUFS == errno) ||
366 (EACCES == errno)) 372 (ENOMEM == errno) ||
373 (ENFILE == errno) ||
374 (EACCES == errno) )
367 { 375 {
368 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); 376 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
377 "socket");
369 return GNUNET_SYSERR; 378 return GNUNET_SYSERR;
370 } 379 }
371 LOG (GNUNET_ERROR_TYPE_INFO, 380 LOG (GNUNET_ERROR_TYPE_INFO,
372 _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), 381 _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
373 service_name, STRERROR (errno)); 382 service_name,
383 STRERROR (errno));
374 disablev6 = GNUNET_YES; 384 disablev6 = GNUNET_YES;
375 } 385 }
376 else 386 else
@@ -381,11 +391,15 @@ get_server_addresses (const char *service_name,
381 } 391 }
382 392
383 port = 0; 393 port = 0;
384 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) 394 if (GNUNET_CONFIGURATION_have_value (cfg,
395 service_name,
396 "PORT"))
385 { 397 {
386 if (GNUNET_OK != 398 if (GNUNET_OK !=
387 GNUNET_CONFIGURATION_get_value_number (cfg, service_name, 399 GNUNET_CONFIGURATION_get_value_number (cfg,
388 "PORT", &port)) 400 service_name,
401 "PORT",
402 &port))
389 { 403 {
390 LOG (GNUNET_ERROR_TYPE_ERROR, 404 LOG (GNUNET_ERROR_TYPE_ERROR,
391 _("Require valid port number for service `%s' in configuration!\n"), 405 _("Require valid port number for service `%s' in configuration!\n"),
@@ -400,11 +414,15 @@ get_server_addresses (const char *service_name,
400 } 414 }
401 } 415 }
402 416
403 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) 417 if (GNUNET_CONFIGURATION_have_value (cfg,
418 service_name,
419 "BINDTO"))
404 { 420 {
405 GNUNET_break (GNUNET_OK == 421 GNUNET_break (GNUNET_OK ==
406 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, 422 GNUNET_CONFIGURATION_get_value_string (cfg,
407 "BINDTO", &hostname)); 423 service_name,
424 "BINDTO",
425 &hostname));
408 } 426 }
409 else 427 else
410 hostname = NULL; 428 hostname = NULL;
@@ -413,10 +431,14 @@ get_server_addresses (const char *service_name,
413 abstract = GNUNET_NO; 431 abstract = GNUNET_NO;
414#ifdef AF_UNIX 432#ifdef AF_UNIX
415 if ((GNUNET_YES == 433 if ((GNUNET_YES ==
416 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && 434 GNUNET_CONFIGURATION_have_value (cfg,
435 service_name,
436 "UNIXPATH")) &&
417 (GNUNET_OK == 437 (GNUNET_OK ==
418 GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", 438 GNUNET_CONFIGURATION_get_value_filename (cfg,
419 &unixpath)) && 439 service_name,
440 "UNIXPATH",
441 &unixpath)) &&
420 (0 < strlen (unixpath))) 442 (0 < strlen (unixpath)))
421 { 443 {
422 /* probe UNIX support */ 444 /* probe UNIX support */
@@ -425,7 +447,8 @@ get_server_addresses (const char *service_name,
425 if (strlen (unixpath) >= sizeof (s_un.sun_path)) 447 if (strlen (unixpath) >= sizeof (s_un.sun_path))
426 { 448 {
427 LOG (GNUNET_ERROR_TYPE_WARNING, 449 LOG (GNUNET_ERROR_TYPE_WARNING,
428 _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, 450 _("UNIXPATH `%s' too long, maximum length is %llu\n"),
451 unixpath,
429 (unsigned long long) sizeof (s_un.sun_path)); 452 (unsigned long long) sizeof (s_un.sun_path));
430 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); 453 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
431 LOG (GNUNET_ERROR_TYPE_INFO, 454 LOG (GNUNET_ERROR_TYPE_INFO,
@@ -439,9 +462,9 @@ get_server_addresses (const char *service_name,
439 if (GNUNET_SYSERR == abstract) 462 if (GNUNET_SYSERR == abstract)
440 abstract = GNUNET_NO; 463 abstract = GNUNET_NO;
441#endif 464#endif
442 if ((GNUNET_YES != abstract) 465 if ( (GNUNET_YES != abstract) &&
443 && (GNUNET_OK != 466 (GNUNET_OK !=
444 GNUNET_DISK_directory_create_for_file (unixpath))) 467 GNUNET_DISK_directory_create_for_file (unixpath)) )
445 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 468 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
446 "mkdir", 469 "mkdir",
447 unixpath); 470 unixpath);
@@ -451,8 +474,10 @@ get_server_addresses (const char *service_name,
451 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); 474 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
452 if (NULL == desc) 475 if (NULL == desc)
453 { 476 {
454 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || 477 if ( (ENOBUFS == errno) ||
455 (EACCES == errno)) 478 (ENOMEM == errno) ||
479 (ENFILE == errno) ||
480 (EACCES == errno) )
456 { 481 {
457 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); 482 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
458 GNUNET_free_non_null (hostname); 483 GNUNET_free_non_null (hostname);
@@ -474,19 +499,29 @@ get_server_addresses (const char *service_name,
474 } 499 }
475#endif 500#endif
476 501
477 if ((0 == port) && (NULL == unixpath)) 502 if ( (0 == port) &&
503 (NULL == unixpath) )
478 { 504 {
479 LOG (GNUNET_ERROR_TYPE_ERROR, 505 if (GNUNET_YES !=
480 _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), 506 GNUNET_CONFIGURATION_get_value_yesno (cfg,
481 service_name); 507 service_name,
508 "AUTOSTART"))
509 LOG (GNUNET_ERROR_TYPE_ERROR,
510 _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
511 service_name);
482 GNUNET_free_non_null (hostname); 512 GNUNET_free_non_null (hostname);
483 return GNUNET_SYSERR; 513 return GNUNET_SYSERR;
484 } 514 }
485 if (0 == port) 515 if (0 == port)
486 { 516 {
487 saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *)); 517 saddrs = GNUNET_new_array (2,
488 saddrlens = GNUNET_malloc (2 * sizeof (socklen_t)); 518 struct sockaddr *);
489 add_unixpath (saddrs, saddrlens, unixpath, abstract); 519 saddrlens = GNUNET_new_array (2,
520 socklen_t);
521 add_unixpath (saddrs,
522 saddrlens,
523 unixpath,
524 abstract);
490 GNUNET_free_non_null (unixpath); 525 GNUNET_free_non_null (unixpath);
491 GNUNET_free_non_null (hostname); 526 GNUNET_free_non_null (hostname);
492 *addrs = saddrs; 527 *addrs = saddrs;
@@ -504,7 +539,10 @@ get_server_addresses (const char *service_name,
504 if (disablev6) 539 if (disablev6)
505 hints.ai_family = AF_INET; 540 hints.ai_family = AF_INET;
506 hints.ai_protocol = IPPROTO_TCP; 541 hints.ai_protocol = IPPROTO_TCP;
507 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || 542 if ((0 != (ret = getaddrinfo (hostname,
543 NULL,
544 &hints,
545 &res))) ||
508 (NULL == res)) 546 (NULL == res))
509 { 547 {
510 LOG (GNUNET_ERROR_TYPE_ERROR, 548 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -538,8 +576,10 @@ get_server_addresses (const char *service_name,
538 resi = i; 576 resi = i;
539 if (NULL != unixpath) 577 if (NULL != unixpath)
540 resi++; 578 resi++;
541 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 579 saddrs = GNUNET_new_array (resi + 1,
542 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 580 struct sockaddr *);
581 saddrlens = GNUNET_new_array (resi + 1,
582 socklen_t);
543 i = 0; 583 i = 0;
544 if (NULL != unixpath) 584 if (NULL != unixpath)
545 { 585 {
@@ -591,8 +631,10 @@ get_server_addresses (const char *service_name,
591 if (NULL != unixpath) 631 if (NULL != unixpath)
592 resi++; 632 resi++;
593 i = 0; 633 i = 0;
594 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 634 saddrs = GNUNET_new_array (resi + 1,
595 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 635 struct sockaddr *);
636 saddrlens = GNUNET_new_array (resi + 1,
637 socklen_t);
596 if (NULL != unixpath) 638 if (NULL != unixpath)
597 { 639 {
598 add_unixpath (saddrs, saddrlens, unixpath, abstract); 640 add_unixpath (saddrs, saddrlens, unixpath, abstract);
@@ -612,12 +654,17 @@ get_server_addresses (const char *service_name,
612 resi = 2; 654 resi = 2;
613 if (NULL != unixpath) 655 if (NULL != unixpath)
614 resi++; 656 resi++;
615 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 657 saddrs = GNUNET_new_array (resi + 1,
616 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 658 struct sockaddr *);
659 saddrlens = GNUNET_new_array (resi + 1,
660 socklen_t);
617 i = 0; 661 i = 0;
618 if (NULL != unixpath) 662 if (NULL != unixpath)
619 { 663 {
620 add_unixpath (saddrs, saddrlens, unixpath, abstract); 664 add_unixpath (saddrs,
665 saddrlens,
666 unixpath,
667 abstract);
621 i++; 668 i++;
622 } 669 }
623 saddrlens[i] = sizeof (struct sockaddr_in6); 670 saddrlens[i] = sizeof (struct sockaddr_in6);
@@ -663,6 +710,7 @@ signal_result (struct GNUNET_SERVICE_Client *client,
663 struct GNUNET_MQ_Envelope *env; 710 struct GNUNET_MQ_Envelope *env;
664 struct GNUNET_ARM_ResultMessage *msg; 711 struct GNUNET_ARM_ResultMessage *msg;
665 712
713 (void) name;
666 env = GNUNET_MQ_msg (msg, 714 env = GNUNET_MQ_msg (msg,
667 GNUNET_MESSAGE_TYPE_ARM_RESULT); 715 GNUNET_MESSAGE_TYPE_ARM_RESULT);
668 msg->result = htonl (result); 716 msg->result = htonl (result);
@@ -1184,6 +1232,7 @@ check_start (void *cls,
1184 uint16_t size; 1232 uint16_t size;
1185 const char *servicename; 1233 const char *servicename;
1186 1234
1235 (void) cls;
1187 size = ntohs (amsg->header.size) - sizeof (struct GNUNET_ARM_Message); 1236 size = ntohs (amsg->header.size) - sizeof (struct GNUNET_ARM_Message);
1188 servicename = (const char *) &amsg[1]; 1237 servicename = (const char *) &amsg[1];
1189 if ( (0 == size) || 1238 if ( (0 == size) ||
@@ -1254,6 +1303,7 @@ handle_start (void *cls,
1254static void 1303static void
1255trigger_shutdown (void *cls) 1304trigger_shutdown (void *cls)
1256{ 1305{
1306 (void) cls;
1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1258 "Triggering shutdown\n"); 1308 "Triggering shutdown\n");
1259 GNUNET_SCHEDULER_shutdown (); 1309 GNUNET_SCHEDULER_shutdown ();
@@ -1275,6 +1325,7 @@ check_stop (void *cls,
1275 uint16_t size; 1325 uint16_t size;
1276 const char *servicename; 1326 const char *servicename;
1277 1327
1328 (void) cls;
1278 size = ntohs (amsg->header.size) - sizeof (struct GNUNET_ARM_Message); 1329 size = ntohs (amsg->header.size) - sizeof (struct GNUNET_ARM_Message);
1279 servicename = (const char *) &amsg[1]; 1330 servicename = (const char *) &amsg[1];
1280 if ( (0 == size) || 1331 if ( (0 == size) ||
@@ -1451,6 +1502,7 @@ handle_test (void *cls,
1451 struct GNUNET_MQ_Envelope *env; 1502 struct GNUNET_MQ_Envelope *env;
1452 struct GNUNET_MessageHeader *msg; 1503 struct GNUNET_MessageHeader *msg;
1453 1504
1505 (void) message;
1454 env = GNUNET_MQ_msg (msg, 1506 env = GNUNET_MQ_msg (msg,
1455 GNUNET_MESSAGE_TYPE_ARM_TEST); 1507 GNUNET_MESSAGE_TYPE_ARM_TEST);
1456 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), 1508 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
@@ -1498,7 +1550,7 @@ list_count (struct ServiceList *running_head)
1498 struct ServiceList *i; 1550 struct ServiceList *i;
1499 unsigned int res; 1551 unsigned int res;
1500 1552
1501 for (res = 0, i = running_head; i; i = i->next, res++) 1553 for (res = 0, i = running_head; NULL != i; i = i->next, res++)
1502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1503 "%s\n", 1555 "%s\n",
1504 i->name); 1556 i->name);
@@ -1518,6 +1570,7 @@ shutdown_task (void *cls)
1518 struct ServiceList *nxt; 1570 struct ServiceList *nxt;
1519 struct ServiceListeningInfo *sli; 1571 struct ServiceListeningInfo *sli;
1520 1572
1573 (void) cls;
1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1522 "First shutdown phase\n"); 1575 "First shutdown phase\n");
1523 if (NULL != child_restart_task) 1576 if (NULL != child_restart_task)
@@ -1589,6 +1642,7 @@ delayed_restart_task (void *cls)
1589 struct GNUNET_TIME_Relative lowestRestartDelay; 1642 struct GNUNET_TIME_Relative lowestRestartDelay;
1590 struct ServiceListeningInfo *sli; 1643 struct ServiceListeningInfo *sli;
1591 1644
1645 (void) cls;
1592 child_restart_task = NULL; 1646 child_restart_task = NULL;
1593 GNUNET_assert (GNUNET_NO == in_shutdown); 1647 GNUNET_assert (GNUNET_NO == in_shutdown);
1594 lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL; 1648 lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1656,7 +1710,7 @@ delayed_restart_task (void *cls)
1656 * Task triggered whenever we receive a SIGCHLD (child 1710 * Task triggered whenever we receive a SIGCHLD (child
1657 * process died). 1711 * process died).
1658 * 1712 *
1659 * @param cls closure, NULL if we need to self-restart 1713 * @param cls closure, NULL
1660 */ 1714 */
1661static void 1715static void
1662maint_child_death (void *cls) 1716maint_child_death (void *cls)
@@ -1672,6 +1726,7 @@ maint_child_death (void *cls)
1672 unsigned long statusCode; 1726 unsigned long statusCode;
1673 const struct GNUNET_DISK_FileHandle *pr; 1727 const struct GNUNET_DISK_FileHandle *pr;
1674 1728
1729 (void) cls;
1675 pr = GNUNET_DISK_pipe_handle (sigpipe, 1730 pr = GNUNET_DISK_pipe_handle (sigpipe,
1676 GNUNET_DISK_PIPE_END_READ); 1731 GNUNET_DISK_PIPE_END_READ);
1677 child_death_task = NULL; 1732 child_death_task = NULL;
@@ -1914,6 +1969,7 @@ setup_service (void *cls,
1914 socklen_t *addr_lens; 1969 socklen_t *addr_lens;
1915 int ret; 1970 int ret;
1916 1971
1972 (void) cls;
1917 if (0 == strcasecmp (section, 1973 if (0 == strcasecmp (section,
1918 "arm")) 1974 "arm"))
1919 return; 1975 return;
@@ -2024,7 +2080,7 @@ setup_service (void *cls,
2024 &addr_lens))) 2080 &addr_lens)))
2025 return; 2081 return;
2026 /* this will free (or capture) addrs[i] */ 2082 /* this will free (or capture) addrs[i] */
2027 for (unsigned int i = 0; i < ret; i++) 2083 for (unsigned int i = 0; i < (unsigned int) ret; i++)
2028 create_listen_socket (addrs[i], 2084 create_listen_socket (addrs[i],
2029 addr_lens[i], 2085 addr_lens[i],
2030 sl); 2086 sl);
@@ -2049,6 +2105,8 @@ client_connect_cb (void *cls,
2049 /* All clients are considered to be of the "monitor" kind 2105 /* All clients are considered to be of the "monitor" kind
2050 * (that is, they don't affect ARM shutdown). 2106 * (that is, they don't affect ARM shutdown).
2051 */ 2107 */
2108 (void) cls;
2109 (void) mq;
2052 GNUNET_SERVICE_client_mark_monitor (client); 2110 GNUNET_SERVICE_client_mark_monitor (client);
2053 return client; 2111 return client;
2054} 2112}
@@ -2066,11 +2124,9 @@ client_disconnect_cb (void *cls,
2066 struct GNUNET_SERVICE_Client *client, 2124 struct GNUNET_SERVICE_Client *client,
2067 void *app_ctx) 2125 void *app_ctx)
2068{ 2126{
2069 struct ServiceList *sl; 2127 (void) cls;
2070
2071 GNUNET_assert (client == app_ctx); 2128 GNUNET_assert (client == app_ctx);
2072 2129 for (struct ServiceList *sl = running_head; NULL != sl; sl = sl->next)
2073 for (sl = running_head; NULL != sl; sl = sl->next)
2074 if (sl->killing_client == client) 2130 if (sl->killing_client == client)
2075 sl->killing_client = NULL; 2131 sl->killing_client = NULL;
2076} 2132}
@@ -2090,6 +2146,7 @@ handle_monitor (void *cls,
2090{ 2146{
2091 struct GNUNET_SERVICE_Client *client = cls; 2147 struct GNUNET_SERVICE_Client *client = cls;
2092 2148
2149 (void) message;
2093 /* FIXME: might want to start by letting monitor know about 2150 /* FIXME: might want to start by letting monitor know about
2094 services that are already running */ 2151 services that are already running */
2095 /* Removal is handled by the server implementation, internally. */ 2152 /* Removal is handled by the server implementation, internally. */
@@ -2105,7 +2162,7 @@ handle_monitor (void *cls,
2105/** 2162/**
2106 * Process arm requests. 2163 * Process arm requests.
2107 * 2164 *
2108 * @param cls closure 2165 * @param cls closure, NULL
2109 * @param serv the initialized service 2166 * @param serv the initialized service
2110 * @param c configuration to use 2167 * @param c configuration to use
2111 */ 2168 */
@@ -2116,6 +2173,7 @@ run (void *cls,
2116{ 2173{
2117 struct ServiceList *sl; 2174 struct ServiceList *sl;
2118 2175
2176 (void) cls;
2119 cfg = c; 2177 cfg = c;
2120 service = serv; 2178 service = serv;
2121 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 2179 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,