diff options
| -rw-r--r-- | libseat/backend/seatd.c | 22 | ||||
| -rw-r--r-- | seatd/seatd.c | 3 | 
2 files changed, 25 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 { diff --git a/seatd/seatd.c b/seatd/seatd.c index cfed341..c1cdccf 100644 --- a/seatd/seatd.c +++ b/seatd/seatd.c @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) {  	if (server_listen(server, path) == -1) {  		log_errorf("server_listen failed: %s", strerror(errno)); +		server_destroy(server);  		return 1;  	} @@ -52,6 +53,8 @@ int main(int argc, char *argv[]) {  			return 1;  		}  	} + +	server_destroy(server);  	unlink(path);  	return 0;  }  | 
