Skip to content

Commit 9a760dc

Browse files
andrewshadurawertarbyte
authored andcommitted
Add systemd socket activation support and systemd unit files.
Signed-off-by: Andrew Shadura <[email protected]>
1 parent dd8e8c3 commit 9a760dc

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ DESTDIR:=/
33
BINDIR:=$(DESTDIR)/$(PREFIX)/sbin/
44
MANDIR:=$(DESTDIR)/$(PREFIX)/share/man/man1/
55

6+
PKGCONFIG = pkg-config
7+
HAVE_PKGCONFIG = $(shell $(PKGCONFIG) --version 2>/dev/null || echo no)
8+
ifneq ($(HAVE_PKGCONFIG),no)
9+
HAVE_SYSTEMD = $(shell $(PKGCONFIG) --exists libsystemd && echo 1 || echo 0)
10+
ifeq ($(HAVE_SYSTEMD),1)
11+
CPPFLAGS += -DHAVE_SYSTEMD=1
12+
CFLAGS += $(shell $(PKGCONFIG) --cflags libsystemd)
13+
LDLIBS += $(shell $(PKGCONFIG) --libs libsystemd)
14+
endif
15+
endif
16+
617
VERSION:=$(shell cat version.inc)
718

819
THD_COMPS := thd keystate trigger eventnames devices cmdsocket obey ignore uinput triggerparser

cmdsocket.c

+12
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@
1515
#include <fcntl.h>
1616
#include <unistd.h>
1717

18+
#ifdef HAVE_SYSTEMD
19+
#include <systemd/sd-daemon.h>
20+
#endif
21+
1822
#include "devtag.h"
1923
#include "devices.h"
2024
#include "command.h"
2125
#include "cmdsocket.h"
2226

2327
int bind_cmdsocket( char *name ) {
2428
int cmd_fd;
29+
30+
#ifdef HAVE_SYSTEMD
31+
if (sd_listen_fds(0) == 1) {
32+
fprintf(stderr, SD_DEBUG "Found socket passed from systemd\n");
33+
return SD_LISTEN_FDS_START + 0;
34+
}
35+
#endif
36+
2537
struct sockaddr_un addr;
2638
/* remove any stale files */
2739
struct stat sb;

systemd/triggerhappy.service

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Unit]
2+
Description=triggerhappy global hotkey daemon
3+
After=local-fs.target
4+
5+
[Service]
6+
Type=notify
7+
ExecStart=/usr/sbin/thd --triggers /etc/triggerhappy/triggers.d/ --socket /run/thd.socket

systemd/triggerhappy.socket

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Socket]
2+
ListenStream=/run/thd.socket
3+
4+
[Install]
5+
WantedBy=sockets.target

thd.c

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include <pwd.h>
2525
#include <grp.h>
2626

27+
#ifdef HAVE_SYSTEMD
28+
#include <systemd/sd-daemon.h>
29+
#endif
30+
2731
#include "thd.h"
2832
#include "eventnames.h"
2933
#include "devices.h"
@@ -343,6 +347,10 @@ int start_readers(int argc, char *argv[], int start) {
343347
}
344348
}
345349

350+
#ifdef HAVE_SYSTEMD
351+
sd_notify(0, "READY=1");
352+
#endif
353+
346354
process_events();
347355

348356
return 0;

0 commit comments

Comments
 (0)