summaryrefslogtreecommitdiff
path: root/src/util/service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/service.c')
-rw-r--r--src/util/service.c856
1 files changed, 306 insertions, 550 deletions
diff --git a/src/util/service.c b/src/util/service.c
index 73a73cbea..fba5a2f20 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -37,14 +37,13 @@
#endif
-#define LOG(kind,...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, \
- "util-service", \
- syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-service", syscall)
-#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file ( \
- kind, "util-service", syscall, filename)
+#define LOG_STRERROR_FILE(kind, syscall, filename) \
+ GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
/**
@@ -77,7 +76,6 @@ struct ServiceListenContext
* Task scheduled to do the listening.
*/
struct GNUNET_SCHEDULER_Task *listen_task;
-
};
@@ -363,8 +361,7 @@ struct GNUNET_SERVICE_Client
static int
have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh)
{
- for (struct GNUNET_SERVICE_Client *client = sh->clients_head;
- NULL != client;
+ for (struct GNUNET_SERVICE_Client *client = sh->clients_head; NULL != client;
client = client->next)
{
if (client->is_monitor)
@@ -383,8 +380,7 @@ have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh)
* @param sr reason for suspending accepting connections
*/
static void
-do_suspend (struct GNUNET_SERVICE_Handle *sh,
- enum SuspendReason sr)
+do_suspend (struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
{
struct ServiceListenContext *slc;
@@ -426,8 +422,7 @@ service_shutdown (void *cls)
break;
case GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN:
if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
- do_suspend (sh,
- SUSPEND_STATE_SHUTDOWN);
+ do_suspend (sh, SUSPEND_STATE_SHUTDOWN);
if (GNUNET_NO == have_non_monitor_clients (sh))
GNUNET_SERVICE_shutdown (sh);
break;
@@ -451,8 +446,7 @@ check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list,
if (NULL == list)
return GNUNET_NO;
i = 0;
- while ( (0 != list[i].network.s_addr) ||
- (0 != list[i].netmask.s_addr) )
+ while ((0 != list[i].network.s_addr) || (0 != list[i].netmask.s_addr))
{
if ((add->s_addr & list[i].netmask.s_addr) ==
(list[i].network.s_addr & list[i].netmask.s_addr))
@@ -480,7 +474,7 @@ check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list,
if (NULL == list)
return GNUNET_NO;
i = 0;
- NEXT:
+NEXT:
while (0 != GNUNET_is_zero (&list[i].network))
{
for (j = 0; j < sizeof (struct in6_addr) / sizeof (int); j++)
@@ -518,22 +512,17 @@ do_send (void *cls)
client->send_task = NULL;
buf = (const char *) client->msg;
left = ntohs (client->msg->size) - client->msg_pos;
- ret = GNUNET_NETWORK_socket_send (client->sock,
- &buf[client->msg_pos],
- left);
+ ret = GNUNET_NETWORK_socket_send (client->sock, &buf[client->msg_pos], left);
GNUNET_assert (ret <= (ssize_t) left);
if (0 == ret)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "no data send");
- GNUNET_MQ_inject_error (client->mq,
- GNUNET_MQ_ERROR_WRITE);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "no data send");
+ GNUNET_MQ_inject_error (client->mq, GNUNET_MQ_ERROR_WRITE);
return;
}
if (-1 == ret)
{
- if ( (EAGAIN == errno) ||
- (EINTR == errno) )
+ if ((EAGAIN == errno) || (EINTR == errno))
{
/* ignore */
ret = 0;
@@ -541,13 +530,11 @@ do_send (void *cls)
else
{
if (EPIPE != errno)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "send");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
LOG (GNUNET_ERROR_TYPE_DEBUG,
"socket send returned with error code %i",
errno);
- GNUNET_MQ_inject_error (client->mq,
- GNUNET_MQ_ERROR_WRITE);
+ GNUNET_MQ_inject_error (client->mq, GNUNET_MQ_ERROR_WRITE);
return;
}
}
@@ -559,11 +546,11 @@ do_send (void *cls)
if (left > (size_t) ret)
{
GNUNET_assert (NULL == client->drop_task);
- client->send_task
- = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &do_send,
- client);
+ client->send_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &do_send,
+ client);
return;
}
GNUNET_MQ_impl_send_continue (client->mq);
@@ -595,11 +582,11 @@ service_mq_send (struct GNUNET_MQ_Handle *mq,
ntohs (msg->size));
client->msg = msg;
client->msg_pos = 0;
- client->send_task
- = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &do_send,
- client);
+ client->send_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &do_send,
+ client);
}
@@ -610,8 +597,7 @@ service_mq_send (struct GNUNET_MQ_Handle *mq,
* @param impl_state state specific to the implementation
*/
static void
-service_mq_cancel (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+service_mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct GNUNET_SERVICE_Client *client = impl_state;
@@ -633,14 +619,12 @@ service_mq_cancel (struct GNUNET_MQ_Handle *mq,
* @param error error code
*/
static void
-service_mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+service_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_SERVICE_Handle *sh = client->sh;
- if ( (GNUNET_MQ_ERROR_NO_MATCH == error) &&
- (GNUNET_NO == sh->require_found) )
+ if ((GNUNET_MQ_ERROR_NO_MATCH == error) && (GNUNET_NO == sh->require_found))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No handler for message of type %u found\n",
@@ -662,18 +646,20 @@ warn_no_client_continue (void *cls)
{
struct GNUNET_SERVICE_Client *client = cls;
- GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
- client->warn_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_client_continue,
- client);
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _ (
- "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
- (unsigned int) client->warn_type,
- GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_duration (client->warn_start),
- GNUNET_YES));
+ GNUNET_break (
+ 0 !=
+ client->warn_type); /* type should never be 0 here, as we don't use 0 */
+ client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_no_client_continue,
+ client);
+ LOG (
+ GNUNET_ERROR_TYPE_WARNING,
+ _ (
+ "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
+ (unsigned int) client->warn_type,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (
+ client->warn_start),
+ GNUNET_YES));
}
@@ -689,8 +675,7 @@ warn_no_client_continue (void *cls)
* @return #GNUNET_OK on success, #GNUNET_SYSERR if the client was dropped
*/
static int
-service_client_mst_cb (void *cls,
- const struct GNUNET_MessageHeader *message)
+service_client_mst_cb (void *cls, const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
@@ -703,12 +688,10 @@ service_client_mst_cb (void *cls,
client->warn_type = ntohs (message->type);
client->warn_start = GNUNET_TIME_absolute_get ();
GNUNET_assert (NULL == client->warn_task);
- client->warn_task
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_client_continue,
- client);
- GNUNET_MQ_inject_message (client->mq,
- message);
+ client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &warn_no_client_continue,
+ client);
+ GNUNET_MQ_inject_message (client->mq, message);
if (NULL != client->drop_task)
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -728,10 +711,7 @@ service_client_recv (void *cls)
int ret;
client->recv_task = NULL;
- ret = GNUNET_MST_read (client->mst,
- client->sock,
- GNUNET_NO,
- GNUNET_YES);
+ ret = GNUNET_MST_read (client->mst, client->sock, GNUNET_NO, GNUNET_YES);
if (GNUNET_SYSERR == ret)
{
/* client closed connection (or IO error) */
@@ -751,11 +731,11 @@ service_client_recv (void *cls)
if (NULL != client->recv_task)
return;
/* MST needs more data, re-schedule read job */
- client->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &service_client_recv,
- client);
+ client->recv_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &service_client_recv,
+ client);
}
@@ -773,9 +753,7 @@ start_client (struct GNUNET_SERVICE_Handle *sh,
struct GNUNET_SERVICE_Client *client;
client = GNUNET_new (struct GNUNET_SERVICE_Client);
- GNUNET_CONTAINER_DLL_insert (sh->clients_head,
- sh->clients_tail,
- client);
+ GNUNET_CONTAINER_DLL_insert (sh->clients_head, sh->clients_tail, client);
client->sh = sh;
client->sock = csock;
client->mq = GNUNET_MQ_queue_for_callbacks (&service_mq_send,
@@ -785,19 +763,15 @@ start_client (struct GNUNET_SERVICE_Handle *sh,
sh->handlers,
&service_mq_error_handler,
client);
- client->mst = GNUNET_MST_create (&service_client_mst_cb,
- client);
+ client->mst = GNUNET_MST_create (&service_client_mst_cb, client);
if (NULL != sh->connect_cb)
- client->user_context = sh->connect_cb (sh->cb_cls,
- client,
- client->mq);
- GNUNET_MQ_set_handlers_closure (client->mq,
- client->user_context);
- client->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- client->sock,
- &service_client_recv,
- client);
+ client->user_context = sh->connect_cb (sh->cb_cls, client, client->mq);
+ GNUNET_MQ_set_handlers_closure (client->mq, client->user_context);
+ client->recv_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ client->sock,
+ &service_client_recv,
+ client);
}
@@ -830,11 +804,9 @@ accept_client (void *cls)
if (NULL == sock)
{
if (EMFILE == errno)
- do_suspend (sh,
- SUSPEND_STATE_EMFILE);
+ do_suspend (sh, SUSPEND_STATE_EMFILE);
else if (EAGAIN != errno)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "accept");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept");
break;
}
switch (sa.ss_family)
@@ -842,26 +814,22 @@ accept_client (void *cls)
case AF_INET:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
v4 = (const struct sockaddr_in *) &sa;
- ok = ( ( (NULL == sh->v4_allowed) ||
- (check_ipv4_listed (sh->v4_allowed,
- &v4->sin_addr))) &&
- ( (NULL == sh->v4_denied) ||
- (! check_ipv4_listed (sh->v4_denied,
- &v4->sin_addr)) ) );
+ ok = (((NULL == sh->v4_allowed) ||
+ (check_ipv4_listed (sh->v4_allowed, &v4->sin_addr))) &&
+ ((NULL == sh->v4_denied) ||
+ (! check_ipv4_listed (sh->v4_denied, &v4->sin_addr))));
break;
case AF_INET6:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
v6 = (const struct sockaddr_in6 *) &sa;
- ok = ( ( (NULL == sh->v6_allowed) ||
- (check_ipv6_listed (sh->v6_allowed,
- &v6->sin6_addr))) &&
- ( (NULL == sh->v6_denied) ||
- (! check_ipv6_listed (sh->v6_denied,
- &v6->sin6_addr)) ) );
+ ok = (((NULL == sh->v6_allowed) ||
+ (check_ipv6_listed (sh->v6_allowed, &v6->sin6_addr))) &&
+ ((NULL == sh->v6_denied) ||
+ (! check_ipv6_listed (sh->v6_denied, &v6->sin6_addr))));
break;
#ifndef WINDOWS
case AF_UNIX:
- ok = GNUNET_OK; /* controlled using file-system ACL now */
+ ok = GNUNET_OK; /* controlled using file-system ACL now */
break;
#endif
default:
@@ -874,26 +842,22 @@ accept_client (void *cls)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service rejected incoming connection from %s due to policy.\n",
- GNUNET_a2s ((const struct sockaddr *) &sa,
- addrlen));
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_a2s ((const struct sockaddr *) &sa, addrlen));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
continue;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service accepted incoming connection from %s.\n",
- GNUNET_a2s ((const struct sockaddr *) &sa,
- addrlen));
- start_client (slc->sh,
- sock);
+ GNUNET_a2s ((const struct sockaddr *) &sa, addrlen));
+ start_client (slc->sh, sock);
}
if (0 != sh->suspend_state)
return;
- slc->listen_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- slc->listen_socket,
- &accept_client,
- slc);
+ slc->listen_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ slc->listen_socket,
+ &accept_client,
+ slc);
}
@@ -905,24 +869,22 @@ accept_client (void *cls)
* or #SUSPEND_STATE_NONE on first startup
*/
static void
-do_resume (struct GNUNET_SERVICE_Handle *sh,
- enum SuspendReason sr)
+do_resume (struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
{
struct ServiceListenContext *slc;
- GNUNET_assert ( (SUSPEND_STATE_NONE == sr) ||
- (0 != (sh->suspend_state & sr)) );
+ GNUNET_assert ((SUSPEND_STATE_NONE == sr) || (0 != (sh->suspend_state & sr)));
sh->suspend_state -= sr;
if (SUSPEND_STATE_NONE != sh->suspend_state)
return;
for (slc = sh->slc_head; NULL != slc; slc = slc->next)
{
GNUNET_assert (NULL == slc->listen_task);
- slc->listen_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- slc->listen_socket,
- &accept_client,
- slc);
+ slc->listen_task =
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ slc->listen_socket,
+ &accept_client,
+ slc);
}
}
@@ -940,22 +902,18 @@ service_main (void *cls)
struct GNUNET_SERVICE_Handle *sh = cls;
if (GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN != sh->options)
- GNUNET_SCHEDULER_add_shutdown (&service_shutdown,
- sh);
- do_resume (sh,
- SUSPEND_STATE_NONE);
+ GNUNET_SCHEDULER_add_shutdown (&service_shutdown, sh);
+ do_resume (sh, SUSPEND_STATE_NONE);
if (-1 != sh->ready_confirm_fd)
{
- GNUNET_break (1 == WRITE (sh->ready_confirm_fd, ".", 1));
- GNUNET_break (0 == CLOSE (sh->ready_confirm_fd));
+ GNUNET_break (1 == write (sh->ready_confirm_fd, ".", 1));
+ GNUNET_break (0 == close (sh->ready_confirm_fd));
sh->ready_confirm_fd = -1;
}
if (NULL != sh->service_init_cb)
- sh->service_init_cb (sh->cb_cls,
- sh->cfg,
- sh);
+ sh->service_init_cb (sh->cb_cls, sh->cfg, sh);
}
@@ -975,9 +933,7 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
{
char *opt;
- if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
- sh->service_name,
- option))
+ if (! GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
@@ -1018,9 +974,7 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
{
char *opt;
- if (! GNUNET_CONFIGURATION_have_value (sh->cfg,
- sh->service_name,
- option))
+ if (! GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
@@ -1066,9 +1020,7 @@ add_unixpath (struct sockaddr **saddrs,
un = GNUNET_new (struct sockaddr_un);
un->sun_family = AF_UNIX;
- GNUNET_strlcpy (un->sun_path,
- unixpath,
- sizeof (un->sun_path));
+ GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
#ifdef LINUX
if (GNUNET_YES == abstract)
un->sun_path[0] = '\0';
@@ -1132,24 +1084,18 @@ get_server_addresses (const char *service_name,
*addr_lens = NULL;
desc = NULL;
disablev6 = GNUNET_NO;
- if ( (GNUNET_NO ==
- GNUNET_NETWORK_test_pf (PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- service_name,
- "DISABLEV6") ) )
+ if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
disablev6 = GNUNET_YES;
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))
+ if (GNUNET_OK != 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"),
@@ -1164,9 +1110,7 @@ get_server_addresses (const char *service_name,
}
}
- 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,
@@ -1181,14 +1125,11 @@ get_server_addresses (const char *service_name,
abstract = GNUNET_NO;
#ifdef AF_UNIX
if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- service_name,
- "UNIXPATH")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- service_name,
- "UNIXPATH",
- &unixpath)) &&
+ GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
@@ -1201,9 +1142,7 @@ get_server_addresses (const char *service_name,
unixpath,
(unsigned long long) sizeof (s_un.sun_path));
unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _ ("Using `%s' instead\n"),
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
}
#ifdef LINUX
abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
@@ -1212,27 +1151,19 @@ get_server_addresses (const char *service_name,
if (GNUNET_SYSERR == abstract)
abstract = GNUNET_NO;
#endif
- if ( (GNUNET_YES != abstract) &&
- (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (unixpath)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "mkdir",
- unixpath);
+ if ((GNUNET_YES != abstract) &&
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath)))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
}
if (NULL != unixpath)
{
- desc = GNUNET_NETWORK_socket_create (AF_UNIX,
- SOCK_STREAM,
- 0);
+ desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
if (NULL == desc)
{
- if ((ENOBUFS == errno) ||
- (ENOMEM == errno) ||
- (ENFILE == errno) ||
+ if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
(EACCES == errno))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
GNUNET_free_non_null (hostname);
GNUNET_free (unixpath);
return GNUNET_SYSERR;
@@ -1241,14 +1172,13 @@ get_server_addresses (const char *service_name,
_ (
"Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
service_name,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (unixpath);
unixpath = NULL;
}
else
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (desc));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
desc = NULL;
}
}
@@ -1265,14 +1195,9 @@ get_server_addresses (const char *service_name,
}
if (0 == port)
{
- saddrs = GNUNET_new_array (2,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (2,
- 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;
@@ -1286,16 +1211,11 @@ get_server_addresses (const char *service_name,
"Resolving `%s' since that is where `%s' will bind to.\n",
hostname,
service_name);
- memset (&hints,
- 0,
- sizeof (struct addrinfo));
+ memset (&hints, 0, sizeof (struct addrinfo));
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,
@@ -1311,8 +1231,7 @@ get_server_addresses (const char *service_name,
while (NULL != (pos = next))
{
next = pos->ai_next;
- if ( (disablev6) &&
- (pos->ai_family == AF_INET6) )
+ if ((disablev6) && (pos->ai_family == AF_INET6))
continue;
i++;
}
@@ -1330,45 +1249,34 @@ get_server_addresses (const char *service_name,
resi = i;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- 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++;
}
next = res;
while (NULL != (pos = next))
{
next = pos->ai_next;
- if ( (disablev6) &&
- (AF_INET6 == pos->ai_family) )
+ if ((disablev6) && (AF_INET6 == pos->ai_family))
continue;
- if ( (IPPROTO_TCP != pos->ai_protocol) &&
- (0 != pos->ai_protocol) )
- continue; /* not TCP */
- if ( (SOCK_STREAM != pos->ai_socktype) &&
- (0 != pos->ai_socktype) )
- continue; /* huh? */
+ if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
+ continue; /* not TCP */
+ if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
+ continue; /* huh? */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Service `%s' will bind to `%s'\n",
service_name,
- GNUNET_a2s (pos->ai_addr,
- pos->ai_addrlen));
+ GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
if (AF_INET == pos->ai_family)
{
GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
saddrlens[i] = pos->ai_addrlen;
saddrs[i] = GNUNET_malloc (saddrlens[i]);
- GNUNET_memcpy (saddrs[i],
- pos->ai_addr,
- saddrlens[i]);
+ GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
}
else
@@ -1377,9 +1285,7 @@ get_server_addresses (const char *service_name,
GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen);
saddrlens[i] = pos->ai_addrlen;
saddrs[i] = GNUNET_malloc (saddrlens[i]);
- GNUNET_memcpy (saddrs[i],
- pos->ai_addr,
- saddrlens[i]);
+ GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
}
i++;
@@ -1398,16 +1304,11 @@ get_server_addresses (const char *service_name,
if (NULL != unixpath)
resi++;
i = 0;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- 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);
+ add_unixpath (saddrs, saddrlens, unixpath, abstract);
i++;
}
saddrlens[i] = sizeof (struct sockaddr_in);
@@ -1424,17 +1325,12 @@ get_server_addresses (const char *service_name,
resi = 2;
if (NULL != unixpath)
resi++;
- saddrs = GNUNET_new_array (resi + 1,
- struct sockaddr *);
- saddrlens = GNUNET_new_array (resi + 1,
- 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);
@@ -1480,18 +1376,14 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
HANDLE lsocks_pipe;
env_buf = getenv ("GNUNET_OS_READ_LSOCKS");
- if ( (NULL == env_buf) ||
- (strlen (env_buf) <= 0) )
+ if ((NULL == env_buf) || (strlen (env_buf) <= 0))
return NULL;
/* Using W32 API directly here, because this pipe will
* never be used outside of this function, and it's just too much of a bother
* to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
*/
- lsocks_pipe = (HANDLE) strtoul (env_buf,
- NULL,
- 10);
- if ( (0 == lsocks_pipe) ||
- (INVALID_HANDLE_VALUE == lsocks_pipe))
+ lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10);
+ if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
return NULL;
fail = 1;
do
@@ -1500,17 +1392,10 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
int fail2;
DWORD rd;
- ret = ReadFile (lsocks_pipe,
- &count,
- sizeof (count),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (count) != rd) ||
- (0 == count) )
+ ret = ReadFile (lsocks_pipe, &count, sizeof (count), &rd, NULL);
+ if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
break;
- lsocks = GNUNET_new_array (count + 1,
- struct GNUNET_NETWORK_Handle *);
+ lsocks = GNUNET_new_array (count + 1, struct GNUNET_NETWORK_Handle *);
fail2 = 1;
for (i = 0; i < count; i++)
@@ -1519,22 +1404,11 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
uint64_t size;
SOCKET s;
- ret = ReadFile (lsocks_pipe,
- &size,
- sizeof (size),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (size) != rd) ||
- (sizeof (pi) != size) )
+ ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL);
+ if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size))
break;
- ret = ReadFile (lsocks_pipe,
- &pi,
- sizeof (pi),
- &rd,
- NULL);
- if ( (0 == ret) ||
- (sizeof (pi) != rd))
+ ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL);
+ if ((0 == ret) || (sizeof (pi) != rd))
break;
s = WSASocketA (pi.iAddressFamily,
pi.iSocketType,
@@ -1552,8 +1426,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
break;
lsocks[count] = NULL;
fail = 0;
- }
- while (fail);
+ } while (fail);
CloseHandle (lsocks_pipe);
if (fail)
@@ -1561,8 +1434,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Could not access a pre-bound socket, will try to bind myself\n"));
for (i = 0; (i < count) && (NULL != lsocks[i]); i++)
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (lsocks[i]));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (lsocks[i]));
GNUNET_free (lsocks);
return NULL;
}
@@ -1579,8 +1451,7 @@ receive_sockets_from_parent (struct GNUNET_SERVICE_Handle *sh)
* @return NULL on error, otherwise the listen socket
*/
static struct GNUNET_NETWORK_Handle *
-open_listen_socket (const struct sockaddr *server_addr,
- socklen_t socklen)
+open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen)
{
struct GNUNET_NETWORK_Handle *sock;
uint16_t port;
@@ -1602,20 +1473,15 @@ open_listen_socket (const struct sockaddr *server_addr,
port = 0;
break;
}
- sock = GNUNET_NETWORK_socket_create (server_addr->sa_family,
- SOCK_STREAM,
- 0);
+ sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0);
if (NULL == sock)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
errno = 0;
return NULL;
}
/* bind the socket */
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock,
- server_addr,
- socklen))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen))
{
eno = errno;
if (EADDRINUSE != errno)
@@ -1631,8 +1497,7 @@ open_listen_socket (const struct sockaddr *server_addr,
port,
(AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
else
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "bind");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
eno = 0;
}
else
@@ -1640,7 +1505,8 @@ open_listen_socket (const struct sockaddr *server_addr,
if (0 != port)
LOG (GNUNET_ERROR_TYPE_WARNING,
_ ("`%s' failed for port %d (%s): address already in use\n"),
- "bind", port,
+ "bind",
+ port,
(AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
else if (AF_UNIX == server_addr->sa_family)
{
@@ -1650,18 +1516,14 @@ open_listen_socket (const struct sockaddr *server_addr,
GNUNET_a2s (server_addr, socklen));
}
}
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
errno = eno;
return NULL;
}
- if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock,
- 5))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "listen");
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (sock));
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen");
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
errno = 0;
return NULL;
}
@@ -1701,16 +1563,12 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
char dummy[2];
#endif
- if (GNUNET_CONFIGURATION_have_value
- (sh->cfg,
- sh->service_name,
- "TOLERANT"))
+ if (GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, "TOLERANT"))
{
if (GNUNET_SYSERR ==
- (tolerant =
- GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "TOLERANT")))
+ (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "TOLERANT")))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Specified value for `%s' of service `%s' is invalid\n"),
@@ -1725,25 +1583,16 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
lsocks = NULL;
#ifndef MINGW
errno = 0;
- if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
- (1 == SSCANF (nfds,
- "%u%1s",
- &cnt,
- dummy)) &&
- (cnt > 0) &&
- (cnt < FD_SETSIZE) &&
- (cnt + 4 < FD_SETSIZE) )
+ if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
+ (1 == sscanf (nfds, "%u%1s", &cnt, dummy)) && (cnt > 0) &&
+ (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
{
- lsocks = GNUNET_new_array (cnt + 1,
- struct GNUNET_NETWORK_Handle *);
+ lsocks = GNUNET_new_array (cnt + 1, struct GNUNET_NETWORK_Handle *);
while (0 < cnt--)
{
- flags = fcntl (3 + cnt,
- F_GETFD);
- if ( (flags < 0) ||
- (0 != (flags & FD_CLOEXEC)) ||
- (NULL ==
- (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
+ flags = fcntl (3 + cnt, F_GETFD);
+ if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
+ (NULL == (lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ (
@@ -1780,9 +1629,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
slc = GNUNET_new (struct ServiceListenContext);
slc->sh = sh;
slc->listen_socket = *ls;
- GNUNET_CONTAINER_DLL_insert (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc);
}
GNUNET_free (lsocks);
}
@@ -1792,10 +1639,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
socklen_t *addrlens;
int num;
- num = get_server_addresses (sh->service_name,
- sh->cfg,
- &addrs,
- &addrlens);
+ num = get_server_addresses (sh->service_name, sh->cfg, &addrs, &addrlens);
if (GNUNET_SYSERR == num)
return GNUNET_SYSERR;
@@ -1805,54 +1649,40 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
slc = GNUNET_new (struct ServiceListenContext);
slc->sh = sh;
- slc->listen_socket = open_listen_socket (addrs[i],
- addrlens[i]);
+ slc->listen_socket = open_listen_socket (addrs[i], addrlens[i]);
GNUNET_free (addrs[i]);
if (NULL == slc->listen_socket)
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "bind");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
GNUNET_free (slc);
continue;
}
- GNUNET_CONTAINER_DLL_insert (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_insert (sh->slc_head, sh->slc_tail, slc);
}
GNUNET_free_non_null (addrlens);
GNUNET_free_non_null (addrs);
- if ( (0 != num) &&
- (NULL == sh->slc_head) )
+ if ((0 != num) && (NULL == sh->slc_head))
{
/* All attempts to bind failed, hard failure */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ (
- "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
return GNUNET_SYSERR;
}
}
sh->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
- sh->match_uid
- = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "UNIX_MATCH_UID");
- sh->match_gid
- = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
- sh->service_name,
- "UNIX_MATCH_GID");
- process_acl4 (&sh->v4_denied,
- sh,
- "REJECT_FROM");
- process_acl4 (&sh->v4_allowed,
- sh,
- "ACCEPT_FROM");
- process_acl6 (&sh->v6_denied,
- sh,
- "REJECT_FROM6");
- process_acl6 (&sh->v6_allowed,
- sh,
- "ACCEPT_FROM6");
+ sh->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "UNIX_MATCH_UID");
+ sh->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sh->cfg,
+ sh->service_name,
+ "UNIX_MATCH_GID");
+ process_acl4 (&sh->v4_denied, sh, "REJECT_FROM");
+ process_acl4 (&sh->v4_allowed, sh, "ACCEPT_FROM");
+ process_acl6 (&sh->v6_denied, sh, "REJECT_FROM6");
+ process_acl6 (&sh->v6_allowed, sh, "ACCEPT_FROM6");
return GNUNET_OK;
}
@@ -1869,11 +1699,10 @@ get_user_name (struct GNUNET_SERVICE_Handle *sh)
{
char *un;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
- sh->service_name,
- "USERNAME",
- &un))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
+ sh->service_name,
+ "USERNAME",
+ &un))
return NULL;
return un;
}
@@ -1891,7 +1720,7 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh)
char *user;
if (NULL == (user = get_user_name (sh)))
- return GNUNET_OK; /* keep */
+ return GNUNET_OK; /* keep */
#ifndef MINGW
struct passwd *pws;
@@ -1902,28 +1731,23 @@ set_user_id (struct GNUNET_SERVICE_Handle *sh)
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Cannot obtain information about user `%s': %s\n"),
user,
- errno == 0 ? _ ("No such user") : STRERROR (errno));
+ errno == 0 ? _ ("No such user") : strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
- if ( (0 != setgid (pws->pw_gid)) ||
- (0 != setegid (pws->pw_gid)) ||
+ if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
#if HAVE_INITGROUPS
- (0 != initgroups (user,
- pws->pw_gid)) ||
+ (0 != initgroups (user, pws->pw_gid)) ||
#endif
- (0 != setuid (pws->pw_uid)) ||
- (0 != seteuid (pws->pw_uid)))
+ (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
{
- if ((0 != setregid (pws->pw_gid,
- pws->pw_gid)) ||
- (0 != setreuid (pws->pw_uid,
- pws->pw_uid)))
+ if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
+ (0 != setreuid (pws->pw_uid, pws->pw_uid)))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_ ("Cannot change user/group to `%s': %s\n"),
user,
- STRERROR (errno));
+ strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
@@ -1946,11 +1770,10 @@ get_pid_file_name (struct GNUNET_SERVICE_Handle *sh)
{
char *pif;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
- sh->service_name,
- "PIDFILE",
- &pif))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sh->cfg,
+ sh->service_name,
+ "PIDFILE",
+ &pif))
return NULL;
return pif;
}
@@ -1967,11 +1790,9 @@ pid_file_delete (struct GNUNET_SERVICE_Handle *sh)
char *pif = get_pid_file_name (sh);
if (NULL == pif)
- return; /* no PID file */
- if (0 != UNLINK (pif))
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
- "unlink",
- pif);
+ return; /* no PID file */
+ if (0 != unlink (pif))
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
GNUNET_free (pif);
}
@@ -1990,17 +1811,15 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
int nullfd;
int filedes[2];
- if (0 != PIPE (filedes))
+ if (0 != pipe (filedes))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "pipe");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
return GNUNET_SYSERR;
}
pid = fork ();
if (pid < 0)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "fork");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork");
return GNUNET_SYSERR;
}
if (0 != pid)
@@ -2008,13 +1827,10 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
/* Parent */
char c;
- GNUNET_break (0 == CLOSE (filedes[1]));
+ GNUNET_break (0 == close (filedes[1]));
c = 'X';
- if (1 != READ (filedes[0],
- &c,
- sizeof (char)))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "read");
+ if (1 != read (filedes[0], &c, sizeof (char)))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
fflush (stdout);
switch (c)
{
@@ -2033,30 +1849,26 @@ detach_terminal (struct GNUNET_SERVICE_Handle *sh)
_ ("Service process failed to report status\n"));
break;
}
- exit (1); /* child reported error */
+ exit (1); /* child reported error */
}
- GNUNET_break (0 == CLOSE (0));
- GNUNET_break (0 == CLOSE (1));
- GNUNET_break (0 == CLOSE (filedes[0]));
- nullfd = OPEN ("/dev/null",
- O_RDWR | O_APPEND);
+ GNUNET_break (0 == close (0));
+ GNUNET_break (0 == close (1));
+ GNUNET_break (0 == close (filedes[0]));
+ nullfd = open ("/dev/null", O_RDWR | O_APPEND);
if (nullfd < 0)
return GNUNET_SYSERR;
/* set stdin/stdout to /dev/null */
- if ( (dup2 (nullfd, 0) < 0) ||
- (dup2 (nullfd, 1) < 0) )
+ if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "dup2");
- (void) CLOSE (nullfd);
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
+ (void) close (nullfd);
return GNUNET_SYSERR;
}
- (void) CLOSE (nullfd);
+ (void) close (nullfd);
/* Detach from controlling terminal */
pid = setsid ();
if (-1 == pid)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
- "setsid");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid");
sh->ready_confirm_fd = filedes[1];
#else
/* FIXME: we probably need to do something else
@@ -2084,9 +1896,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
GNUNET_free_non_null (sh->v6_allowed);
while (NULL != (slc = sh->slc_head))
{
- GNUNET_CONTAINER_DLL_remove (sh->slc_head,
- sh->slc_tail,
- slc);
+ GNUNET_CONTAINER_DLL_remove (sh->slc_head, sh->slc_tail, slc);
if (NULL != slc->listen_task)
GNUNET_SCHEDULER_cancel (slc->listen_task);
GNUNET_break (GNUNET_OK ==
@@ -2103,8 +1913,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
* @param msg AGPL request
*/
static void
-return_agpl (void *cls,
- const struct GNUNET_MessageHeader *msg)
+return_agpl (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
struct GNUNET_MQ_Handle *mq;
@@ -2114,15 +1923,10 @@ return_agpl (void *cls,
(void) msg;
slen = strlen (GNUNET_AGPL_URL) + 1;
- env = GNUNET_MQ_msg_extra (res,
- GNUNET_MESSAGE_TYPE_RESPONSE_AGPL,
- slen);
- memcpy (&res[1],
- GNUNET_AGPL_URL,
- slen);
+ env = GNUNET_MQ_msg_extra (res, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, slen);
+ memcpy (&res[1], GNUNET_AGPL_URL, slen);
mq = GNUNET_SERVICE_client_get_mq (client);
- GNUNET_MQ_send (mq,
- env);
+ GNUNET_MQ_send (mq, env);
GNUNET_SERVICE_client_continue (client);
}
@@ -2179,17 +1983,14 @@ GNUNET_SERVICE_start (const char *service_name,
sh->connect_cb = connect_cb;
sh->disconnect_cb = disconnect_cb;
sh->cb_cls = cls;
- sh->handlers = GNUNET_MQ_copy_handlers2 (handlers,
- &return_agpl,
- NULL);
+ sh->handlers = GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
if (GNUNET_OK != setup_service (sh))
{
GNUNET_free_non_null (sh->handlers);
GNUNET_free (sh);
return NULL;
}
- do_resume (sh,
- SUSPEND_STATE_NONE);
+ do_resume (sh, SUSPEND_STATE_NONE);
return sh;
}
@@ -2279,24 +2080,21 @@ GNUNET_SERVICE_run_ (int argc,
int ret;
int err;
- struct GNUNET_GETOPT_CommandLineOption service_options[] = {
- GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
- GNUNET_GETOPT_option_flag ('d',
- "daemonize",
- gettext_noop (
- "do daemonize (detach from terminal)"),
- &do_daemonize),
- GNUNET_GETOPT_option_help (NULL),
- GNUNET_GETOPT_option_loglevel (&loglev),
- GNUNET_GETOPT_option_logfile (&logfile),
- GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption service_options[] =
+ {GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
+ GNUNET_GETOPT_option_flag ('d',
+ "daemonize",
+ gettext_noop (
+ "do daemonize (detach from terminal)"),
+ &do_daemonize),
+ GNUNET_GETOPT_option_help (NULL),
+ GNUNET_GETOPT_option_loglevel (&loglev),
+ GNUNET_GETOPT_option_logfile (&logfile),
+ GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
+ GNUNET_GETOPT_OPTION_END};
err = 1;
- memset (&sh,
- 0,
- sizeof (sh));
+ memset (&sh, 0, sizeof (sh));
xdg = getenv ("XDG_CONFIG_HOME");
if (NULL != xdg)
GNUNET_asprintf (&cfg_filename,
@@ -2305,8 +2103,8 @@ GNUNET_SERVICE_run_ (int argc,
DIR_SEPARATOR_STR,
GNUNET_OS_project_data_get ()->config_file);
else
- cfg_filename = GNUNET_strdup (
- GNUNET_OS_project_data_get ()->user_config_file);
+ cfg_filename =
+ GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
sh.ready_confirm_fd = -1;
sh.options = options;
sh.cfg = cfg = GNUNET_CONFIGURATION_create ();
@@ -2322,10 +2120,7 @@ GNUNET_SERVICE_run_ (int argc,
logfile = NULL;
opt_cfg_filename = NULL;
do_daemonize = 0;
- ret = GNUNET_GETOPT_run (service_name,
- service_options,
- argc,
- argv);
+ ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv);
if (GNUNET_SYSERR == ret)
goto shutdown;
if (GNUNET_NO == ret)
@@ -2333,20 +2128,15 @@ GNUNET_SERVICE_run_ (int argc,
err = 0;
goto shutdown;
}
- if (GNUNET_OK != GNUNET_log_setup (service_name,
- loglev,
- logfile))
+ if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile))
{
GNUNET_break (0);
goto shutdown;
}
if (NULL != opt_cfg_filename)
{
- if ( (GNUNET_YES !=
- GNUNET_DISK_file_test (opt_cfg_filename)) ||
- (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- opt_cfg_filename)) )
+ if ((GNUNET_YES != GNUNET_DISK_file_test (opt_cfg_filename)) ||
+ (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_filename)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration file `%s', exit ...\n"),
@@ -2356,12 +2146,9 @@ GNUNET_SERVICE_run_ (int argc,
}
else
{
- if (GNUNET_YES ==
- GNUNET_DISK_file_test (cfg_filename))
+ if (GNUNET_YES == GNUNET_DISK_file_test (cfg_filename))
{
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- cfg_filename))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_filename))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration file `%s', exit ...\n"),
@@ -2371,9 +2158,7 @@ GNUNET_SERVICE_run_ (int argc,
}
else
{
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- NULL))
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_ ("Malformed configuration, exit ...\n"));
@@ -2383,8 +2168,7 @@ GNUNET_SERVICE_run_ (int argc,
}
if (GNUNET_OK != setup_service (&sh))
goto shutdown;
- if ( (1 == do_daemonize) &&
- (GNUNET_OK != detach_terminal (&sh)) )
+ if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sh)))
{
GNUNET_break (0);
goto shutdown;
@@ -2395,64 +2179,51 @@ GNUNET_SERVICE_run_ (int argc,
"Service `%s' runs with configuration from `%s'\n",
service_name,
(NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
- if ((GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sh.cfg,
- "TESTING",
- "SKEW_OFFSET",
- &skew_offset)) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sh.cfg,
- "TESTING",
- "SKEW_VARIANCE",
- &skew_variance)))
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sh.cfg,
+ "TESTING",
+ "SKEW_OFFSET",
+ &skew_offset)) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sh.cfg,
+ "TESTING",
+ "SKEW_VARIANCE",
+ &skew_variance)))
{
clock_offset = skew_offset - skew_variance;
GNUNET_TIME_set_offset (clock_offset);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Skewing clock by %dll ms\n",
- clock_offset);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset);
}
GNUNET_RESOLVER_connect (sh.cfg);
/* actually run service */
err = 0;
- GNUNET_SCHEDULER_run (&service_main,
- &sh);
+ GNUNET_SCHEDULER_run (&service_main, &sh);
/* shutdown */
if (1 == do_daemonize)
pid_file_delete (&sh);
- shutdown:
+shutdown:
if (-1 != sh.ready_confirm_fd)
{
- if (1 != WRITE (sh.ready_confirm_fd,
- err ? "I" : "S",
- 1))
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING,
- "write");
- GNUNET_break (0 == CLOSE (sh.ready_confirm_fd));
+ if (1 != write (sh.ready_confirm_fd, err ? "I" : "S", 1))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_break (0 == close (sh.ready_confirm_fd));
}
#if HAVE_MALLINFO
{
char *counter;
- if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (sh.cfg,
- service_name,
- "GAUGER_HEAP")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sh.cfg,
- service_name,
- "GAUGER_HEAP",
- &counter)) )
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sh.cfg,
+ service_name,
+ "GAUGER_HEAP")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sh.cfg,
+ service_name,
+ "GAUGER_HEAP",
+ &counter)))
{
struct mallinfo mi;
mi = mallinfo ();
- GAUGER (service_name,
- counter,
- mi.usmblks,
- "blocks");
+ GAUGER (service_name, counter, mi.usmblks, "blocks");
GNUNET_free (counter);
}
}
@@ -2479,8 +2250,7 @@ GNUNET_SERVICE_run_ (int argc,
void
GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
{
- do_suspend (sh,
- SUSPEND_STATE_APP);
+ do_suspend (sh, SUSPEND_STATE_APP);
}
@@ -2492,8 +2262,7 @@ GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
void
GNUNET_SERVICE_resume (struct GNUNET_SERVICE_Handle *sh)
{
- do_resume (sh,
- SUSPEND_STATE_APP);
+ do_resume (sh, SUSPEND_STATE_APP);
}
@@ -2511,8 +2280,7 @@ resume_client_receive (void *cls)
c->recv_task = NULL;
/* first, check if there is still something in the buffer */
- ret = GNUNET_MST_next (c->mst,
- GNUNET_YES);
+ ret = GNUNET_MST_next (c->mst, GNUNET_YES);
if (GNUNET_SYSERR == ret)
{
if (NULL == c->drop_task)
@@ -2527,11 +2295,10 @@ resume_client_receive (void *cls)
/* need to receive more data from the network first */
if (NULL != c->recv_task)
return;
- c->recv_task
- = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- c->sock,
- &service_client_recv,
- c);
+ c->recv_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ c->sock,
+ &service_client_recv,
+ c);
}
@@ -2553,9 +2320,7 @@ GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
GNUNET_SCHEDULER_cancel (c->warn_task);
c->warn_task = NULL;
}
- c->recv_task
- = GNUNET_SCHEDULER_add_now (&resume_client_receive,
- c);
+ c->recv_task = GNUNET_SCHEDULER_add_now (&resume_client_receive, c);
}
@@ -2598,20 +2363,18 @@ finish_client_drop (void *cls)
GNUNET_MQ_destroy (c->mq);
if (GNUNET_NO == c->persist)
{
- GNUNET_break (GNUNET_OK ==
- GNUNET_NETWORK_socket_close (c->sock));
- if ( (0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
- (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) )
- do_resume (sh,
- SUSPEND_STATE_EMFILE);
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (c->sock));
+ if ((0 != (SUSPEND_STATE_EMFILE & sh->suspend_state)) &&
+ (0 == (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)))
+ do_resume (sh, SUSPEND_STATE_EMFILE);
}
else
{
GNUNET_NETWORK_socket_free_memory_only_ (c->sock);
}
GNUNET_free (c);
- if ( (0 != (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) &&
- (GNUNET_NO == have_non_monitor_clients (sh)) )
+ if ((0 != (SUSPEND_STATE_SHUTDOWN & sh->suspend_state)) &&
+ (GNUNET_NO == have_non_monitor_clients (sh)))
GNUNET_SERVICE_shutdown (sh);
}
@@ -2640,8 +2403,7 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
void *backtrace_array[MAX_TRACE_DEPTH];
int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
char **backtrace_strings =
- backtrace_symbols (backtrace_array,
- t->num_backtrace_strings);
+ backtrace_symbols (backtrace_array, t->num_backtrace_strings);
for (unsigned int i = 0; i < num_backtrace_strings; i++)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"client drop trace %u: %s\n",
@@ -2655,13 +2417,9 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
GNUNET_assert (0);
return;
}
- GNUNET_CONTAINER_DLL_remove (sh->clients_head,
- sh->clients_tail,
- c);
+ GNUNET_CONTAINER_DLL_remove (sh->clients_head, sh->clients_tail, c);
if (NULL != sh->disconnect_cb)
- sh->disconnect_cb (sh->cb_cls,
- c,
- c->user_context);
+ sh->disconnect_cb (sh->cb_cls, c, c->user_context);
if (NULL != c->warn_task)
{
GNUNET_SCHEDULER_cancel (c->warn_task);
@@ -2677,8 +2435,7 @@ GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
GNUNET_SCHEDULER_cancel (c->send_task);
c->send_task = NULL;
}
- c->drop_task = GNUNET_SCHEDULER_add_now (&finish_client_drop,
- c);
+ c->drop_task = GNUNET_SCHEDULER_add_now (&finish_client_drop, c);
}
@@ -2693,8 +2450,7 @@ GNUNET_SERVICE_shutdown (struct GNUNET_SERVICE_Handle *sh)
struct GNUNET_SERVICE_Client *client;
if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
- do_suspend (sh,
- SUSPEND_STATE_SHUTDOWN);
+ do_suspend (sh, SUSPEND_STATE_SHUTDOWN);
while (NULL != (client = sh->clients_head))
GNUNET_SERVICE_client_drop (client);
}
@@ -2716,8 +2472,8 @@ void
GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
{
c->is_monitor = GNUNET_YES;
- if ( ((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state))&&
- (GNUNET_NO == have_non_monitor_clients (c->sh)) ) )
+ if (((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state)) &&
+ (GNUNET_NO == have_non_monitor_clients (c->sh))))
GNUNET_SERVICE_shutdown (c->sh);
}