Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ VKBD=uinput
PREFIX?=/usr/local

CONFIG_DIR?=/etc/keyd

ifneq (,$(wildcard /run/systemd/system))
SOCKET_PATH=/run/keyd.socket
else ifneq (,$(FORCE_SYSTEMD))
SOCKET_PATH=/run/keyd.socket
else
SOCKET_PATH=/var/run/keyd.socket
endif

CFLAGS:=-DVERSION=\"v$(VERSION)\ \($(COMMIT)\)\" \
-I/usr/local/include \
Expand Down Expand Up @@ -52,6 +59,7 @@ install:
sed -e 's#@PREFIX@#$(PREFIX)#' keyd.service.in > keyd.service; \
mkdir -p $(DESTDIR)$(PREFIX)/lib/systemd/system/; \
install -Dm644 keyd.service $(DESTDIR)$(PREFIX)/lib/systemd/system/keyd.service; \
install -Dm644 keyd.socket $(DESTDIR)$(PREFIX)/lib/systemd/system/keyd.socket; \
else \
echo "NOTE: systemd not found, you will need to manually add keyd to your system's init process."; \
fi
Expand Down
10 changes: 10 additions & 0 deletions keyd.socket
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=key remapping daemon socket

[Socket]
ListenStream=%t/keyd.socket
SocketMode=0660
SocketGroup=keyd

[Install]
WantedBy=sockets.target
11 changes: 11 additions & 0 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "keyd.h"

#include "sd-daemon.h"

/* TODO (maybe): settle on an API and publish the protocol. */

static void chgid()
Expand Down Expand Up @@ -46,6 +48,15 @@ int ipc_connect()

int ipc_create_server()
{
int n;
n = sd_listen_fds(0);
if (n > 1) {
fprintf(stderr, "Too many file descriptors received.\n");
exit(1);
} else if (n == 1) {
return SD_LISTEN_FDS_START + 0;
}

char lockpath[PATH_MAX];
int sd = socket(AF_UNIX, SOCK_STREAM, 0);
int lfd;
Expand Down
Loading