aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/listen.c63
1 files changed, 38 insertions, 25 deletions
diff --git a/src/listen.c b/src/listen.c
index f1ca7e17c..dc777eae6 100644
--- a/src/listen.c
+++ b/src/listen.c
@@ -214,42 +214,55 @@ listen_add_port(unsigned int port, GError **error)
#endif /* HAVE_TCP */
}
+#ifdef HAVE_UN
+/**
+ * Add a listener on a Unix domain socket.
+ *
+ * @param path the absolute socket path
+ * @param error location to store the error occuring, or NULL to ignore errors
+ * @return true on success
+ */
static bool
-listen_add_config_param(unsigned int port,
- const struct config_param *param,
- GError **error)
+listen_add_path(const char *path, GError **error)
{
+ size_t path_length;
+ struct sockaddr_un s_un;
+ const struct sockaddr *addrp = (const struct sockaddr *)&s_un;
+ socklen_t addrlen = sizeof(s_un);
bool success;
- const struct sockaddr *addrp;
- socklen_t addrlen;
- if (!param || 0 == strcmp(param->value, "any")) {
- return listen_add_port(port, error);
-#ifdef HAVE_UN
- } else if (param->value[0] == '/') {
- size_t path_length;
- struct sockaddr_un s_un;
+ path_length = strlen(path);
+ if (path_length >= sizeof(s_un.sun_path))
+ g_error("unix socket path is too long");
- path_length = strlen(param->value);
- if (path_length >= sizeof(s_un.sun_path))
- g_error("unix socket path is too long");
+ unlink(path);
- unlink(param->value);
+ s_un.sun_family = AF_UNIX;
+ memcpy(s_un.sun_path, path, path_length + 1);
- s_un.sun_family = AF_UNIX;
- memcpy(s_un.sun_path, param->value, path_length + 1);
+ success = listen_add_address(PF_UNIX, addrp, addrlen, error);
+ if (!success)
+ return false;
- addrp = (const struct sockaddr *)&s_un;
- addrlen = sizeof(s_un);
+ /* allow everybody to connect */
+ chmod(path, 0666);
- success = listen_add_address(PF_UNIX, addrp, addrlen, error);
- if (!success)
- return false;
+ return true;
+}
+#endif /* HAVE_UN */
- /* allow everybody to connect */
- chmod(param->value, 0666);
+static bool
+listen_add_config_param(unsigned int port,
+ const struct config_param *param,
+ GError **error)
+{
+ bool success;
- return true;
+ if (!param || 0 == strcmp(param->value, "any")) {
+ return listen_add_port(port, error);
+#ifdef HAVE_UN
+ } else if (param->value[0] == '/') {
+ return listen_add_path(param->value, error);
#endif /* HAVE_UN */
} else {
#ifdef HAVE_TCP