/**
* Transmit a status result message.
*
- * @param cls pointer to "unit16_t*" with message type
- * @param size number of bytes available in buf
+ * @param cls a `unit16_t *` with message type
+ * @param size number of bytes available in @a buf
* @param buf where to copy the message, NULL on error
- * @return number of bytes copied to buf
+ * @return number of bytes copied to @a buf
*/
static size_t
write_result (void *cls, size_t size, void *buf)
return 0; /* error, not much we can do */
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending status response %u to client\n", (unsigned int) msg->result);
+ "Sending status response %u to client\n",
+ (unsigned int) msg->result);
msize = msg->arm_msg.header.size;
GNUNET_assert (size >= msize);
msg->arm_msg.header.size = htons (msg->arm_msg.header.size);
return msize;
}
+
/**
* Transmit the list of running services.
- *
- * @param cls pointer to struct GNUNET_ARM_ListResultMessage with the message
- * @param size number of bytes available in buf
+ *
+ * @param cls pointer to `struct GNUNET_ARM_ListResultMessage` with the message
+ * @param size number of bytes available in @a buf
* @param buf where to copy the message, NULL on error
- * @return number of bytes copied to buf
+ * @return number of bytes copied to @a buf
*/
static size_t
write_list_result (void *cls, size_t size, void *buf)
{
struct GNUNET_ARM_ListResultMessage *msg = cls;
size_t rslt_size;
-
+
if (buf == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
GNUNET_free (msg);
return 0; /* error, not much we can do */
}
-
+
rslt_size = msg->arm_msg.header.size;
GNUNET_assert (size >= rslt_size);
msg->arm_msg.header.size = htons (msg->arm_msg.header.size);
msg->arm_msg.header.type = htons (msg->arm_msg.header.type);
msg->arm_msg.request_id = GNUNET_htonll (msg->arm_msg.request_id);
msg->count = htons (msg->count);
-
+
memcpy (buf, msg, rslt_size);
GNUNET_free (msg);
return rslt_size;
* @return NULL if it was not found
*/
static void
-signal_result (struct GNUNET_SERVER_Client *client, const char *name,
- uint64_t request_id, enum GNUNET_ARM_Result result)
+signal_result (struct GNUNET_SERVER_Client *client,
+ const char *name,
+ uint64_t request_id,
+ enum GNUNET_ARM_Result result)
{
struct GNUNET_ARM_ResultMessage *msg;
size_t msize;
msg->arm_msg.request_id = request_id;
GNUNET_SERVER_notify_transmit_ready (client, msize,
- GNUNET_TIME_UNIT_FOREVER_REL, write_result, msg);
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ write_result, msg);
}
* otherwise, send to all clients in the notifier
*/
static void
-broadcast_status (const char *name, enum GNUNET_ARM_ServiceStatus status,
- struct GNUNET_SERVER_Client *unicast)
+broadcast_status (const char *name,
+ enum GNUNET_ARM_ServiceStatus status,
+ struct GNUNET_SERVER_Client *unicast)
{
struct GNUNET_ARM_StatusMessage *msg;
size_t namelen;
if (NULL == sl->config)
sl->proc =
do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- lsocks, loprefix, binary,
+ lsocks, loprefix, binary,
options, NULL);
else
sl->proc =
* First connection has come to the listening socket associated with the service,
* create the service in order to relay the incoming connection to it
*
- * @param cls callback data, struct ServiceListeningInfo describing a listen socket
+ * @param cls callback data, `struct ServiceListeningInfo` describing a listen socket
* @param tc context
*/
static void
* wait for the first incoming connection to it
*
* @param sa address associated with the service
- * @param addr_len length of sa
+ * @param addr_len length of @a sa
* @param sl service entry for the service in question
*/
static void
static int on = 1;
struct GNUNET_NETWORK_Handle *sock;
struct ServiceListeningInfo *sli;
+ int match_uid;
+ int match_gid;
switch (sa->sa_family)
- {
- case AF_INET:
- sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
- break;
- case AF_INET6:
- sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
- break;
- case AF_UNIX:
- if (strcmp (GNUNET_a2s (sa, addr_len), "@") == 0) /* Do not bind to blank UNIX path! */
- return;
- sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
- break;
- default:
- GNUNET_break (0);
- sock = NULL;
- errno = EAFNOSUPPORT;
- break;
- }
- if (NULL == sock)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to create socket for service `%s': %s\n"),
- sl->name, STRERROR (errno));
- GNUNET_free (sa);
+ {
+ case AF_INET:
+ sock = GNUNET_NETWORK_socket_create (PF_INET, SOCK_STREAM, 0);
+ break;
+ case AF_INET6:
+ sock = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
+ break;
+ case AF_UNIX:
+ if (strcmp (GNUNET_a2s (sa, addr_len), "@") == 0) /* Do not bind to blank UNIX path! */
return;
- }
+ sock = GNUNET_NETWORK_socket_create (PF_UNIX, SOCK_STREAM, 0);
+ break;
+ default:
+ GNUNET_break (0);
+ sock = NULL;
+ errno = EAFNOSUPPORT;
+ break;
+ }
+ if (NULL == sock)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to create socket for service `%s': %s\n"),
+ sl->name, STRERROR (errno));
+ GNUNET_free (sa);
+ return;
+ }
if (GNUNET_NETWORK_socket_setsockopt
(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"setsockopt");
#endif
- if (GNUNET_NETWORK_socket_bind
- (sock, (const struct sockaddr *) sa, addr_len) != GNUNET_OK)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _
- ("Unable to bind listening socket for service `%s' to address `%s': %s\n"),
- sl->name, GNUNET_a2s (sa, addr_len), STRERROR (errno));
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- GNUNET_free (sa);
- return;
- }
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) sa, addr_len))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _
+ ("Unable to bind listening socket for service `%s' to address `%s': %s\n"),
+ sl->name, GNUNET_a2s (sa, addr_len), STRERROR (errno));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ GNUNET_free (sa);
+ return;
+ }
+#ifndef WINDOWS
+ if (AF_UNIX == sa->sa_family)
+ {
+ match_uid =
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name,
+ "UNIX_MATCH_UID");
+ match_gid =
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name,
+ "UNIX_MATCH_GID");
+ GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sa)->sun_path,
+ match_uid,
+ match_gid);
+
+ }
+#endif
if (GNUNET_NETWORK_socket_listen (sock, 5) != GNUNET_OK)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
- GNUNET_free (sa);
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
+ GNUNET_free (sa);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("ARM now monitors connections to service `%s' at `%s'\n"),
sl->name, GNUNET_a2s (sa, addr_len));
* @param cls closure (always NULL)
* @param client identification of the client
* @param message the actual message
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ * #GNUNET_SYSERR to close it (signal serious error)
*/
static void
handle_start (void *cls, struct GNUNET_SERVER_Client *client,
uint64_t request_id;
struct GNUNET_ARM_Message *amsg;
- amsg = (struct GNUNET_ARM_Message *) message;
+ amsg = (struct GNUNET_ARM_Message *) message;
request_id = GNUNET_ntohll (amsg->request_id);
size = ntohs (amsg->header.size);
size -= sizeof (struct GNUNET_ARM_Message);
* @param cls closure (always NULL)
* @param client identification of the client
* @param message the actual message
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ * #GNUNET_SYSERR to close it (signal serious error)
*/
static void
handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
uint64_t request_id;
struct GNUNET_ARM_Message *amsg;
- amsg = (struct GNUNET_ARM_Message *) message;
+ amsg = (struct GNUNET_ARM_Message *) message;
request_id = GNUNET_ntohll (amsg->request_id);
size = ntohs (amsg->header.size);
size -= sizeof (struct GNUNET_ARM_Message);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
+
/**
* Handle LIST-message.
*
size_t total_size;
struct ServiceList *sl;
uint16_t count;
-
+
if (NULL == client)
return;
-
+
request = (struct GNUNET_ARM_Message *) message;
count = 0;
string_list_size = 0;
}
}
- total_size = sizeof (struct GNUNET_ARM_ListResultMessage)
+ total_size = sizeof (struct GNUNET_ARM_ListResultMessage)
+ string_list_size;
msg = GNUNET_malloc (total_size);
msg->arm_msg.header.size = total_size;
msg->arm_msg.header.type = GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT;
msg->arm_msg.request_id = GNUNET_ntohll (request->request_id);
msg->count = count;
-
+
char *pos = (char *)&msg[1];
- for (sl = running_head; sl != NULL; sl = sl->next)
+ for (sl = running_head; sl != NULL; sl = sl->next)
{
if (sl->proc != NULL)
{
pos += s;
}
}
-
+
GNUNET_SERVER_notify_transmit_ready (client,
total_size,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
+
/**
* We are done with everything. Stop remaining
* tasks, signal handler and the server.
}
}
-unsigned int
+
+static unsigned int
list_count (struct ServiceList *running_head)
{
struct ServiceList *i;
unsigned int res = 0;
+
for (res = 0, i = running_head; i; i = i->next, res++)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n", i->name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "%s\n",
+ i->name);
return res;
}
+
/**
* Task run for shutdown.
*
struct ServiceList *nxt;
struct ServiceListeningInfo *sli;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First shutdown phase\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "First shutdown phase\n");
if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
{
GNUNET_SCHEDULER_cancel (child_restart_task);
nxt = pos->next;
if (pos->proc != NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Stopping service `%s'\n",
pos->name);
pos->killed_at = GNUNET_TIME_absolute_get ();
if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
do_shutdown ();
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delaying shutdown, have %u childs still running\n", list_count (running_head));
+ "Delaying shutdown, have %u childs still running\n",
+ list_count (running_head));
}
if (NULL != sl->proc)
continue;
/* service is currently not running */
- if (GNUNET_TIME_absolute_get_remaining (sl->restart_at).rel_value ==
- 0)
+ if (0 == GNUNET_TIME_absolute_get_remaining (sl->restart_at).rel_value_us)
{
/* restart is now allowed */
if (sl->is_default)
(sl->restart_at));
}
}
- if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
+ if (lowestRestartDelay.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Will restart process in %s\n",
GNUNET_STRINGS_relative_time_to_string (lowestRestartDelay, GNUNET_YES));
child_restart_task =
GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
&delayed_restart_task, NULL);
}
}
statstr = _( /* process termination method */ "unknown");
statcode = 0;
}
- if (0 != pos->killed_at.abs_value)
+ if (0 != pos->killed_at.abs_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Service `%s' took %s to terminate\n"),
GNUNET_SERVER_client_drop (pos->killing_client);
pos->killing_client = NULL;
pos->killing_client_request_id = 0;
- /* process can still be re-started on-demand, ensure it is re-started if there is demand */
- for (sli = pos->listen_head; NULL != sli; sli = sli->next)
- {
- GNUNET_break (GNUNET_SCHEDULER_NO_TASK == sli->accept_task);
- sli->accept_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- sli->listen_socket, &accept_connection, sli);
- }
}
if (GNUNET_YES != in_shutdown)
{
if ((statusType == GNUNET_OS_PROCESS_EXITED) && (statcode == 0))
{
/* process terminated normally, allow restart at any time */
- pos->restart_at.abs_value = 0;
+ pos->restart_at.abs_value_us = 0;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Service `%s' terminated normally, will restart at any time\n"),
pos->name);
*
* @param cls unused
* @param section a section in the configuration file
- * @return GNUNET_OK (continue)
+ * @return #GNUNET_OK (continue)
*/
static void
setup_service (void *cls, const char *section)
{
/* got the same section twice!? */
GNUNET_break (0);
+ GNUNET_free (binary);
return;
}
config = NULL;
{
if (NULL != config)
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
section, "CONFIG",
STRERROR (errno));
GNUNET_free (config);
config = NULL;
}
}
- sl = GNUNET_malloc (sizeof (struct ServiceList));
+ sl = GNUNET_new (struct ServiceList);
sl->name = GNUNET_strdup (section);
sl->binary = binary;
sl->config = config;
#else
if (GNUNET_CONFIGURATION_have_value (cfg, section, "PIPECONTROL"))
sl->pipe_control = GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "PIPECONTROL");
-#endif
+#endif
GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl);
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "AUTOSTART"))
GNUNET_SERVER_client_mark_monitor (client);
}
+
/**
* Handle MONITOR-message.
*
* @param cls closure (always NULL)
* @param client identification of the client
* @param message the actual message
- * @return GNUNET_OK to keep the connection open,
- * GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ * #GNUNET_SYSERR to close it (signal serious error)
*/
static void
handle_monitor (void *cls, struct GNUNET_SERVER_Client *client,
}
}
+
/**
* Process arm requests.
*
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
{&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0},
{&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0},
- {&handle_monitor, NULL, GNUNET_MESSAGE_TYPE_ARM_MONITOR,
+ {&handle_monitor, NULL, GNUNET_MESSAGE_TYPE_ARM_MONITOR,
sizeof (struct GNUNET_MessageHeader)},
- {&handle_list, NULL, GNUNET_MESSAGE_TYPE_ARM_LIST,
+ {&handle_list, NULL, GNUNET_MESSAGE_TYPE_ARM_LIST,
sizeof (struct GNUNET_ARM_Message)},
{NULL, NULL, 0, 0}
};
GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
ret =
(GNUNET_OK ==
- GNUNET_SERVICE_run (argc, argv, "arm",
+ GNUNET_SERVICE_run (argc, argv, "arm",
GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN, &run, NULL)) ? 0 : 1;
GNUNET_SIGNAL_handler_uninstall (shc_chld);
shc_chld = NULL;