~kennylevinsen/seatd-devel

seatd: shut down builtin server when seat is closed v1 PROPOSED

Lucas Stach: 1
 seatd: shut down builtin server when seat is closed

 1 files changed, 11 insertions(+), 3 deletions(-)
Am Montag, dem 23.01.2023 um 23:40 +0100 schrieb Kenny Levinsen:
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~kennylevinsen/seatd-devel/patches/38306/mbox | git am -3
Learn more about email & git

[PATCH] seatd: shut down builtin server when seat is closed Export this patch

This shuts down the spawned builtin server process by sending it a
SIGTERM when the seat is closed.
---
This is probably trying to fix the same issue as 795cf169e779
("seatd: Shut down on client disconnect in builtin"), but I can't see
how this is supposed to work. AFAICS nothing defines LIBSEAT and I
don't see any way to distinguish between a real seatd server and the
builtin one at that spot in the code.
---
 libseat/backend/seatd.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libseat/backend/seatd.c b/libseat/backend/seatd.c
index abcd2a5bf5cf..dd7977391950 100644
--- a/libseat/backend/seatd.c
+++ b/libseat/backend/seatd.c
@@ -2,6 +2,7 @@
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -38,6 +39,7 @@ struct backend_seatd {
	struct linked_list pending_events;
	bool awaiting_pong;
	bool error;
	pid_t builtin_server_pid;

	char seat_name[MAX_SEAT_LEN];
};
@@ -354,7 +356,8 @@ static int dispatch_and_execute(struct libseat *base, int timeout) {
	return predispatch + postdispatch;
}

static struct libseat *_open_seat(const struct libseat_seat_listener *listener, void *data, int fd) {
static struct libseat *_open_seat(const struct libseat_seat_listener *listener, void *data,
				  int fd, pid_t server_pid) {
	assert(listener != NULL);
	assert(listener->enable_seat != NULL && listener->disable_seat != NULL);
	struct backend_seatd *backend = calloc(1, sizeof(struct backend_seatd));
@@ -366,6 +369,7 @@ static struct libseat *_open_seat(const struct libseat_seat_listener *listener,
	backend->seat_listener = listener;
	backend->seat_listener_data = data;
	backend->connection.fd = fd;
	backend->builtin_server_pid = server_pid;
	backend->base.impl = &seatd_impl;
	linked_list_init(&backend->pending_events);

@@ -408,7 +412,7 @@ static struct libseat *open_seat(const struct libseat_seat_listener *listener, v
		return NULL;
	}

	return _open_seat(listener, data, fd);
	return _open_seat(listener, data, fd, -1);
}

static int close_seat(struct libseat *base) {
@@ -427,6 +431,10 @@ static int close_seat(struct libseat *base) {
	}

	execute_events(backend);

	if (backend->builtin_server_pid != -1)
		kill(backend->builtin_server_pid, SIGTERM);

	destroy(backend);
	return 0;

@@ -647,7 +655,7 @@ static struct libseat *builtin_open_seat(const struct libseat_seat_listener *lis
	} else {
		close(fds[0]);
		int fd = fds[1];
		return _open_seat(listener, data, fd);
		return _open_seat(listener, data, fd, pid);
	}
}

-- 
2.39.0
On Thu, Jan 19 2023 at 07:14:17 PM +01:00:00, Lucas Stach 
<l.stach@pengutronix.de> wrote: