diff options
-rw-r--r-- | src/lib/util/service.c | 178 |
1 files changed, 97 insertions, 81 deletions
diff --git a/src/lib/util/service.c b/src/lib/util/service.c index 063519f1f..7ed61919f 100644 --- a/src/lib/util/service.c +++ b/src/lib/util/service.c | |||
@@ -232,15 +232,10 @@ struct GNUNET_SERVICE_Handle | |||
232 | int ready_confirm_fd; | 232 | int ready_confirm_fd; |
233 | 233 | ||
234 | /** | 234 | /** |
235 | * Overall success/failure of the service start. | 235 | * If true, consider unknown message types an error where the |
236 | */ | ||
237 | int ret; | ||
238 | |||
239 | /** | ||
240 | * If #GNUNET_YES, consider unknown message types an error where the | ||
241 | * client is disconnected. | 236 | * client is disconnected. |
242 | */ | 237 | */ |
243 | int require_found; | 238 | bool require_found; |
244 | }; | 239 | }; |
245 | 240 | ||
246 | 241 | ||
@@ -329,19 +324,19 @@ struct GNUNET_SERVICE_Client | |||
329 | * force the OS to close once the process actually dies. Should only | 324 | * force the OS to close once the process actually dies. Should only |
330 | * be used in special cases! | 325 | * be used in special cases! |
331 | */ | 326 | */ |
332 | int persist; | 327 | bool persist; |
333 | 328 | ||
334 | /** | 329 | /** |
335 | * Is this client a 'monitor' client that should not be counted | 330 | * Is this client a 'monitor' client that should not be counted |
336 | * when deciding on destroying the server during soft shutdown? | 331 | * when deciding on destroying the server during soft shutdown? |
337 | * (see also #GNUNET_SERVICE_start) | 332 | * (see also #GNUNET_SERVICE_start) |
338 | */ | 333 | */ |
339 | int is_monitor; | 334 | bool is_monitor; |
340 | 335 | ||
341 | /** | 336 | /** |
342 | * Are we waiting for the application to call #GNUNET_SERVICE_client_continue()? | 337 | * Are we waiting for the application to call #GNUNET_SERVICE_client_continue()? |
343 | */ | 338 | */ |
344 | int needs_continue; | 339 | bool needs_continue; |
345 | 340 | ||
346 | /** | 341 | /** |
347 | * Type of last message processed (for warn_no_receive_done). | 342 | * Type of last message processed (for warn_no_receive_done). |
@@ -442,17 +437,13 @@ static bool | |||
442 | check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, | 437 | check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, |
443 | const struct in_addr *add) | 438 | const struct in_addr *add) |
444 | { | 439 | { |
445 | unsigned int i; | 440 | for (unsigned int i = 0; |
446 | 441 | 0 != list[i].network.s_addr; | |
447 | if (NULL == list) | 442 | i++) |
448 | return false; | ||
449 | i = 0; | ||
450 | while ((0 != list[i].network.s_addr) || (0 != list[i].netmask.s_addr)) | ||
451 | { | 443 | { |
452 | if ((add->s_addr & list[i].netmask.s_addr) == | 444 | if ( (add->s_addr & list[i].netmask.s_addr) == |
453 | (list[i].network.s_addr & list[i].netmask.s_addr)) | 445 | (list[i].network.s_addr & list[i].netmask.s_addr) ) |
454 | return true; | 446 | return true; |
455 | i++; | ||
456 | } | 447 | } |
457 | return false; | 448 | return false; |
458 | } | 449 | } |
@@ -469,22 +460,21 @@ static bool | |||
469 | check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, | 460 | check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, |
470 | const struct in6_addr *ip) | 461 | const struct in6_addr *ip) |
471 | { | 462 | { |
472 | unsigned int i; | 463 | for (unsigned int i = 0; |
473 | 464 | ! GNUNET_is_zero (&list[i].network); | |
474 | if (NULL == list) | 465 | i++) |
475 | return false; | ||
476 | i = 0; | ||
477 | NEXT: | ||
478 | while (GNUNET_NO == GNUNET_is_zero (&list[i].network)) | ||
479 | { | 466 | { |
467 | bool match = true; | ||
468 | |||
480 | for (unsigned int j = 0; j < sizeof(struct in6_addr) / sizeof(int); j++) | 469 | for (unsigned int j = 0; j < sizeof(struct in6_addr) / sizeof(int); j++) |
481 | if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != | 470 | if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) != |
482 | (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) | 471 | (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j])) |
483 | { | 472 | { |
484 | i++; | 473 | match = false; |
485 | goto NEXT; | 474 | break; |
486 | } | 475 | } |
487 | return true; | 476 | if (match) |
477 | return true; | ||
488 | } | 478 | } |
489 | return false; | 479 | return false; |
490 | } | 480 | } |
@@ -624,7 +614,7 @@ service_mq_error_handler (void *cls, | |||
624 | struct GNUNET_SERVICE_Handle *sh = client->sh; | 614 | struct GNUNET_SERVICE_Handle *sh = client->sh; |
625 | 615 | ||
626 | if ( (GNUNET_MQ_ERROR_NO_MATCH == error) && | 616 | if ( (GNUNET_MQ_ERROR_NO_MATCH == error) && |
627 | (GNUNET_NO == sh->require_found) ) | 617 | (! sh->require_found) ) |
628 | { | 618 | { |
629 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 619 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
630 | "No handler for message of type %u found\n", | 620 | "No handler for message of type %u found\n", |
@@ -684,8 +674,8 @@ service_client_mst_cb (void *cls, | |||
684 | "Received message of type %u and size %u from client\n", | 674 | "Received message of type %u and size %u from client\n", |
685 | ntohs (message->type), | 675 | ntohs (message->type), |
686 | ntohs (message->size)); | 676 | ntohs (message->size)); |
687 | GNUNET_assert (GNUNET_NO == client->needs_continue); | 677 | GNUNET_assert (! client->needs_continue); |
688 | client->needs_continue = GNUNET_YES; | 678 | client->needs_continue = true; |
689 | client->warn_type = ntohs (message->type); | 679 | client->warn_type = ntohs (message->type); |
690 | client->warn_start = GNUNET_TIME_absolute_get (); | 680 | client->warn_start = GNUNET_TIME_absolute_get (); |
691 | GNUNET_assert (NULL == client->warn_task); | 681 | GNUNET_assert (NULL == client->warn_task); |
@@ -721,7 +711,7 @@ service_client_recv (void *cls) | |||
721 | /* client closed connection (or IO error) */ | 711 | /* client closed connection (or IO error) */ |
722 | if (NULL == client->drop_task) | 712 | if (NULL == client->drop_task) |
723 | { | 713 | { |
724 | GNUNET_assert (GNUNET_NO == client->needs_continue); | 714 | GNUNET_assert (! client->needs_continue); |
725 | GNUNET_SERVICE_client_drop (client); | 715 | GNUNET_SERVICE_client_drop (client); |
726 | } | 716 | } |
727 | return; | 717 | return; |
@@ -730,7 +720,7 @@ service_client_recv (void *cls) | |||
730 | return; /* more messages in buffer, wait for application | 720 | return; /* more messages in buffer, wait for application |
731 | to be done processing */ | 721 | to be done processing */ |
732 | GNUNET_assert (GNUNET_OK == ret); | 722 | GNUNET_assert (GNUNET_OK == ret); |
733 | if (GNUNET_YES == client->needs_continue) | 723 | if (client->needs_continue) |
734 | return; | 724 | return; |
735 | if (NULL != client->recv_task) | 725 | if (NULL != client->recv_task) |
736 | return; | 726 | return; |
@@ -1502,8 +1492,8 @@ setup_service (struct GNUNET_SERVICE_Handle *sh) | |||
1502 | 1492 | ||
1503 | lsocks = NULL; | 1493 | lsocks = NULL; |
1504 | errno = 0; | 1494 | errno = 0; |
1505 | if ((NULL != (nfds = getenv ("LISTEN_FDS"))) && | 1495 | if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) && |
1506 | (1 == sscanf (nfds, "%u%1s", &cnt, dummy)) && (cnt > 0) && | 1496 | (1 == sscanf (nfds, "%u%1s", &cnt, dummy)) && (cnt > 0) && |
1507 | (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE)) | 1497 | (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE)) |
1508 | { | 1498 | { |
1509 | lsocks = GNUNET_new_array (cnt + 1, struct GNUNET_NETWORK_Handle *); | 1499 | lsocks = GNUNET_new_array (cnt + 1, struct GNUNET_NETWORK_Handle *); |
@@ -1576,7 +1566,9 @@ setup_service (struct GNUNET_SERVICE_Handle *sh) | |||
1576 | GNUNET_free (slc); | 1566 | GNUNET_free (slc); |
1577 | continue; | 1567 | continue; |
1578 | } | 1568 | } |
1579 | GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc); | 1569 | GNUNET_CONTAINER_DLL_insert (sh->slc_head, |
1570 | sh->slc_tail, | ||
1571 | slc); | ||
1580 | } | 1572 | } |
1581 | GNUNET_free (addrlens); | 1573 | GNUNET_free (addrlens); |
1582 | GNUNET_free (addrs); | 1574 | GNUNET_free (addrs); |
@@ -1598,7 +1590,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh) | |||
1598 | GNUNET_NETWORK_socket_close (*ls); | 1590 | GNUNET_NETWORK_socket_close (*ls); |
1599 | GNUNET_free (csocks); | 1591 | GNUNET_free (csocks); |
1600 | } | 1592 | } |
1601 | sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES; | 1593 | sh->require_found = (GNUNET_NO == tolerant); |
1602 | sh->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg, | 1594 | sh->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg, |
1603 | sh->service_name, | 1595 | sh->service_name, |
1604 | "UNIX_MATCH_UID"); | 1596 | "UNIX_MATCH_UID"); |
@@ -1641,16 +1633,14 @@ get_user_name (struct GNUNET_SERVICE_Handle *sh) | |||
1641 | * @param sh service context | 1633 | * @param sh service context |
1642 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1634 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1643 | */ | 1635 | */ |
1644 | static int | 1636 | static enum GNUNET_GenericReturnValue |
1645 | set_user_id (struct GNUNET_SERVICE_Handle *sh) | 1637 | set_user_id (struct GNUNET_SERVICE_Handle *sh) |
1646 | { | 1638 | { |
1647 | char *user; | 1639 | char *user; |
1640 | struct passwd *pws; | ||
1648 | 1641 | ||
1649 | if (NULL == (user = get_user_name (sh))) | 1642 | if (NULL == (user = get_user_name (sh))) |
1650 | return GNUNET_OK; /* keep */ | 1643 | return GNUNET_OK; /* keep */ |
1651 | |||
1652 | struct passwd *pws; | ||
1653 | |||
1654 | errno = 0; | 1644 | errno = 0; |
1655 | pws = getpwnam (user); | 1645 | pws = getpwnam (user); |
1656 | if (NULL == pws) | 1646 | if (NULL == pws) |
@@ -1666,7 +1656,8 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh) | |||
1666 | #if HAVE_INITGROUPS | 1656 | #if HAVE_INITGROUPS |
1667 | (0 != initgroups (user, pws->pw_gid)) || | 1657 | (0 != initgroups (user, pws->pw_gid)) || |
1668 | #endif | 1658 | #endif |
1669 | (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid))) | 1659 | (0 != setuid (pws->pw_uid)) || |
1660 | (0 != seteuid (pws->pw_uid))) | ||
1670 | { | 1661 | { |
1671 | if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || | 1662 | if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || |
1672 | (0 != setreuid (pws->pw_uid, pws->pw_uid))) | 1663 | (0 != setreuid (pws->pw_uid, pws->pw_uid))) |
@@ -1742,13 +1733,15 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh) | |||
1742 | 1733 | ||
1743 | if (0 != pipe (filedes)) | 1734 | if (0 != pipe (filedes)) |
1744 | { | 1735 | { |
1745 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); | 1736 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, |
1737 | "pipe"); | ||
1746 | return GNUNET_SYSERR; | 1738 | return GNUNET_SYSERR; |
1747 | } | 1739 | } |
1748 | pid = fork (); | 1740 | pid = fork (); |
1749 | if (pid < 0) | 1741 | if (pid < 0) |
1750 | { | 1742 | { |
1751 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); | 1743 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, |
1744 | "fork"); | ||
1752 | return GNUNET_SYSERR; | 1745 | return GNUNET_SYSERR; |
1753 | } | 1746 | } |
1754 | if (0 != pid) | 1747 | if (0 != pid) |
@@ -1759,7 +1752,8 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh) | |||
1759 | GNUNET_break (0 == close (filedes[1])); | 1752 | GNUNET_break (0 == close (filedes[1])); |
1760 | c = 'X'; | 1753 | c = 'X'; |
1761 | if (1 != read (filedes[0], &c, sizeof(char))) | 1754 | if (1 != read (filedes[0], &c, sizeof(char))) |
1762 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); | 1755 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, |
1756 | "read"); | ||
1763 | fflush (stdout); | 1757 | fflush (stdout); |
1764 | switch (c) | 1758 | switch (c) |
1765 | { | 1759 | { |
@@ -1800,7 +1794,8 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh) | |||
1800 | /* Detach from controlling terminal */ | 1794 | /* Detach from controlling terminal */ |
1801 | pid = setsid (); | 1795 | pid = setsid (); |
1802 | if (-1 == pid) | 1796 | if (-1 == pid) |
1803 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid"); | 1797 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, |
1798 | "setsid"); | ||
1804 | sh->ready_confirm_fd = filedes[1]; | 1799 | sh->ready_confirm_fd = filedes[1]; |
1805 | 1800 | ||
1806 | return GNUNET_OK; | 1801 | return GNUNET_OK; |
@@ -1824,7 +1819,9 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh) | |||
1824 | GNUNET_free (sh->v6_allowed); | 1819 | GNUNET_free (sh->v6_allowed); |
1825 | while (NULL != (slc = sh->slc_head)) | 1820 | while (NULL != (slc = sh->slc_head)) |
1826 | { | 1821 | { |
1827 | GNUNET_CONTAINER_DLL_remove (sh->slc_head, sh->slc_tail, slc); | 1822 | GNUNET_CONTAINER_DLL_remove (sh->slc_head, |
1823 | sh->slc_tail, | ||
1824 | slc); | ||
1828 | if (NULL != slc->listen_task) | 1825 | if (NULL != slc->listen_task) |
1829 | GNUNET_SCHEDULER_cancel (slc->listen_task); | 1826 | GNUNET_SCHEDULER_cancel (slc->listen_task); |
1830 | GNUNET_break (GNUNET_OK == | 1827 | GNUNET_break (GNUNET_OK == |
@@ -1853,8 +1850,11 @@ return_agpl (void *cls, | |||
1853 | 1850 | ||
1854 | (void) msg; | 1851 | (void) msg; |
1855 | slen = strlen (pd->agpl_url) + 1; | 1852 | slen = strlen (pd->agpl_url) + 1; |
1856 | env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen); | 1853 | env = GNUNET_MQ_msg_extra (res, |
1857 | memcpy (&res[1], GNUNET_AGPL_URL, slen); | 1854 | GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen); |
1855 | memcpy (&res[1], | ||
1856 | GNUNET_AGPL_URL, | ||
1857 | slen); | ||
1858 | mq = GNUNET_SERVICE_client_get_mq (client); | 1858 | mq = GNUNET_SERVICE_client_get_mq (client); |
1859 | GNUNET_MQ_send (mq, env); | 1859 | GNUNET_MQ_send (mq, env); |
1860 | GNUNET_SERVICE_client_continue (client); | 1860 | GNUNET_SERVICE_client_continue (client); |
@@ -1971,7 +1971,6 @@ GNUNET_SERVICE_run_ (int argc, | |||
1971 | ? GNUNET_MQ_copy_handlers (handlers) | 1971 | ? GNUNET_MQ_copy_handlers (handlers) |
1972 | : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL); | 1972 | : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL); |
1973 | sh.service_name = service_name; | 1973 | sh.service_name = service_name; |
1974 | sh.ret = 0; | ||
1975 | /* setup subsystems */ | 1974 | /* setup subsystems */ |
1976 | loglev = NULL; | 1975 | loglev = NULL; |
1977 | logfile = NULL; | 1976 | logfile = NULL; |
@@ -2023,9 +2022,12 @@ GNUNET_SERVICE_run_ (int argc, | |||
2023 | } | 2022 | } |
2024 | else | 2023 | else |
2025 | { | 2024 | { |
2026 | if (GNUNET_YES == GNUNET_DISK_file_test (cfg_filename)) | 2025 | if (GNUNET_YES == |
2026 | GNUNET_DISK_file_test (cfg_filename)) | ||
2027 | { | 2027 | { |
2028 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_filename)) | 2028 | if (GNUNET_SYSERR == |
2029 | GNUNET_CONFIGURATION_load (cfg, | ||
2030 | cfg_filename)) | ||
2029 | { | 2031 | { |
2030 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2032 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2031 | _ ("Malformed configuration file `%s', exit ...\n"), | 2033 | _ ("Malformed configuration file `%s', exit ...\n"), |
@@ -2035,7 +2037,9 @@ GNUNET_SERVICE_run_ (int argc, | |||
2035 | } | 2037 | } |
2036 | else | 2038 | else |
2037 | { | 2039 | { |
2038 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) | 2040 | if (GNUNET_SYSERR == |
2041 | GNUNET_CONFIGURATION_load (cfg, | ||
2042 | NULL)) | ||
2039 | { | 2043 | { |
2040 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2044 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2041 | _ ("Malformed configuration, exit ...\n")); | 2045 | _ ("Malformed configuration, exit ...\n")); |
@@ -2045,7 +2049,8 @@ GNUNET_SERVICE_run_ (int argc, | |||
2045 | } | 2049 | } |
2046 | if (GNUNET_OK != setup_service (&sh)) | 2050 | if (GNUNET_OK != setup_service (&sh)) |
2047 | goto shutdown; | 2051 | goto shutdown; |
2048 | if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sh))) | 2052 | if ( (1 == do_daemonize) && |
2053 | (GNUNET_OK != detach_terminal (&sh)) ) | ||
2049 | { | 2054 | { |
2050 | GNUNET_break (0); | 2055 | GNUNET_break (0); |
2051 | goto shutdown; | 2056 | goto shutdown; |
@@ -2093,13 +2098,15 @@ shutdown: | |||
2093 | { | 2098 | { |
2094 | char *counter; | 2099 | char *counter; |
2095 | 2100 | ||
2096 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sh.cfg, | 2101 | if ( (GNUNET_YES == |
2097 | service_name, | 2102 | GNUNET_CONFIGURATION_have_value (sh.cfg, |
2098 | "GAUGER_HEAP")) && | 2103 | service_name, |
2099 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sh.cfg, | 2104 | "GAUGER_HEAP")) && |
2100 | service_name, | 2105 | (GNUNET_OK == |
2101 | "GAUGER_HEAP", | 2106 | GNUNET_CONFIGURATION_get_value_string (sh.cfg, |
2102 | &counter))) | 2107 | service_name, |
2108 | "GAUGER_HEAP", | ||
2109 | &counter))) | ||
2103 | { | 2110 | { |
2104 | struct mallinfo2 mi; | 2111 | struct mallinfo2 mi; |
2105 | 2112 | ||
@@ -2121,11 +2128,12 @@ shutdown: | |||
2121 | GNUNET_free (cfg_filename); | 2128 | GNUNET_free (cfg_filename); |
2122 | GNUNET_free (opt_cfg_filename); | 2129 | GNUNET_free (opt_cfg_filename); |
2123 | 2130 | ||
2124 | return err ? GNUNET_SYSERR : sh.ret; | 2131 | return err ? GNUNET_SYSERR : 0; |
2125 | } | 2132 | } |
2126 | 2133 | ||
2127 | 2134 | ||
2128 | /* A list of service to be launched when GNUNET_SERVICE_main() | 2135 | /** |
2136 | * A list of service to be launched when GNUNET_SERVICE_main() | ||
2129 | * is called | 2137 | * is called |
2130 | */ | 2138 | */ |
2131 | struct ServiceHandleList | 2139 | struct ServiceHandleList |
@@ -2146,6 +2154,7 @@ static struct ServiceHandleList *hll_head; | |||
2146 | /* The service list */ | 2154 | /* The service list */ |
2147 | static struct ServiceHandleList *hll_tail; | 2155 | static struct ServiceHandleList *hll_tail; |
2148 | 2156 | ||
2157 | |||
2149 | int | 2158 | int |
2150 | GNUNET_SERVICE_register_ (const char *service_name, | 2159 | GNUNET_SERVICE_register_ (const char *service_name, |
2151 | enum GNUNET_SERVICE_Options options, | 2160 | enum GNUNET_SERVICE_Options options, |
@@ -2169,13 +2178,12 @@ GNUNET_SERVICE_register_ (const char *service_name, | |||
2169 | ? GNUNET_MQ_copy_handlers (handlers) | 2178 | ? GNUNET_MQ_copy_handlers (handlers) |
2170 | : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL); | 2179 | : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL); |
2171 | sh->service_name = service_name; | 2180 | sh->service_name = service_name; |
2172 | sh->ret = 0; | ||
2173 | hle = GNUNET_new (struct ServiceHandleList); | 2181 | hle = GNUNET_new (struct ServiceHandleList); |
2174 | hle->sh = sh; | 2182 | hle->sh = sh; |
2175 | GNUNET_CONTAINER_DLL_insert (hll_head, | 2183 | GNUNET_CONTAINER_DLL_insert (hll_head, |
2176 | hll_tail, | 2184 | hll_tail, |
2177 | hle); | 2185 | hle); |
2178 | return GNUNET_OK; | 2186 | return 0; |
2179 | } | 2187 | } |
2180 | 2188 | ||
2181 | 2189 | ||
@@ -2241,7 +2249,6 @@ GNUNET_SERVICE_main (int argc, | |||
2241 | int ret; | 2249 | int ret; |
2242 | struct GNUNET_CONFIGURATION_Handle *cfg; | 2250 | struct GNUNET_CONFIGURATION_Handle *cfg; |
2243 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); | 2251 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); |
2244 | |||
2245 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | 2252 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { |
2246 | GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), | 2253 | GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), |
2247 | GNUNET_GETOPT_option_flag ('d', | 2254 | GNUNET_GETOPT_option_flag ('d', |
@@ -2255,6 +2262,7 @@ GNUNET_SERVICE_main (int argc, | |||
2255 | GNUNET_GETOPT_option_version (pd->version), | 2262 | GNUNET_GETOPT_option_version (pd->version), |
2256 | GNUNET_GETOPT_OPTION_END | 2263 | GNUNET_GETOPT_OPTION_END |
2257 | }; | 2264 | }; |
2265 | |||
2258 | xdg = getenv ("XDG_CONFIG_HOME"); | 2266 | xdg = getenv ("XDG_CONFIG_HOME"); |
2259 | if (NULL != xdg) | 2267 | if (NULL != xdg) |
2260 | GNUNET_asprintf (&cfg_filename, | 2268 | GNUNET_asprintf (&cfg_filename, |
@@ -2277,9 +2285,11 @@ GNUNET_SERVICE_main (int argc, | |||
2277 | goto shutdown; | 2285 | goto shutdown; |
2278 | } | 2286 | } |
2279 | // FIXME we need to set this up for each service! | 2287 | // FIXME we need to set this up for each service! |
2280 | if (GNUNET_OK != GNUNET_log_setup ("libgnunet", | 2288 | // NOTE: that was not the idea. What are you proposing? -CG |
2281 | loglev, | 2289 | if (GNUNET_OK != |
2282 | logfile)) | 2290 | GNUNET_log_setup ("libgnunet", |
2291 | loglev, | ||
2292 | logfile)) | ||
2283 | { | 2293 | { |
2284 | GNUNET_break (0); | 2294 | GNUNET_break (0); |
2285 | goto shutdown; | 2295 | goto shutdown; |
@@ -2316,7 +2326,9 @@ GNUNET_SERVICE_main (int argc, | |||
2316 | } | 2326 | } |
2317 | else | 2327 | else |
2318 | { | 2328 | { |
2319 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) | 2329 | if (GNUNET_SYSERR == |
2330 | GNUNET_CONFIGURATION_load (cfg, | ||
2331 | NULL)) | ||
2320 | { | 2332 | { |
2321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2333 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2322 | _ ("Malformed configuration, exit ...\n")); | 2334 | _ ("Malformed configuration, exit ...\n")); |
@@ -2369,7 +2381,8 @@ resume_client_receive (void *cls) | |||
2369 | 2381 | ||
2370 | c->recv_task = NULL; | 2382 | c->recv_task = NULL; |
2371 | /* first, check if there is still something in the buffer */ | 2383 | /* first, check if there is still something in the buffer */ |
2372 | ret = GNUNET_MST_next (c->mst, GNUNET_YES); | 2384 | ret = GNUNET_MST_next (c->mst, |
2385 | GNUNET_YES); | ||
2373 | if (GNUNET_SYSERR == ret) | 2386 | if (GNUNET_SYSERR == ret) |
2374 | { | 2387 | { |
2375 | if (NULL == c->drop_task) | 2388 | if (NULL == c->drop_task) |
@@ -2379,7 +2392,7 @@ resume_client_receive (void *cls) | |||
2379 | if (GNUNET_NO == ret) | 2392 | if (GNUNET_NO == ret) |
2380 | return; /* done processing, wait for more later */ | 2393 | return; /* done processing, wait for more later */ |
2381 | GNUNET_assert (GNUNET_OK == ret); | 2394 | GNUNET_assert (GNUNET_OK == ret); |
2382 | if (GNUNET_YES == c->needs_continue) | 2395 | if (c->needs_continue) |
2383 | return; /* #GNUNET_MST_next() did give a message to the client */ | 2396 | return; /* #GNUNET_MST_next() did give a message to the client */ |
2384 | /* need to receive more data from the network first */ | 2397 | /* need to receive more data from the network first */ |
2385 | if (NULL != c->recv_task) | 2398 | if (NULL != c->recv_task) |
@@ -2395,9 +2408,9 @@ void | |||
2395 | GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c) | 2408 | GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c) |
2396 | { | 2409 | { |
2397 | GNUNET_assert (NULL == c->drop_task); | 2410 | GNUNET_assert (NULL == c->drop_task); |
2398 | GNUNET_assert (GNUNET_YES == c->needs_continue); | 2411 | GNUNET_assert (c->needs_continue); |
2399 | GNUNET_assert (NULL == c->recv_task); | 2412 | GNUNET_assert (NULL == c->recv_task); |
2400 | c->needs_continue = GNUNET_NO; | 2413 | c->needs_continue = false; |
2401 | if (NULL != c->warn_task) | 2414 | if (NULL != c->warn_task) |
2402 | { | 2415 | { |
2403 | GNUNET_SCHEDULER_cancel (c->warn_task); | 2416 | GNUNET_SCHEDULER_cancel (c->warn_task); |
@@ -2437,9 +2450,10 @@ finish_client_drop (void *cls) | |||
2437 | GNUNET_assert (NULL == c->warn_task); | 2450 | GNUNET_assert (NULL == c->warn_task); |
2438 | GNUNET_MST_destroy (c->mst); | 2451 | GNUNET_MST_destroy (c->mst); |
2439 | GNUNET_MQ_destroy (c->mq); | 2452 | GNUNET_MQ_destroy (c->mq); |
2440 | if (GNUNET_NO == c->persist) | 2453 | if (! c->persist) |
2441 | { | 2454 | { |
2442 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (c->sock)); | 2455 | GNUNET_break (GNUNET_OK == |
2456 | GNUNET_NETWORK_socket_close (c->sock)); | ||
2443 | if ((0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) && | 2457 | if ((0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) && |
2444 | (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state))) | 2458 | (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state))) |
2445 | do_resume (sh, SUSPEND_STATE_EMFILE); | 2459 | do_resume (sh, SUSPEND_STATE_EMFILE); |
@@ -2467,9 +2481,11 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c) | |||
2467 | #if EXECINFO | 2481 | #if EXECINFO |
2468 | { | 2482 | { |
2469 | void *backtrace_array[MAX_TRACE_DEPTH]; | 2483 | void *backtrace_array[MAX_TRACE_DEPTH]; |
2470 | int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH); | 2484 | int num_backtrace_strings = backtrace (backtrace_array, |
2485 | MAX_TRACE_DEPTH); | ||
2471 | char **backtrace_strings = | 2486 | char **backtrace_strings = |
2472 | backtrace_symbols (backtrace_array, t->num_backtrace_strings); | 2487 | backtrace_symbols (backtrace_array, |
2488 | t->num_backtrace_strings); | ||
2473 | for (unsigned int i = 0; i < num_backtrace_strings; i++) | 2489 | for (unsigned int i = 0; i < num_backtrace_strings; i++) |
2474 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2490 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2475 | "client drop trace %u: %s\n", | 2491 | "client drop trace %u: %s\n", |
@@ -2525,7 +2541,7 @@ GNUNET_SERVICE_shutdown (struct GNUNET_SERVICE_Handle *sh) | |||
2525 | void | 2541 | void |
2526 | GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c) | 2542 | GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c) |
2527 | { | 2543 | { |
2528 | c->is_monitor = GNUNET_YES; | 2544 | c->is_monitor = true; |
2529 | if (((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state)) && | 2545 | if (((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state)) && |
2530 | (GNUNET_NO == have_non_monitor_clients (c->sh)))) | 2546 | (GNUNET_NO == have_non_monitor_clients (c->sh)))) |
2531 | GNUNET_SERVICE_shutdown (c->sh); | 2547 | GNUNET_SERVICE_shutdown (c->sh); |
@@ -2535,7 +2551,7 @@ GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c) | |||
2535 | void | 2551 | void |
2536 | GNUNET_SERVICE_client_persist (struct GNUNET_SERVICE_Client *c) | 2552 | GNUNET_SERVICE_client_persist (struct GNUNET_SERVICE_Client *c) |
2537 | { | 2553 | { |
2538 | c->persist = GNUNET_YES; | 2554 | c->persist = true; |
2539 | } | 2555 | } |
2540 | 2556 | ||
2541 | 2557 | ||