--- /dev/null
+[Service]
+ExecStart=/usr/local/bin/tlspool -c /usr/local/etc/tlspool.conf
--- /dev/null
+[Socket]
+ListenStream=/var/run/tlspool.sock
+SocketUser=tlspool
+SocketGroup=tlspool
+SocketMode=0666
+
+[Install]
+WantedBy=sockets.target
#define TLSPOOL_INTERNAL_H
#include <stdint.h>
+#include <stdbool.h>
#include <tlspool/commands.h>
LIBS = $(GNUTLS_LIBS) $(P11KIT_LIBS) $(BDB_LIBS) $(TASN1_LIBS) -lpthread
+ifdef WITH_SYSTEMD
+CFLAGS += -DHAVE_SYSTEMD
+LIBS += -lsystemd-daemon
+endif
+
GNUTLS_CFLAGS = $(shell pkg-config --cflags gnutls)
GNUTLS_LIBS = $(shell pkg-config --libs gnutls)
P11KIT_CFLAGS = $(shell pkg-config --cflags p11-kit-1)
//NOTYET// #include <ldap.h>
+#ifdef HAVE_SYSTEMD
+# include <systemd/sd-daemon.h>
+#endif
+
#include <tlspool/internal.h>
//NOTYET// #include <libmemcached/memcached.h>
struct sockaddr_un sun;
int sox;
#ifndef CONFIG_PARSE_ONLY
+#ifndef HAVE_SYSTEMD
uid_t me = getuid ();
gid_t my = getgid ();
if (strlen (value) + 1 > sizeof (sun.sun_path)) {
exit (1);
}
}
+#else /* HAVE_SYSTEMD */
+ if (sd_listen_fds (0) != 1) {
+ fprintf (stderr, "TLS Pool should have received one socket\n");
+ exit (1);
+ }
+ sox = SD_LISTEN_FDS_START + 0;
+#endif /* HAVE_SYSTEMD */
register_server_socket (sox);
#endif
}
//TODO// setup syslogging
//UNDO// sigset_t sigblockmask;
+#ifdef HAVE_SYSTEMD
+ int pid = -2; /* Skip setsid() but otherwise proceed */
+#else
int pid = fork ();
+#endif
switch (pid) {
case -1:
perror ("Failed to fork daemon");
case 0:
// Detach from the startup session
setsid ();
+ case -2:
//TODO// close the common fd's 0/1/2
// Setup a SIGHUP handler to gracefully stop service
if (sigaction (SIGHUP, &hupaction, NULL) != 0) {