WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
*/
static int in_shutdown;
+/**
+ * Return value from main
+ */
+static int global_ret;
+
/**
* Are we starting user services?
*/
*addrs = NULL;
*addr_lens = NULL;
desc = NULL;
- if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
+ if (GNUNET_CONFIGURATION_have_value (cfg,
+ service_name,
+ "DISABLEV6"))
{
if (GNUNET_SYSERR ==
(disablev6 =
- GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
+ GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ service_name,
+ "DISABLEV6")))
return GNUNET_SYSERR;
}
else
if (! disablev6)
{
/* probe IPv6 support */
- desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
+ desc = GNUNET_NETWORK_socket_create (PF_INET6,
+ SOCK_STREAM,
+ 0);
if (NULL == desc)
{
- if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
- (EACCES == errno))
+ if ( (ENOBUFS == errno) ||
+ (ENOMEM == errno) ||
+ (ENFILE == errno) ||
+ (EACCES == errno) )
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
+ "socket");
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
_("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
- service_name, STRERROR (errno));
+ service_name,
+ STRERROR (errno));
disablev6 = GNUNET_YES;
}
else
}
port = 0;
- if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
+ if (GNUNET_CONFIGURATION_have_value (cfg,
+ service_name,
+ "PORT"))
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, service_name,
- "PORT", &port))
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ service_name,
+ "PORT",
+ &port))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_("Require valid port number for service `%s' in configuration!\n"),
}
}
- if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
+ if (GNUNET_CONFIGURATION_have_value (cfg,
+ service_name,
+ "BINDTO"))
{
GNUNET_break (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, service_name,
- "BINDTO", &hostname));
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ service_name,
+ "BINDTO",
+ &hostname));
}
else
hostname = NULL;
abstract = GNUNET_NO;
#ifdef AF_UNIX
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
+ GNUNET_CONFIGURATION_have_value (cfg,
+ service_name,
+ "UNIXPATH")) &&
(GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH",
- &unixpath)) &&
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
if (strlen (unixpath) >= sizeof (s_un.sun_path))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
+ _("UNIXPATH `%s' too long, maximum length is %llu\n"),
+ unixpath,
(unsigned long long) sizeof (s_un.sun_path));
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
LOG (GNUNET_ERROR_TYPE_INFO,
if (GNUNET_SYSERR == abstract)
abstract = GNUNET_NO;
#endif
- if ((GNUNET_YES != abstract)
- && (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath)))
+ if ( (GNUNET_YES != abstract) &&
+ (GNUNET_OK !=
+ GNUNET_DISK_directory_create_for_file (unixpath)) )
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
"mkdir",
unixpath);
desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
if (NULL == desc)
{
- if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
- (EACCES == errno))
+ if ( (ENOBUFS == errno) ||
+ (ENOMEM == errno) ||
+ (ENFILE == errno) ||
+ (EACCES == errno) )
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
GNUNET_free_non_null (hostname);
}
#endif
- if ((0 == port) && (NULL == unixpath))
+ if ( (0 == port) &&
+ (NULL == unixpath) )
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
- service_name);
+ if (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ service_name,
+ "START_ON_DEMAND"))
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
+ service_name);
GNUNET_free_non_null (hostname);
return GNUNET_SYSERR;
}
if (0 == port)
{
- saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
- saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
- add_unixpath (saddrs, saddrlens, unixpath, abstract);
+ saddrs = GNUNET_new_array (2,
+ struct sockaddr *);
+ saddrlens = GNUNET_new_array (2,
+ socklen_t);
+ add_unixpath (saddrs,
+ saddrlens,
+ unixpath,
+ abstract);
GNUNET_free_non_null (unixpath);
GNUNET_free_non_null (hostname);
*addrs = saddrs;
if (disablev6)
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_TCP;
- if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
+ if ((0 != (ret = getaddrinfo (hostname,
+ NULL,
+ &hints,
+ &res))) ||
(NULL == res))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
resi = i;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
- saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
+ saddrs = GNUNET_new_array (resi + 1,
+ struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1,
+ socklen_t);
i = 0;
if (NULL != unixpath)
{
if (NULL != unixpath)
resi++;
i = 0;
- saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
- saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
+ saddrs = GNUNET_new_array (resi + 1,
+ struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1,
+ socklen_t);
if (NULL != unixpath)
{
add_unixpath (saddrs, saddrlens, unixpath, abstract);
resi = 2;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
- saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
+ saddrs = GNUNET_new_array (resi + 1,
+ struct sockaddr *);
+ saddrlens = GNUNET_new_array (resi + 1,
+ socklen_t);
i = 0;
if (NULL != unixpath)
{
- add_unixpath (saddrs, saddrlens, unixpath, abstract);
+ add_unixpath (saddrs,
+ saddrlens,
+ unixpath,
+ abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in6);
struct GNUNET_MQ_Envelope *env;
struct GNUNET_ARM_ResultMessage *msg;
+ (void) name;
env = GNUNET_MQ_msg (msg,
GNUNET_MESSAGE_TYPE_ARM_RESULT);
msg->result = htonl (result);
check_start (void *cls,
const struct GNUNET_ARM_Message *amsg)
{
- uint16_t size;
- const char *servicename;
-
- size = ntohs (amsg->header.size) - sizeof (struct GNUNET_ARM_Message);
- servicename = (const char *) &amsg[1];
- if ( (0 == size) ||
- (servicename[size - 1] != '\0') )
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ (void) cls;
+ GNUNET_MQ_check_zero_termination (amsg);
return GNUNET_OK;
}
static void
trigger_shutdown (void *cls)
{
+ (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Triggering shutdown\n");
GNUNET_SCHEDULER_shutdown ();
check_stop (void *cls,
const struct GNUNET_ARM_Message *amsg)
{
- uint16_t size;
- const char *servicename;
-
- size = ntohs (amsg->header.size) - sizeof (struct GNUNET_ARM_Message);
- servicename = (const char *) &amsg[1];
- if ( (0 == size) ||
- (servicename[size - 1] != '\0') )
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
+ (void) cls;
+ GNUNET_MQ_check_zero_termination (amsg);
return GNUNET_OK;
}
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
+ (void) message;
env = GNUNET_MQ_msg (msg,
GNUNET_MESSAGE_TYPE_ARM_TEST);
GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
struct ServiceList *i;
unsigned int res;
- for (res = 0, i = running_head; i; i = i->next, res++)
+ for (res = 0, i = running_head; NULL != i; i = i->next, res++)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s\n",
i->name);
struct ServiceList *nxt;
struct ServiceListeningInfo *sli;
+ (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"First shutdown phase\n");
if (NULL != child_restart_task)
struct GNUNET_TIME_Relative lowestRestartDelay;
struct ServiceListeningInfo *sli;
+ (void) cls;
child_restart_task = NULL;
GNUNET_assert (GNUNET_NO == in_shutdown);
lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
* Task triggered whenever we receive a SIGCHLD (child
* process died).
*
- * @param cls closure, NULL if we need to self-restart
+ * @param cls closure, NULL
*/
static void
maint_child_death (void *cls)
unsigned long statusCode;
const struct GNUNET_DISK_FileHandle *pr;
+ (void) cls;
pr = GNUNET_DISK_pipe_handle (sigpipe,
GNUNET_DISK_PIPE_END_READ);
child_death_task = NULL;
socklen_t *addr_lens;
int ret;
+ (void) cls;
if (0 == strcasecmp (section,
"arm"))
return;
if ((GNUNET_YES ==
GNUNET_CONFIGURATION_have_value (cfg,
section,
- "USER_SERVICE")) &&
+ "RUN_PER_USER")) &&
(GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg,
section,
- "USER_SERVICE")))
+ "RUN_PER_USER")))
{
if (GNUNET_NO == start_user)
{
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (cfg,
section,
- "FORCESTART"))
+ "IMMEDIATE_START"))
{
sl->force_start = GNUNET_YES;
if (GNUNET_YES ==
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_yesno (cfg,
section,
- "AUTOSTART"))
+ "START_ON_DEMAND"))
return;
}
if (0 >= (ret = get_server_addresses (section,
&addr_lens)))
return;
/* this will free (or capture) addrs[i] */
- for (unsigned int i = 0; i < ret; i++)
+ for (unsigned int i = 0; i < (unsigned int) ret; i++)
create_listen_socket (addrs[i],
addr_lens[i],
sl);
/* All clients are considered to be of the "monitor" kind
* (that is, they don't affect ARM shutdown).
*/
+ (void) cls;
+ (void) mq;
GNUNET_SERVICE_client_mark_monitor (client);
return client;
}
struct GNUNET_SERVICE_Client *client,
void *app_ctx)
{
- struct ServiceList *sl;
-
+ (void) cls;
GNUNET_assert (client == app_ctx);
-
- for (sl = running_head; NULL != sl; sl = sl->next)
+ for (struct ServiceList *sl = running_head; NULL != sl; sl = sl->next)
if (sl->killing_client == client)
sl->killing_client = NULL;
}
{
struct GNUNET_SERVICE_Client *client = cls;
+ (void) message;
/* FIXME: might want to start by letting monitor know about
services that are already running */
/* Removal is handled by the server implementation, internally. */
/**
* Process arm requests.
*
- * @param cls closure
+ * @param cls closure, NULL
* @param serv the initialized service
* @param c configuration to use
*/
{
struct ServiceList *sl;
+ (void) cls;
cfg = c;
service = serv;
GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
else
final_option = GNUNET_CONFIGURATION_expand_dollar (cfg,
final_option);
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ start_user = GNUNET_CONFIGURATION_get_value_yesno (cfg,
"ARM",
- "USER_ONLY"))
- {
- GNUNET_break (GNUNET_YES == start_user);
- start_system = GNUNET_NO;
- }
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "START_USER_SERVICES");
+ start_system = GNUNET_CONFIGURATION_get_value_yesno (cfg,
"ARM",
- "SYSTEM_ONLY"))
+ "START_SYSTEM_SERVICES");
+ if ( (GNUNET_NO == start_user) &&
+ (GNUNET_NO == start_system) )
{
- GNUNET_break (GNUNET_YES == start_system);
- start_user = GNUNET_NO;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Please configure either START_USER_SERVICES or START_SYSTEM_SERVICES or both.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = 1;
+ return;
}
GNUNET_CONFIGURATION_iterate_sections (cfg,
&setup_service,
main (int argc,
char *const *argv)
{
- int ret;
struct GNUNET_SIGNAL_Context *shc_chld;
struct GNUNET_MQ_MessageHandler handlers[] = {
GNUNET_MQ_hd_var_size (start,
shc_chld =
GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD,
&sighandler_child_death);
- ret = GNUNET_SERVICE_run_ (argc,
+ if ( GNUNET_OK != GNUNET_SERVICE_run_ (argc,
argv,
"arm",
GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN,
&client_connect_cb,
&client_disconnect_cb,
NULL,
- handlers);
+ handlers))
+ global_ret = 2;
#if HAVE_WAIT4
if (NULL != wait_file)
{
shc_chld = NULL;
GNUNET_DISK_pipe_close (sigpipe);
sigpipe = NULL;
- return ret;
+ return global_ret;
}