seatd: Perform clean server shutdown
This commit is contained in:
parent
957483fde5
commit
6f6f5de154
2 changed files with 25 additions and 0 deletions
|
@ -497,6 +497,26 @@ const struct libseat_impl seatd_impl = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef BUILTIN_ENABLED
|
#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) {
|
static struct libseat *builtin_open_seat(struct libseat_seat_listener *listener, void *data) {
|
||||||
int fds[2];
|
int fds[2];
|
||||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) {
|
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) {
|
if (server_add_client(server, fd) == -1) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
set_deathsig(SIGTERM);
|
||||||
while (server->running) {
|
while (server->running) {
|
||||||
if (poller_poll(server->poller) == -1) {
|
if (poller_poll(server->poller) == -1) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
server_destroy(server);
|
||||||
close(fd);
|
close(fd);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -41,6 +41,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
if (server_listen(server, path) == -1) {
|
if (server_listen(server, path) == -1) {
|
||||||
log_errorf("server_listen failed: %s", strerror(errno));
|
log_errorf("server_listen failed: %s", strerror(errno));
|
||||||
|
server_destroy(server);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +53,8 @@ int main(int argc, char *argv[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server_destroy(server);
|
||||||
unlink(path);
|
unlink(path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue