summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client.c6
-rw-r--r--compat.h1
-rw-r--r--compat/systemd.c6
3 files changed, 13 insertions, 0 deletions
diff --git a/client.c b/client.c
index df6cee94..7f712ffb 100644
--- a/client.c
+++ b/client.c
@@ -284,6 +284,12 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
log_debug("flags are %#llx", (unsigned long long)client_flags);
/* Initialize the client socket and start the server. */
+#ifdef HAVE_SYSTEMD
+ if (systemd_activated()) {
+ /* socket-based activation, do not even try to be a client. */
+ fd = server_start(client_proc, flags, base, 0, NULL);
+ } else
+#endif
fd = client_connect(base, socket_path, client_flags);
if (fd == -1) {
if (errno == ECONNREFUSED) {
diff --git a/compat.h b/compat.h
index 6eb97619..aefc0d38 100644
--- a/compat.h
+++ b/compat.h
@@ -423,6 +423,7 @@ void *recallocarray(void *, size_t, size_t, size_t);
#ifdef HAVE_SYSTEMD
/* systemd.c */
+int systemd_activated(void);
int systemd_create_socket(int, char **);
#endif
diff --git a/compat/systemd.c b/compat/systemd.c
index 9a3adbb3..cce42ed4 100644
--- a/compat/systemd.c
+++ b/compat/systemd.c
@@ -26,6 +26,12 @@
#include "tmux.h"
int
+systemd_activated(void)
+{
+ return (sd_listen_fds(0) >= 1);
+}
+
+int
systemd_create_socket(int flags, char **cause)
{
int fds;