summaryrefslogtreecommitdiff
path: root/src/mhd/mhd_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mhd/mhd_config.c')
-rw-r--r--src/mhd/mhd_config.c75
1 files changed, 72 insertions, 3 deletions
diff --git a/src/mhd/mhd_config.c b/src/mhd/mhd_config.c
index e2471e9b5..31ec3e476 100644
--- a/src/mhd/mhd_config.c
+++ b/src/mhd/mhd_config.c
@@ -78,7 +78,7 @@ TALER_MHD_parse_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
section,
- "port",
+ "PORT",
&port))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
@@ -124,6 +124,7 @@ TALER_MHD_parse_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"unixpath `%s' is too long\n",
*unix_path);
+ GNUNET_free (*unix_path);
return GNUNET_SYSERR;
}
@@ -136,6 +137,7 @@ TALER_MHD_parse_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
section,
"UNIXPATH_MODE");
+ GNUNET_free (*unix_path);
return GNUNET_SYSERR;
}
errno = 0;
@@ -147,6 +149,7 @@ TALER_MHD_parse_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
"UNIXPATH_MODE",
"must be octal number");
GNUNET_free (modestring);
+ GNUNET_free (*unix_path);
return GNUNET_SYSERR;
}
GNUNET_free (modestring);
@@ -252,6 +255,7 @@ TALER_MHD_open_unix_path (const char *unix_path,
GNUNET_free (un);
return -1;
}
+
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (nh,
(void *) un,
@@ -319,6 +323,53 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
char *bind_to;
struct GNUNET_NETWORK_Handle *nh;
+ /* try systemd passing first */
+ {
+ const char *listen_pid;
+ const char *listen_fds;
+
+ /* check for systemd-style FD passing */
+ listen_pid = getenv ("LISTEN_PID");
+ listen_fds = getenv ("LISTEN_FDS");
+ if ( (NULL != listen_pid) &&
+ (NULL != listen_fds) &&
+ (getpid () == strtol (listen_pid,
+ NULL,
+ 10)) &&
+ (1 == strtoul (listen_fds,
+ NULL,
+ 10)) )
+ {
+ int fh;
+ int flags;
+
+ fh = 3;
+ flags = fcntl (fh,
+ F_GETFD);
+ if ( (-1 == flags) &&
+ (EBADF == errno) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Bad listen socket passed, ignored\n");
+ fh = -1;
+ }
+ flags |= FD_CLOEXEC;
+ if ( (-1 != fh) &&
+ (0 != fcntl (fh,
+ F_SETFD,
+ flags)) )
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "fcntl");
+ if (-1 != fh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Successfully obtained listen socket from hypervisor\n");
+ return fh;
+ }
+ }
+ }
+
+ /* now try configuration file */
*port = 0;
{
char *serve_unixpath;
@@ -332,8 +383,14 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
&unixpath_mode))
return -1;
if (NULL != serve_unixpath)
- return TALER_MHD_open_unix_path (serve_unixpath,
- unixpath_mode);
+ {
+ int ret;
+
+ ret = TALER_MHD_open_unix_path (serve_unixpath,
+ unixpath_mode);
+ GNUNET_free (serve_unixpath);
+ return ret;
+ }
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -390,6 +447,18 @@ TALER_MHD_bind (const struct GNUNET_CONFIGURATION_Handle *cfg,
freeaddrinfo (res);
return -1;
}
+ {
+ const int on = 1;
+
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_setsockopt (nh,
+ SOL_SOCKET,
+ SO_REUSEPORT,
+ &on,
+ sizeof(on)))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "setsockopt");
+ }
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (nh,
res->ai_addr,