aboutsummaryrefslogtreecommitdiff
path: root/libseat/backend/seatd.c
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-08-01 16:53:34 +0200
committerKenny Levinsen <kl@kl.wtf>2020-08-01 17:02:28 +0200
commit6f6f5de15431cfb9f8961359e96d32eaeb15bcad (patch)
treeb315c14fe7040e6f192382298fa4fe7368eaec3f /libseat/backend/seatd.c
parent957483fde564d0313a842577602d6bf5de314871 (diff)
seatd: Perform clean server shutdown
Diffstat (limited to 'libseat/backend/seatd.c')
-rw-r--r--libseat/backend/seatd.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/libseat/backend/seatd.c b/libseat/backend/seatd.c
index 654b5bb..1b1523e 100644
--- a/libseat/backend/seatd.c
+++ b/libseat/backend/seatd.c
@@ -497,6 +497,26 @@ const struct libseat_impl seatd_impl = {
};
#ifdef BUILTIN_ENABLED
+#include <signal.h>
+
+static int set_deathsig(int signal);
+
+#if defined(__linux__)
+#include <sys/prctl.h>
+
+static int set_deathsig(int signal) {
+ return prctl(PR_SET_PDEATHSIG, signal);
+}
+#elif defined(__FreeBSD__)
+#include <sys/procctl.h>
+
+static int set_deathsig(int signal) {
+ return procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &signal);
+}
+#else
+#error Unsupported platform
+#endif
+
static struct libseat *builtin_open_seat(struct libseat_seat_listener *listener, void *data) {
int fds[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
@@ -518,11 +538,13 @@ static struct libseat *builtin_open_seat(struct libseat_seat_listener *listener,
if (server_add_client(server, fd) == -1) {
exit(1);
}
+ set_deathsig(SIGTERM);
while (server->running) {
if (poller_poll(server->poller) == -1) {
exit(1);
}
}
+ server_destroy(server);
close(fd);
exit(0);
} else {