~kennylevinsen/seatd

065fd643c2a763ca5e9bd8aa4d0b258378b28803 — Kenny Levinsen 2 years ago 7784bae seat_select
Expose session ID in libseat API

This sends the seatd session ID to a seatd client, and exposes this in
the API. It is currently stubbed out for logind.
M examples/simpletest/main.c => examples/simpletest/main.c +2 -1
@@ 45,7 45,8 @@ int main(int argc, char *argv[]) {
		fprintf(stderr, "waiting for activation...\n");
		libseat_dispatch(backend, -1);
	}
	fprintf(stderr, "active!\n");
	fprintf(stderr, "active! seat name: %s, session id: %d\n", libseat_seat_name(backend),
		libseat_session(backend));

	int fd, device;
	device = libseat_open_device(backend, file, &fd);

M include/backend.h => include/backend.h +1 -0
@@ 20,6 20,7 @@ struct seat_impl {
	int (*disable_seat)(struct libseat *seat);
	int (*close_seat)(struct libseat *seat);
	const char *(*seat_name)(struct libseat *seat);
	int (*session)(struct libseat *seat);

	int (*open_device)(struct libseat *seat, const char *path, int *fd);
	int (*close_device)(struct libseat *seat, int device_id);

M include/libseat.h => include/libseat.h +6 -0
@@ 103,6 103,12 @@ int libseat_close_device(struct libseat *seat, int device_id);
const char *libseat_seat_name(struct libseat *seat);

/*
 * Retrieves the session ID of the seat that is currently made available
 * through the provided libseat instance.
 */
int libseat_session(struct libseat *seat);

/*
 * Requests that the seat switches session to the specified session number.
 * For seats that are VT-bound, the session number matches the VT number, and
 * switching session results in a VT switch.

M include/protocol.h => include/protocol.h +1 -0
@@ 50,6 50,7 @@ struct proto_client_switch_session {
};

struct proto_server_seat_opened {
	int session;
	uint16_t seat_name_len;
	// NULL-terminated byte-sequence seat_name_len long follows
};

M libseat/backend/logind.c => libseat/backend/logind.c +7 -0
@@ 245,6 245,12 @@ static const char *seat_name(struct libseat *base) {
	return backend->seat;
}

static int session(struct libseat *base) {
	(void)base;
	errno = ENOSYS;
	return -1;
}

static struct backend_logind *backend_logind_from_libseat_backend(struct libseat *base) {
	assert(base->impl == &logind_impl);
	return (struct backend_logind *)base;


@@ 682,6 688,7 @@ const struct seat_impl logind_impl = {
	.open_seat = logind_open_seat,
	.disable_seat = disable_seat,
	.close_seat = close_seat,
	.session = session,
	.seat_name = seat_name,
	.open_device = open_device,
	.close_device = close_device,

M libseat/backend/seatd.c => libseat/backend/seatd.c +9 -0
@@ 38,6 38,7 @@ struct backend_seatd {
	struct linked_list pending_events;
	bool error;

	int session;
	char seat_name[MAX_SEAT_LEN];
};



@@ 386,6 387,7 @@ static struct libseat *_open_seat(struct libseat_seat_listener *listener, void *
	if (size == SIZE_MAX || conn_get(backend, &rmsg, sizeof rmsg) == -1) {
		goto backend_error;
	}
	backend->session = rmsg.session;
	if (rmsg.seat_name_len != size - sizeof rmsg) {
		log_errorf("Invalid message: seat_name_len does not match remaining message size (%d != %zd)",
			   rmsg.seat_name_len, size);


@@ 445,6 447,11 @@ static const char *seat_name(struct libseat *base) {
	return backend->seat_name;
}

static int session(struct libseat *base) {
	struct backend_seatd *backend = backend_seatd_from_libseat_backend(base);
	return backend->session;
}

static int open_device(struct libseat *base, const char *path, int *fd) {
	struct backend_seatd *backend = backend_seatd_from_libseat_backend(base);
	if (backend->error) {


@@ 565,6 572,7 @@ const struct seat_impl seatd_impl = {
	.open_seat = open_seat,
	.disable_seat = disable_seat,
	.close_seat = close_seat,
	.session = session,
	.seat_name = seat_name,
	.open_device = open_device,
	.close_device = close_device,


@@ 650,6 658,7 @@ const struct seat_impl builtin_impl = {
	.open_seat = builtin_open_seat,
	.disable_seat = disable_seat,
	.close_seat = close_seat,
	.session = session,
	.seat_name = seat_name,
	.open_device = open_device,
	.close_device = close_device,

M libseat/libseat.c => libseat/libseat.c +5 -0
@@ 90,6 90,11 @@ const char *libseat_seat_name(struct libseat *seat) {
	return seat->impl->seat_name(seat);
}

int libseat_session(struct libseat *seat) {
	assert(seat && seat->impl);
	return seat->impl->session(seat);
}

int libseat_open_device(struct libseat *seat, const char *path, int *fd) {
	assert(seat && seat->impl);
	return seat->impl->open_device(seat, path, fd);

M seatd/client.c => seatd/client.c +1 -0
@@ 142,6 142,7 @@ static int handle_open_seat(struct client *client, char *seat_name) {
	size_t seat_name_len = strlen(seat_name);

	struct proto_server_seat_opened rmsg = {
		.session = client->session,
		.seat_name_len = (uint16_t)seat_name_len,
	};
	struct proto_header header = {