diff options
author | Eckhart Wörner <ewoerner@kde.org> | 2011-04-29 14:27:58 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-04-29 14:27:58 -0400 |
commit | 5b963265dfdcc99ad37e06f82be17b25751e57a6 (patch) | |
tree | 9ca6d11370a762e2956f4c5b15008ba7ef58bd27 /sd_socket.c | |
parent | 20ee83fe8ab703e27e37bf2c348d1278667837e3 (diff) | |
download | gpsd-5b963265dfdcc99ad37e06f82be17b25751e57a6.tar.gz |
Mac OS X systemd activation for gpsd.
The attached patch allows to use gpsd together with socket activation
in systemd. The idea is that systemd listens to the control socket
and TCP sockets and, as soon as someone connects to them, starts gpsd
and passes the file descriptors over (without accept()ing itself).
Sockets are in the following order: fd 3 is the control socket,
followed by up to two TCP sockets (for IPv4 and IPv6). If no socket
passing happens, behaviour of gpsd should be the same as before.
For using this new feature, one could use the following config *skeleton*:
-> File /etc/systemd/system/gpsd.socket:
[Socket]
ListenStream=/var/run/gpsd.sock
ListenStream=127.0.0.1:2947
-> File /etc/systemd/system/gpsd.service:
[Unit]
Requires=gpsd.spcket
[Service]
type=simple
ExecStart=/usr/bin/gpsd -N
What has been tested:
- gpsd compiles fine with both systemd=true/false
- Socket activation on the TCP socket works (gpsd is started, version string
is sent)
What has not been tested:
- Socket activation on the control socket works
Signed-off-by: Eric S. Raymond <esr@thyrsus.com>
Diffstat (limited to 'sd_socket.c')
-rw-r--r-- | sd_socket.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sd_socket.c b/sd_socket.c new file mode 100644 index 00000000..8c8c7719 --- /dev/null +++ b/sd_socket.c @@ -0,0 +1,33 @@ +/* + * This file is Copyright (c) 2011 by Eckhart Wörner + * BSD terms apply: see the file COPYING in the distribution root for details. + */ + +#include <limits.h> +#include <stdlib.h> +#include <unistd.h> + +#include "sd_socket.h" + +int sd_get_socket_count(void) { + unsigned long n; + const char* env; + + env = getenv("LISTEN_PID"); + if (!env) + return 0; + + n = strtoul(env, NULL, 10); + if (n == ULONG_MAX || (pid_t)n != getpid()) + return 0; + + env = getenv("LISTEN_FDS"); + if (!env) + return 0; + + n = strtoul(env, NULL, 10); + if (n == ULONG_MAX) + return 0; + + return (int)n; +} |