summaryrefslogtreecommitdiff
path: root/src/transport/tcp_service_legacy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/tcp_service_legacy.c')
-rw-r--r--src/transport/tcp_service_legacy.c458
1 files changed, 259 insertions, 199 deletions
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c
index 19508a39f..e59fa4a1c 100644
--- a/src/transport/tcp_service_legacy.c
+++ b/src/transport/tcp_service_legacy.c
@@ -224,7 +224,6 @@ struct LEGACY_SERVICE_Context
* Our options.
*/
enum LEGACY_SERVICE_Options options;
-
};
@@ -247,7 +246,7 @@ write_test (void *cls, size_t size, void *buf)
if (size < sizeof (struct GNUNET_MessageHeader))
{
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return 0; /* client disconnected */
+ return 0; /* client disconnected */
}
msg = (struct GNUNET_MessageHeader *) buf;
msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
@@ -265,7 +264,8 @@ write_test (void *cls, size_t size, void *buf)
* @param message the actual message
*/
static void
-handle_test (void *cls, struct GNUNET_SERVER_Client *client,
+handle_test (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
/* simply bounce message back to acknowledge */
@@ -273,7 +273,8 @@ handle_test (void *cls, struct GNUNET_SERVER_Client *client,
GNUNET_SERVER_notify_transmit_ready (client,
sizeof (struct GNUNET_MessageHeader),
GNUNET_TIME_UNIT_FOREVER_REL,
- &write_test, client))
+ &write_test,
+ client))
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
}
@@ -283,11 +284,12 @@ handle_test (void *cls, struct GNUNET_SERVER_Client *client,
* "callback_cls" fields will be replaced with the specific service
* struct.
*/
-static const struct GNUNET_SERVER_MessageHandler defhandlers[] = {
- {&handle_test, NULL, GNUNET_MESSAGE_TYPE_TEST,
- sizeof (struct GNUNET_MessageHeader)},
- {NULL, NULL, 0, 0}
-};
+static const struct GNUNET_SERVER_MessageHandler defhandlers[] =
+ {{&handle_test,
+ NULL,
+ GNUNET_MESSAGE_TYPE_TEST,
+ sizeof (struct GNUNET_MessageHeader)},
+ {NULL, NULL, 0, 0}};
/* ****************** service core routines ************** */
@@ -304,8 +306,10 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = {
* for unknown address family (will be denied).
*/
static int
-check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
- const struct sockaddr *addr, socklen_t addrlen)
+check_access (void *cls,
+ const struct GNUNET_CONNECTION_Credentials *uc,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
struct LEGACY_SERVICE_Context *sctx = cls;
const struct sockaddr_in *i4;
@@ -319,32 +323,33 @@ check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc,
i4 = (const struct sockaddr_in *) addr;
ret = ((NULL == sctx->v4_allowed) ||
(check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) &&
- ((NULL == sctx->v4_denied) ||
- (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
+ ((NULL == sctx->v4_denied) ||
+ (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr)));
break;
case AF_INET6:
GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
i6 = (const struct sockaddr_in6 *) addr;
ret = ((NULL == sctx->v6_allowed) ||
(check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) &&
- ((NULL == sctx->v6_denied) ||
- (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
+ ((NULL == sctx->v6_denied) ||
+ (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr)));
break;
#ifndef WINDOWS
case AF_UNIX:
- ret = GNUNET_OK; /* controlled using file-system ACL now */
+ ret = GNUNET_OK; /* controlled using file-system ACL now */
break;
#endif
default:
- LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"),
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _ ("Unknown address family %d\n"),
addr->sa_family);
return GNUNET_SYSERR;
}
if (GNUNET_OK != ret)
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Access from `%s' denied to service `%s'\n"),
- GNUNET_a2s (addr, addrlen),
+ _ ("Access from `%s' denied to service `%s'\n"),
+ GNUNET_a2s (addr, addrlen),
sctx->service_name);
}
return ret;
@@ -363,9 +368,10 @@ get_pid_file_name (struct LEGACY_SERVICE_Context *sctx)
{
char *pif;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name,
- "PIDFILE", &pif))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
+ sctx->service_name,
+ "PIDFILE",
+ &pif))
return NULL;
return pif;
}
@@ -387,7 +393,7 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
{
char *opt;
- if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
+ if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
@@ -395,12 +401,15 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret,
GNUNET_break (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
sctx->service_name,
- option, &opt));
+ option,
+ &opt));
if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt)))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
- opt, sctx->service_name, option);
+ _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
+ opt,
+ sctx->service_name,
+ option);
GNUNET_free (opt);
return GNUNET_SYSERR;
}
@@ -425,7 +434,7 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
{
char *opt;
- if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
+ if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option))
{
*ret = NULL;
return GNUNET_OK;
@@ -433,12 +442,15 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret,
GNUNET_break (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
sctx->service_name,
- option, &opt));
+ option,
+ &opt));
if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt)))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
- opt, sctx->service_name, option);
+ _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
+ opt,
+ sctx->service_name,
+ option);
GNUNET_free (opt);
return GNUNET_SYSERR;
}
@@ -507,10 +519,11 @@ add_unixpath (struct sockaddr **saddrs,
* set to NULL).
*/
int
-LEGACY_SERVICE_get_server_addresses (const char *service_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct sockaddr ***addrs,
- socklen_t ** addr_lens)
+LEGACY_SERVICE_get_server_addresses (
+ const char *service_name,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct sockaddr ***addrs,
+ socklen_t **addr_lens)
{
int disablev6;
struct GNUNET_NETWORK_Handle *desc;
@@ -534,8 +547,9 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6"))
{
if (GNUNET_SYSERR ==
- (disablev6 =
- GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
+ (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ service_name,
+ "DISABLEV6")))
return GNUNET_SYSERR;
}
else
@@ -554,8 +568,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
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));
+ _ (
+ "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
+ service_name,
+ strerror (errno));
disablev6 = GNUNET_YES;
}
else
@@ -568,18 +584,19 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
port = 0;
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"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
}
if (port > 65535)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Require valid port number for service `%s' in configuration!\n"),
+ _ ("Require valid port number for service `%s' in configuration!\n"),
service_name);
return GNUNET_SYSERR;
}
@@ -588,8 +605,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
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;
@@ -599,9 +618,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
#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_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
+ service_name,
+ "UNIXPATH",
+ &unixpath)) &&
(0 < strlen (unixpath)))
{
/* probe UNIX support */
@@ -610,12 +630,11 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
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,
- _("Using `%s' instead\n"),
- unixpath);
+ LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
}
#ifdef LINUX
abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
@@ -624,12 +643,9 @@ LEGACY_SERVICE_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)
{
@@ -645,9 +661,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
return GNUNET_SYSERR;
}
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
+ _ (
+ "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;
}
@@ -662,7 +679,8 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
if ((0 == port) && (NULL == unixpath))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
+ _ (
+ "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
service_name);
GNUNET_free_non_null (hostname);
return GNUNET_SYSERR;
@@ -693,7 +711,7 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
(NULL == res))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to resolve `%s': %s\n"),
+ _ ("Failed to resolve `%s': %s\n"),
hostname,
gai_strerror (ret));
GNUNET_free (hostname);
@@ -712,7 +730,7 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
if (0 == i)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to find %saddress for `%s'.\n"),
+ _ ("Failed to find %saddress for `%s'.\n"),
disablev6 ? "IPv4 " : "",
hostname);
freeaddrinfo (res);
@@ -738,11 +756,13 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name,
if ((disablev6) && (AF_INET6 == pos->ai_family))
continue;
if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
- continue; /* not TCP */
+ 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));
+ continue; /* huh? */
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Service `%s' will bind to `%s'\n",
+ service_name,
+ GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
if (AF_INET == pos->ai_family)
{
GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
@@ -854,7 +874,7 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
* 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))
+ if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
return GNUNET_NO;
fail = 1;
do
@@ -867,7 +887,7 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
break;
sctx->lsocks =
- GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1));
+ GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1));
fail2 = 1;
for (i = 0; i < count; i++)
@@ -877,12 +897,17 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
SOCKET s;
ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL);
- if ( (0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size) )
+ 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))
+ if ((0 == ret) || (sizeof (pi) != rd))
break;
- s = WSASocketA (pi.iAddressFamily, pi.iSocketType, pi.iProtocol, &pi, 0, WSA_FLAG_OVERLAPPED);
+ s = WSASocketA (pi.iAddressFamily,
+ pi.iSocketType,
+ pi.iProtocol,
+ &pi,
+ 0,
+ WSA_FLAG_OVERLAPPED);
sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s);
if (NULL == sctx->lsocks[i])
break;
@@ -893,15 +918,14 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
break;
sctx->lsocks[count] = NULL;
fail = 0;
- }
- while (fail);
+ } while (fail);
CloseHandle (lsocks_pipe);
if (fail)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access a pre-bound socket, will try to bind myself\n"));
+ _ ("Could not access a pre-bound socket, will try to bind myself\n"));
for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++)
GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i]));
GNUNET_free_non_null (sctx->lsocks);
@@ -943,15 +967,19 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
int flags;
#endif
- if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, "TIMEOUT"))
+ if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
+ sctx->service_name,
+ "TIMEOUT"))
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->service_name,
- "TIMEOUT", &idleout))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
+ sctx->service_name,
+ "TIMEOUT",
+ &idleout))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is invalid\n"),
- "TIMEOUT", sctx->service_name);
+ _ ("Specified value for `%s' of service `%s' is invalid\n"),
+ "TIMEOUT",
+ sctx->service_name);
return GNUNET_SYSERR;
}
sctx->timeout = idleout;
@@ -959,17 +987,19 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
else
sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
- if (GNUNET_CONFIGURATION_have_value
- (sctx->cfg, sctx->service_name, "TOLERANT"))
+ if (GNUNET_CONFIGURATION_have_value (sctx->cfg,
+ sctx->service_name,
+ "TOLERANT"))
{
if (GNUNET_SYSERR ==
- (tolerant =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
- "TOLERANT")))
+ (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
+ sctx->service_name,
+ "TOLERANT")))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Specified value for `%s' of service `%s' is invalid\n"),
- "TOLERANT", sctx->service_name);
+ _ ("Specified value for `%s' of service `%s' is invalid\n"),
+ "TOLERANT",
+ sctx->service_name);
return GNUNET_SYSERR;
}
}
@@ -979,11 +1009,11 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
#ifndef MINGW
errno = 0;
if ((NULL != (nfds = getenv ("LISTEN_FDS"))) &&
- (1 == SSCANF (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
+ (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
(cnt + 4 < FD_SETSIZE))
{
sctx->lsocks =
- GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
+ GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
while (0 < cnt--)
{
flags = fcntl (3 + cnt, F_GETFD);
@@ -992,8 +1022,8 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
(sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt))))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Could not access pre-bound socket %u, will try to bind myself\n"),
+ _ (
+ "Could not access pre-bound socket %u, will try to bind myself\n"),
(unsigned int) 3 + cnt);
cnt++;
while (sctx->lsocks[cnt] != NULL)
@@ -1014,17 +1044,18 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
#endif
if ((NULL == sctx->lsocks) &&
- (GNUNET_SYSERR ==
- LEGACY_SERVICE_get_server_addresses (sctx->service_name, sctx->cfg,
- &sctx->addrs, &sctx->addrlens)))
+ (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name,
+ sctx->cfg,
+ &sctx->addrs,
+ &sctx->addrlens)))
return GNUNET_SYSERR;
sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
- sctx->match_uid =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
- "UNIX_MATCH_UID");
- sctx->match_gid =
- GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name,
- "UNIX_MATCH_GID");
+ sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
+ sctx->service_name,
+ "UNIX_MATCH_UID");
+ sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
+ sctx->service_name,
+ "UNIX_MATCH_GID");
process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM");
process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM");
process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6");
@@ -1046,9 +1077,10 @@ get_user_name (struct LEGACY_SERVICE_Context *sctx)
{
char *un;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name,
- "USERNAME", &un))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg,
+ sctx->service_name,
+ "USERNAME",
+ &un))
return NULL;
return un;
}
@@ -1071,14 +1103,14 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
int len;
if (NULL == (pif = get_pid_file_name (sctx)))
- return GNUNET_OK; /* no file desired */
+ return GNUNET_OK; /* no file desired */
user = get_user_name (sctx);
rdir = GNUNET_strdup (pif);
len = strlen (rdir);
while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
len--;
rdir[len] = '\0';
- if (0 != ACCESS (rdir, F_OK))
+ if (0 != access (rdir, F_OK))
{
/* we get to create a directory -- and claim it
* as ours! */
@@ -1086,7 +1118,7 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
if ((NULL != user) && (0 < strlen (user)))
GNUNET_DISK_file_change_owner (rdir, user);
}
- if (0 != ACCESS (rdir, W_OK | X_OK))
+ if (0 != access (rdir, W_OK | X_OK))
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
GNUNET_free (rdir);
@@ -1095,7 +1127,7 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
return GNUNET_SYSERR;
}
GNUNET_free (rdir);
- pidfd = FOPEN (pif, "w");
+ pidfd = fopen (pif, "w");
if (NULL == pidfd)
{
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
@@ -1103,9 +1135,9 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
GNUNET_free_non_null (user);
return GNUNET_SYSERR;
}
- if (0 > FPRINTF (pidfd, "%u", pid))
+ if (0 > fprintf (pidfd, "%u", pid))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
- GNUNET_break (0 == FCLOSE (pidfd));
+ GNUNET_break (0 == fclose (pidfd));
if ((NULL != user) && (0 < strlen (user)))
GNUNET_DISK_file_change_owner (pif, user);
GNUNET_free_non_null (user);
@@ -1146,29 +1178,37 @@ service_task (void *cls)
GNUNET_RESOLVER_connect (sctx->cfg);
if (NULL != sctx->lsocks)
- sctx->server
- = GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
- sctx->timeout, sctx->require_found);
+ sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
+ sctx,
+ sctx->lsocks,
+ sctx->timeout,
+ sctx->require_found);
else
- sctx->server
- = GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
- sctx->timeout, sctx->require_found);
+ sctx->server = GNUNET_SERVER_create (&check_access,
+ sctx,
+ sctx->addrs,
+ sctx->addrlens,
+ sctx->timeout,
+ sctx->require_found);
if (NULL == sctx->server)
{
if (NULL != sctx->addrs)
for (i = 0; NULL != sctx->addrs[i]; i++)
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Failed to start `%s' at `%s'\n"),
- sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
+ _ ("Failed to start `%s' at `%s'\n"),
+ sctx->service_name,
+ GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
sctx->ret = GNUNET_SYSERR;
return;
}
#ifndef WINDOWS
if (NULL != sctx->addrs)
for (i = 0; NULL != sctx->addrs[i]; i++)
- if ((AF_UNIX == sctx->addrs[i]->sa_family)
- && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
- GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
+ if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
+ ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
+ GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
+ sctx->addrs[i])
+ ->sun_path,
sctx->match_uid,
sctx->match_gid);
#endif
@@ -1178,8 +1218,7 @@ service_task (void *cls)
{
/* install a task that will kill the server
* process if the scheduler ever gets a shutdown signal */
- sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- sctx);
+ sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx);
}
sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
@@ -1189,8 +1228,8 @@ service_task (void *cls)
GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers);
if (-1 != sctx->ready_confirm_fd)
{
- GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1));
- GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd));
+ GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1));
+ GNUNET_break (0 == close (sctx->ready_confirm_fd));
sctx->ready_confirm_fd = -1;
write_pid_file (sctx, getpid ());
}
@@ -1199,8 +1238,10 @@ service_task (void *cls)
i = 0;
while (NULL != sctx->addrs[i])
{
- LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"),
- sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _ ("Service `%s' runs at %s\n"),
+ sctx->service_name,
+ GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i]));
i++;
}
}
@@ -1222,7 +1263,7 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx)
int nullfd;
int filedes[2];
- if (0 != PIPE (filedes))
+ if (0 != pipe (filedes))
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe");
return GNUNET_SYSERR;
@@ -1238,9 +1279,9 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx)
/* 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)))
+ if (1 != read (filedes[0], &c, sizeof (char)))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
fflush (stdout);
switch (c)
@@ -1248,33 +1289,34 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx)
case '.':
exit (0);
case 'I':
- LOG (GNUNET_ERROR_TYPE_INFO, _("Service process failed to initialize\n"));
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _ ("Service process failed to initialize\n"));
break;
case 'S':
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process could not initialize server function\n"));
+ _ ("Service process could not initialize server function\n"));
break;
case 'X':
LOG (GNUNET_ERROR_TYPE_INFO,
- _("Service process failed to report status\n"));
+ _ ("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))
{
LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
- (void) CLOSE (nullfd);
+ (void) close (nullfd);
return GNUNET_SYSERR;
}
- (void) CLOSE (nullfd);
+ (void) close (nullfd);
/* Detach from controlling terminal */
pid = setsid ();
if (-1 == pid)
@@ -1301,7 +1343,7 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx)
char *user;
if (NULL == (user = get_user_name (sctx)))
- return GNUNET_OK; /* keep */
+ return GNUNET_OK; /* keep */
#ifndef MINGW
struct passwd *pws;
@@ -1310,8 +1352,9 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx)
if (NULL == pws)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Cannot obtain information about user `%s': %s\n"), user,
- errno == 0 ? _("No such user") : STRERROR (errno));
+ _ ("Cannot obtain information about user `%s': %s\n"),
+ user,
+ errno == 0 ? _ ("No such user") : strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
@@ -1324,8 +1367,10 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx)
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));
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Cannot change user/group to `%s': %s\n"),
+ user,
+ strerror (errno));
GNUNET_free (user);
return GNUNET_SYSERR;
}
@@ -1347,8 +1392,8 @@ pid_file_delete (struct LEGACY_SERVICE_Context *sctx)
char *pif = get_pid_file_name (sctx);
if (NULL == pif)
- return; /* no PID file */
- if (0 != UNLINK (pif))
+ return; /* no PID file */
+ if (0 != unlink (pif))
LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
GNUNET_free (pif);
}
@@ -1368,13 +1413,19 @@ pid_file_delete (struct LEGACY_SERVICE_Context *sctx)
* if we shutdown nicely
*/
int
-LEGACY_SERVICE_run (int argc, char *const *argv,
+LEGACY_SERVICE_run (int argc,
+ char *const *argv,
const char *service_name,
enum LEGACY_SERVICE_Options options,
LEGACY_SERVICE_Main task,
void *task_cls)
{
-#define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0)
+#define HANDLE_ERROR \
+ do \
+ { \
+ GNUNET_break (0); \
+ goto shutdown; \
+ } while (0)
int err;
int ret;
@@ -1391,18 +1442,18 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
struct GNUNET_CONFIGURATION_Handle *cfg;
const char *xdg;
- struct GNUNET_GETOPT_CommandLineOption service_options[] = {
- GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn),
- 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_fn),
+ 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;
do_daemonize = 0;
logfile = NULL;
@@ -1445,7 +1496,7 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Malformed configuration file `%s', exit ...\n"),
+ _ ("Malformed configuration file `%s', exit ...\n"),
opt_cfg_fn);
goto shutdown;
}
@@ -1455,13 +1506,13 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Malformed configuration, exit ...\n"));
+ _ ("Malformed configuration, exit ...\n"));
goto shutdown;
}
if (0 != strcmp (opt_cfg_fn, cfg_fn))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not access configuration file `%s'\n"),
- opt_cfg_fn);
+ _ ("Could not access configuration file `%s'\n"),
+ opt_cfg_fn);
}
if (GNUNET_OK != setup_service (&sctx))
goto shutdown;
@@ -1473,12 +1524,14 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
"Service `%s' runs with configuration from `%s'\n",
service_name,
opt_cfg_fn);
- if ((GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
- "SKEW_OFFSET", &skew_offset)) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING",
- "SKEW_VARIANCE", &skew_variance)))
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
+ "TESTING",
+ "SKEW_OFFSET",
+ &skew_offset)) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg,
+ "TESTING",
+ "SKEW_VARIANCE",
+ &skew_variance)))
{
clock_offset = skew_offset - skew_variance;
GNUNET_TIME_set_offset (clock_offset);
@@ -1495,21 +1548,21 @@ LEGACY_SERVICE_run (int argc, char *const *argv,
shutdown:
if (-1 != sctx.ready_confirm_fd)
{
- if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1))
+ if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1))
LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
- GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd));
+ GNUNET_break (0 == close (sctx.ready_confirm_fd));
}
#if HAVE_MALLINFO
{
char *counter;
- if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (sctx.cfg, service_name,
- "GAUGER_HEAP")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sctx.cfg, service_name,
- "GAUGER_HEAP",
- &counter)) )
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg,
+ service_name,
+ "GAUGER_HEAP")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg,
+ service_name,
+ "GAUGER_HEAP",
+ &counter)))
{
struct mallinfo mi;
@@ -1551,13 +1604,13 @@ shutdown:
struct LEGACY_SERVICE_Context *
LEGACY_SERVICE_start (const char *service_name,
const struct GNUNET_CONFIGURATION_Handle *cfg,
- enum LEGACY_SERVICE_Options options)
+ enum LEGACY_SERVICE_Options options)
{
int i;
struct LEGACY_SERVICE_Context *sctx;
sctx = GNUNET_new (struct LEGACY_SERVICE_Context);
- sctx->ready_confirm_fd = -1; /* no daemonizing */
+ sctx->ready_confirm_fd = -1; /* no daemonizing */
sctx->ret = GNUNET_OK;
sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
sctx->service_name = service_name;
@@ -1571,13 +1624,18 @@ LEGACY_SERVICE_start (const char *service_name,
return NULL;
}
if (NULL != sctx->lsocks)
- sctx->server =
- GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks,
- sctx->timeout, sctx->require_found);
+ sctx->server = GNUNET_SERVER_create_with_sockets (&check_access,
+ sctx,
+ sctx->lsocks,
+ sctx->timeout,
+ sctx->require_found);
else
- sctx->server =
- GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens,
- sctx->timeout, sctx->require_found);
+ sctx->server = GNUNET_SERVER_create (&check_access,
+ sctx,
+ sctx->addrs,
+ sctx->addrlens,
+ sctx->timeout,
+ sctx->require_found);
if (NULL == sctx->server)
{
@@ -1587,9 +1645,11 @@ LEGACY_SERVICE_start (const char *service_name,
#ifndef WINDOWS
if (NULL != sctx->addrs)
for (i = 0; NULL != sctx->addrs[i]; i++)
- if ((AF_UNIX == sctx->addrs[i]->sa_family)
- && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
- GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path,
+ if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
+ ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0]))
+ GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)
+ sctx->addrs[i])
+ ->sun_path,
sctx->match_uid,
sctx->match_gid);
#endif
@@ -1624,7 +1684,7 @@ LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx)
* @return NULL if there are no listen sockets, otherwise NULL-terminated
* array of listen sockets.
*/
-struct GNUNET_NETWORK_Handle *const*
+struct GNUNET_NETWORK_Handle *const *
LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx)
{
return ctx->lsocks;
@@ -1645,13 +1705,13 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx)
{
char *counter;
- if ( (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name,
- "GAUGER_HEAP")) &&
- (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (sctx->cfg, sctx->service_name,
- "GAUGER_HEAP",
- &counter)) )
+ if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg,
+ sctx->service_name,
+ "GAUGER_HEAP")) &&
+ (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg,
+ sctx->service_name,
+ "GAUGER_HEAP",
+ &counter)))
{
struct mallinfo mi;