~kennylevinsen/seatd

e4c28227ec1de65ee6ce5bb52412a2a2cf4c0628 — Kenny Levinsen a month ago 79b9078
Normalize log texts a bit
5 files changed, 135 insertions(+), 135 deletions(-)

M common/terminal.c
M seatd/client.c
M seatd/seat.c
M seatd/seatd.c
M seatd/server.c
M common/terminal.c => common/terminal.c +19 -19
@@ 141,12 141,12 @@ static int get_tty_path(int tty, char path[static TTYPATHLEN]) {
int terminal_open(int vt) {
	char path[TTYPATHLEN];
	if (get_tty_path(vt, path) == -1) {
		log_errorf("could not generate tty path: %s", strerror(errno));
		log_errorf("Could not generate tty path: %s", strerror(errno));
		return -1;
	}
	int fd = open(path, O_RDWR | O_NOCTTY);
	if (fd == -1) {
		log_errorf("could not open target tty: %s", strerror(errno));
		log_errorf("Could not open target tty: %s", strerror(errno));
		return -1;
	}
	return fd;


@@ 158,7 158,7 @@ int terminal_current_vt(int fd) {
	int res = ioctl(fd, VT_GETSTATE, &st);
	close(fd);
	if (res == -1) {
		log_errorf("could not retrieve VT state: %s", strerror(errno));
		log_errorf("Could not retrieve VT state: %s", strerror(errno));
		return -1;
	}
	return st.v_active;


@@ 167,12 167,12 @@ int terminal_current_vt(int fd) {
	int res = ioctl(fd, VT_GETACTIVE, &vt);
	close(fd);
	if (res == -1) {
		log_errorf("could not retrieve VT state: %s", strerror(errno));
		log_errorf("Could not retrieve VT state: %s", strerror(errno));
		return -1;
	}

	if (vt == -1) {
		log_errorf("invalid vt: %d", vt);
		log_errorf("Invalid VT: %d", vt);
		return -1;
	}
	return vt;


@@ 182,7 182,7 @@ int terminal_current_vt(int fd) {
}

int terminal_set_process_switching(int fd, bool enable) {
	log_debugf("setting process switching to %d", enable);
	log_debugf("Setting process switching to %d", enable);
	struct vt_mode mode = {
		.mode = enable ? VT_PROCESS : VT_AUTO,
		.waitv = 0,


@@ 192,7 192,7 @@ int terminal_set_process_switching(int fd, bool enable) {
	};

	if (ioctl(fd, VT_SETMODE, &mode) == -1) {
		log_errorf("could not set VT mode to %s process switching: %s",
		log_errorf("Could not set VT mode to %s process switching: %s",
			   enable ? "enable" : "disable", strerror(errno));
		return -1;
	}


@@ 200,9 200,9 @@ int terminal_set_process_switching(int fd, bool enable) {
}

int terminal_switch_vt(int fd, int vt) {
	log_debugf("switching to VT %d", vt);
	log_debugf("Switching to VT %d", vt);
	if (ioctl(fd, VT_ACTIVATE, vt) == -1) {
		log_errorf("could not activate VT %d: %s", vt, strerror(errno));
		log_errorf("Could not activate VT %d: %s", vt, strerror(errno));
		return -1;
	}



@@ 210,9 210,9 @@ int terminal_switch_vt(int fd, int vt) {
}

int terminal_ack_release(int fd) {
	log_debug("acking VT release");
	log_debug("Acking VT release");
	if (ioctl(fd, VT_RELDISP, 1) == -1) {
		log_errorf("could not ack VT release: %s", strerror(errno));
		log_errorf("Could not ack VT release: %s", strerror(errno));
		return -1;
	}



@@ 220,9 220,9 @@ int terminal_ack_release(int fd) {
}

int terminal_ack_acquire(int fd) {
	log_debug("acking VT acquire");
	log_debug("Acking VT acquire");
	if (ioctl(fd, VT_RELDISP, VT_ACKACQ) == -1) {
		log_errorf("could not ack VT acquire: %s", strerror(errno));
		log_errorf("Could not ack VT acquire: %s", strerror(errno));
		return -1;
	}



@@ 230,16 230,16 @@ int terminal_ack_acquire(int fd) {
}

int terminal_set_keyboard(int fd, bool enable) {
	log_debugf("setting KD keyboard state to %d", enable);
	log_debugf("Setting KD keyboard state to %d", enable);
	if (ioctl(fd, KDSKBMODE, enable ? K_ENABLE : K_DISABLE) == -1) {
		log_errorf("could not set KD keyboard mode to %s: %s",
		log_errorf("Could not set KD keyboard mode to %s: %s",
			   enable ? "enabled" : "disabled", strerror(errno));
		return -1;
	}
#if defined(__FreeBSD__)
	struct termios tios;
	if (tcgetattr(fd, &tios) == -1) {
		log_errorf("could not set get terminal mode: %s", strerror(errno));
		log_errorf("Could not set get terminal mode: %s", strerror(errno));
		return -1;
	}
	if (enable) {


@@ 248,7 248,7 @@ int terminal_set_keyboard(int fd, bool enable) {
		cfmakeraw(&tios);
	}
	if (tcsetattr(fd, TCSAFLUSH, &tios) == -1) {
		log_errorf("could not set terminal mode to %s: %s", enable ? "sane" : "raw",
		log_errorf("Could not set terminal mode to %s: %s", enable ? "sane" : "raw",
			   strerror(errno));
		return -1;
	}


@@ 257,9 257,9 @@ int terminal_set_keyboard(int fd, bool enable) {
}

int terminal_set_graphics(int fd, bool enable) {
	log_debugf("setting KD graphics state to %d", enable);
	log_debugf("Setting KD graphics state to %d", enable);
	if (ioctl(fd, KDSETMODE, enable ? KD_GRAPHICS : KD_TEXT) == -1) {
		log_errorf("could not set KD graphics mode to %s: %s", enable ? "graphics" : "text",
		log_errorf("Could not set KD graphics mode to %s: %s", enable ? "graphics" : "text",
			   strerror(errno));
		return -1;
	}

M seatd/client.c => seatd/client.c +38 -34
@@ 120,7 120,7 @@ static int client_send_error(struct client *client, int error_code) {

	if (connection_put(&client->connection, &errheader, sizeof errheader) == -1 ||
	    connection_put(&client->connection, &errmsg, sizeof errmsg) == -1) {
		log_error("could not send error to client");
		log_errorf("Could not send error to client: %s", strerror(errno));
		return -1;
	}
	return 0;


@@ 135,18 135,18 @@ static char *client_get_seat_name(struct client *client) {
static int handle_open_seat(struct client *client) {
	char *seat_name = client_get_seat_name(client);
	if (seat_name == NULL) {
		log_error("could not get name of target seat");
		log_error("Could not get name of target seat");
		return -1;
	}

	struct seat *seat = server_get_seat(client->server, seat_name);
	if (seat == NULL) {
		log_error("unable to find seat by name");
		log_errorf("Could not find seat named %s", seat_name);
		return -1;
	}

	if (seat_add_client(seat, client) == -1) {
		log_errorf("unable to add client to target seat: %s", strerror(errno));
		log_errorf("Could not add client to target seat: %s", strerror(errno));
		return -1;
	}
	linked_list_remove(&client->link);


@@ 165,7 165,7 @@ static int handle_open_seat(struct client *client) {
	if (connection_put(&client->connection, &header, sizeof header) == -1 ||
	    connection_put(&client->connection, &rmsg, sizeof rmsg) == -1 ||
	    connection_put(&client->connection, seat_name, seat_name_len) == -1) {
		log_errorf("unable to write response: %s", strerror(errno));
		log_errorf("Could not write response: %s", strerror(errno));
		return -1;
	}



@@ 175,13 175,13 @@ static int handle_open_seat(struct client *client) {

static int handle_close_seat(struct client *client) {
	if (client->seat == NULL) {
		log_error("protocol error: no seat associated with client");
		log_error("Protocol error: no seat associated with client");
		return -1;
	}

	linked_list_remove(&client->link);
	if (seat_remove_client(client) == -1) {
		log_error("unable to remove client from seat");
		log_error("Could not remove client from seat");
		return -1;
	}
	linked_list_insert(&client->server->idle_clients, &client->link);


@@ 192,7 192,7 @@ static int handle_close_seat(struct client *client) {
	};

	if (connection_put(&client->connection, &header, sizeof header) == -1) {
		log_errorf("unable to write response: %s", strerror(errno));
		log_errorf("Could not write response: %s", strerror(errno));
		return -1;
	}



@@ 201,25 201,25 @@ static int handle_close_seat(struct client *client) {

static int handle_open_device(struct client *client, char *path) {
	if (client->seat == NULL) {
		log_error("protocol error: no seat associated with client");
		log_error("Protocol error: no seat associated with client");
		return -1;
	}

	struct seat_device *device = seat_open_device(client, path);
	if (device == NULL) {
		log_errorf("could not open device: %s", strerror(errno));
		log_errorf("Could not open device: %s", strerror(errno));
		goto fail;
	}

	int dupfd = dup(device->fd);
	if (dupfd == -1) {
		log_errorf("could not dup fd: %s", strerror(errno));
		log_errorf("Could not dup fd: %s", strerror(errno));
		seat_close_device(client, device);
		goto fail;
	}

	if (connection_put_fd(&client->connection, dupfd) == -1) {
		log_errorf("unable to queue fd for sending: %s", strerror(errno));
		log_errorf("Could not queue fd for sending: %s", strerror(errno));
		return -1;
	}



@@ 233,7 233,7 @@ static int handle_open_device(struct client *client, char *path) {

	if (connection_put(&client->connection, &header, sizeof header) == -1 ||
	    connection_put(&client->connection, &msg, sizeof msg) == -1) {
		log_errorf("unable to write response: %s", strerror(errno));
		log_errorf("Could not write response: %s", strerror(errno));
		return -1;
	}



@@ 245,19 245,19 @@ fail:

static int handle_close_device(struct client *client, int device_id) {
	if (client->seat == NULL) {
		log_error("protocol error: no seat associated with client");
		log_error("Protocol error: no seat associated with client");
		return -1;
	}

	struct seat_device *device = seat_find_device(client, device_id);
	if (device == NULL) {
		log_error("no such device");
		log_error("No such device");
		errno = EBADF;
		goto fail;
	}

	if (seat_close_device(client, device) == -1) {
		log_errorf("could not close device: %s", strerror(errno));
		log_errorf("Could not close device: %s", strerror(errno));
		goto fail;
	}



@@ 267,7 267,7 @@ static int handle_close_device(struct client *client, int device_id) {
	};

	if (connection_put(&client->connection, &header, sizeof header) == -1) {
		log_errorf("unable to write response: %s", strerror(errno));
		log_errorf("Could not write response: %s", strerror(errno));
		return -1;
	}



@@ 279,7 279,7 @@ fail:

static int handle_switch_session(struct client *client, int session) {
	if (client->seat == NULL) {
		log_error("protocol error: no seat associated with client");
		log_error("Protocol error: no seat associated with client");
		return -1;
	}



@@ 295,7 295,7 @@ error:

static int handle_disable_seat(struct client *client) {
	if (client->seat == NULL) {
		log_error("protocol error: no seat associated with client");
		log_error("Protocol error: no seat associated with client");
		return -1;
	}



@@ 314,7 314,7 @@ static int client_handle_opcode(struct client *client, uint16_t opcode, size_t s
	switch (opcode) {
	case CLIENT_OPEN_SEAT: {
		if (size != 0) {
			log_error("protocol error: invalid open_seat message");
			log_error("Protocol error: invalid open_seat message");
			return -1;
		}
		res = handle_open_seat(client);


@@ 322,7 322,7 @@ static int client_handle_opcode(struct client *client, uint16_t opcode, size_t s
	}
	case CLIENT_CLOSE_SEAT: {
		if (size != 0) {
			log_error("protocol error: invalid close_seat message");
			log_error("Protocol error: invalid close_seat message");
			return -1;
		}
		res = handle_close_seat(client);


@@ 333,11 333,11 @@ static int client_handle_opcode(struct client *client, uint16_t opcode, size_t s
		struct proto_client_open_device msg;
		if (sizeof msg > size || connection_get(&client->connection, &msg, sizeof msg) == -1 ||
		    sizeof msg + msg.path_len > size || msg.path_len > MAX_PATH_LEN) {
			log_error("protocol error: invalid open_device message");
			log_error("Protocol error: invalid open_device message");
			return -1;
		}
		if (connection_get(&client->connection, path, msg.path_len) == -1) {
			log_error("protocol error: invalid open_device message");
			log_error("Protocol error: invalid open_device message");
			return -1;
		}



@@ 347,7 347,7 @@ static int client_handle_opcode(struct client *client, uint16_t opcode, size_t s
	case CLIENT_CLOSE_DEVICE: {
		struct proto_client_close_device msg;
		if (sizeof msg > size || connection_get(&client->connection, &msg, sizeof msg) == -1) {
			log_error("protocol error: invalid close_device message");
			log_error("Protocol error: invalid close_device message");
			return -1;
		}



@@ 357,7 357,7 @@ static int client_handle_opcode(struct client *client, uint16_t opcode, size_t s
	case CLIENT_SWITCH_SESSION: {
		struct proto_client_switch_session msg;
		if (sizeof msg > size || connection_get(&client->connection, &msg, sizeof msg) == -1) {
			log_error("protocol error: invalid switch_session message");
			log_error("Protocol error: invalid switch_session message");
			return -1;
		}



@@ 366,14 366,14 @@ static int client_handle_opcode(struct client *client, uint16_t opcode, size_t s
	}
	case CLIENT_DISABLE_SEAT: {
		if (size != 0) {
			log_error("protocol error: invalid disable_seat message");
			log_error("Protocol error: invalid disable_seat message");
			return -1;
		}
		res = handle_disable_seat(client);
		break;
	}
	default:
		log_errorf("protocol error: unknown opcode: %d", opcode);
		log_errorf("Protocol error: unknown opcode: %d", opcode);
		res = -1;
		break;
	}


@@ 390,7 390,7 @@ int client_send_disable_seat(struct client *client) {
	};
	if (connection_put(&client->connection, &header, sizeof header) == -1 ||
	    connection_flush(&client->connection) == -1) {
		log_error("unable to send event");
		log_errorf("Could not send event: %s", strerror(errno));
		return -1;
	}
	return 0;


@@ 403,7 403,7 @@ int client_send_enable_seat(struct client *client) {
	};
	if (connection_put(&client->connection, &header, sizeof header) == -1 ||
	    connection_flush(&client->connection) == -1) {
		log_error("unable to send event");
		log_errorf("Could not send event: %s", strerror(errno));
		return -1;
	}
	return 0;


@@ 414,18 414,18 @@ int client_handle_connection(int fd, uint32_t mask, void *data) {

	struct client *client = data;
	if (mask & EVENT_ERROR) {
		log_error("connection error");
		log_error("Connection error");
		goto fail;
	}
	if (mask & EVENT_HANGUP) {
		log_info("client disconnected");
		log_info("Client disconnected");
		goto fail;
	}

	if (mask & EVENT_WRITABLE) {
		int len = connection_flush(&client->connection);
		if (len == -1 && errno != EAGAIN) {
			log_error("could not flush client connection");
			log_errorf("Could not flush client connection: %s", strerror(errno));
			goto fail;
		} else if (len >= 0) {
			event_source_fd_update(client->event_source, EVENT_READABLE);


@@ 434,8 434,12 @@ int client_handle_connection(int fd, uint32_t mask, void *data) {

	if (mask & EVENT_READABLE) {
		int len = connection_read(&client->connection);
		if (len == 0 || (len == -1 && errno != EAGAIN)) {
			log_error("could not read client connection");
		if (len == -1 && errno != EAGAIN) {
			log_errorf("Could not read client connection: %s", strerror(errno));
			goto fail;
		}
		if (len == 0) {
			log_error("Could not read client connection: zero-length read");
			goto fail;
		}


M seatd/seat.c => seatd/seat.c +62 -66
@@ 36,9 36,9 @@ struct seat *seat_create(const char *seat_name, bool vt_bound) {
		return NULL;
	}
	if (vt_bound) {
		log_infof("created VT-bound seat '%s'", seat_name);
		log_infof("Created VT-bound seat %s", seat_name);
	} else {
		log_infof("created seat '%s'", seat_name);
		log_infof("Created seat %s", seat_name);
	}
	return seat;
}


@@ 59,7 59,7 @@ void seat_destroy(struct seat *seat) {
static void seat_update_vt(struct seat *seat) {
	int tty0fd = terminal_open(0);
	if (tty0fd == -1) {
		log_errorf("unable to open tty0: %s", strerror(errno));
		log_errorf("Could not open tty0 to update VT: %s", strerror(errno));
		return;
	}
	seat->cur_vt = terminal_current_vt(tty0fd);


@@ 74,7 74,7 @@ static int vt_open(struct seat *seat, int vt) {
	}
	seat->cur_ttyfd = terminal_open(vt);
	if (seat->cur_ttyfd == -1) {
		log_errorf("could not open terminal for vt %d: %s", vt, strerror(errno));
		log_errorf("Could not open terminal for VT %d: %s", vt, strerror(errno));
		return -1;
	}



@@ 103,7 103,7 @@ static void vt_close(struct seat *seat) {
static int vt_close_num(int vt) {
	int ttyfd = terminal_open(vt);
	if (ttyfd == -1) {
		log_errorf("could not open terminal %s", strerror(errno));
		log_errorf("Could not open terminal to clean up VT %d: %s", vt, strerror(errno));
		return -1;
	}
	vt_close_fd(ttyfd);


@@ 114,7 114,7 @@ static int vt_close_num(int vt) {
static int vt_switch(struct seat *seat, int vt) {
	int ttyfd = terminal_open(seat->cur_vt);
	if (ttyfd == -1) {
		log_errorf("could not open terminal: %s", strerror(errno));
		log_errorf("Could not open terminal to switch to VT %d: %s", vt, strerror(errno));
		return -1;
	}
	terminal_set_process_switching(ttyfd, true);


@@ 126,7 126,7 @@ static int vt_switch(struct seat *seat, int vt) {
static int vt_ack(struct seat *seat, bool release) {
	int tty0fd = terminal_open(seat->cur_vt);
	if (tty0fd == -1) {
		log_errorf("unable to open tty0: %s", strerror(errno));
		log_errorf("Could not open tty0 to ack VT signal: %s", strerror(errno));
		return -1;
	}
	if (release) {


@@ 143,19 143,19 @@ int seat_add_client(struct seat *seat, struct client *client) {
	assert(client);

	if (client->seat != NULL) {
		log_error("cannot add client: client is already a member of a seat");
		log_error("Could not add client: client is already a member of a seat");
		errno = EBUSY;
		return -1;
	}

	if (seat->vt_bound && seat->active_client != NULL) {
		log_error("cannot add client: seat is VT-bound and an active client already exists");
		log_error("Could not add client: seat is VT-bound and has an active client");
		errno = EBUSY;
		return -1;
	}

	if (client->session != -1) {
		log_error("cannot add client: client cannot be reused");
		log_error("Could not add client: client cannot be reused");
		errno = EINVAL;
		return -1;
	}


@@ 163,7 163,7 @@ int seat_add_client(struct seat *seat, struct client *client) {
	if (seat->vt_bound) {
		seat_update_vt(seat);
		if (seat->cur_vt == -1) {
			log_error("could not determine VT for client");
			log_error("Could not determine VT for client");
			errno = EINVAL;
			return -1;
		}


@@ 173,7 173,7 @@ int seat_add_client(struct seat *seat, struct client *client) {
	}

	client->seat = seat;
	log_infof("added client %d", client->session);
	log_infof("Added client %d to %s", client->session, seat->seat_name);

	return 0;
}


@@ 195,7 195,7 @@ int seat_remove_client(struct client *client) {
	seat_close_client(client);

	client->seat = NULL;
	log_infof("removed client %d", client->session);
	log_infof("Removed client %d from %s", client->session, seat->seat_name);

	return 0;
}


@@ 222,8 222,10 @@ struct seat_device *seat_open_device(struct client *client, const char *path) {
	assert(strlen(path) > 0);
	struct seat *seat = client->seat;

	log_debugf("Opening device %s for client %d on %s", path, client->session, seat->seat_name);

	if (client->state != CLIENT_ACTIVE) {
		log_error("client is not active");
		log_error("Could open device: client is not active");
		errno = EPERM;
		return NULL;
	}


@@ 231,7 233,7 @@ struct seat_device *seat_open_device(struct client *client, const char *path) {

	char sanitized_path[PATH_MAX];
	if (realpath(path, sanitized_path) == NULL) {
		log_errorf("invalid path '%s': %s", path, strerror(errno));
		log_errorf("Could not canonicalize path %s: %s", path, strerror(errno));
		return NULL;
	}



@@ 241,7 243,7 @@ struct seat_device *seat_open_device(struct client *client, const char *path) {
	} else if (path_is_drm(sanitized_path)) {
		type = SEAT_DEVICE_TYPE_DRM;
	} else {
		log_errorf("invalid path '%s'", sanitized_path);
		log_errorf("%s is not a supported device type ", sanitized_path);
		errno = ENOENT;
		return NULL;
	}


@@ 266,34 268,34 @@ struct seat_device *seat_open_device(struct client *client, const char *path) {
	}

	if (device_count >= MAX_SEAT_DEVICES) {
		log_error("max seat devices exceeded");
		log_error("Client exceeded max seat devices");
		errno = EMFILE;
		return NULL;
	}

	int fd = open(sanitized_path, O_RDWR | O_NOCTTY | O_NOFOLLOW | O_CLOEXEC | O_NONBLOCK);
	if (fd == -1) {
		log_errorf("could not open file: %s", strerror(errno));
		log_errorf("Could not open file: %s", strerror(errno));
		return NULL;
	}

	switch (type) {
	case SEAT_DEVICE_TYPE_DRM:
		if (drm_set_master(fd) == -1) {
			log_errorf("could not make device fd drm master: %s", strerror(errno));
			log_errorf("Could not make device fd drm master: %s", strerror(errno));
		}
		break;
	case SEAT_DEVICE_TYPE_EVDEV:
		// Nothing to do here
		break;
	default:
		log_error("invalid seat device type");
		log_error("Invalid seat device type");
		abort();
	}

	device = calloc(1, sizeof(struct seat_device));
	if (device == NULL) {
		log_errorf("could not alloc device for '%s': %s", sanitized_path, strerror(errno));
		log_errorf("Allocation failed: %s", strerror(errno));
		close(fd);
		errno = ENOMEM;
		return NULL;


@@ 301,7 303,7 @@ struct seat_device *seat_open_device(struct client *client, const char *path) {

	device->path = strdup(sanitized_path);
	if (device->path == NULL) {
		log_errorf("could not dup path for '%s': %s", sanitized_path, strerror(errno));
		log_errorf("Allocation failed: %s", strerror(errno));
		close(fd);
		free(device);
		return NULL;


@@ 315,8 317,6 @@ struct seat_device *seat_open_device(struct client *client, const char *path) {
	linked_list_insert(&client->devices, &device->link);

done:
	log_debugf("seat: '%s', client: %d, path: '%s', device_id: %d, ref_cnt: %d",
		   seat->seat_name, client->session, path, device_id, device->ref_cnt);

	return device;
}


@@ 330,18 330,18 @@ static int seat_deactivate_device(struct seat_device *seat_device) {
	switch (seat_device->type) {
	case SEAT_DEVICE_TYPE_DRM:
		if (drm_drop_master(seat_device->fd) == -1) {
			log_errorf("could not revoke drm master on device fd: %s", strerror(errno));
			log_errorf("Could not revoke drm master on device fd: %s", strerror(errno));
			return -1;
		}
		break;
	case SEAT_DEVICE_TYPE_EVDEV:
		if (evdev_revoke(seat_device->fd) == -1) {
			log_errorf("could not revoke evdev on device fd: %s", strerror(errno));
			log_errorf("Could not revoke evdev on device fd: %s", strerror(errno));
			return -1;
		}
		break;
	default:
		log_error("invalid seat device type");
		log_error("Invalid seat device type");
		abort();
	}
	seat_device->active = false;


@@ 353,9 353,8 @@ int seat_close_device(struct client *client, struct seat_device *seat_device) {
	assert(client->seat);
	assert(seat_device && seat_device->fd != -1);

	log_debugf("seat: '%s', client: %d, path: '%s', device_id: %d, ref_cnt: %d",
		   client->seat->seat_name, client->session, seat_device->path,
		   seat_device->device_id, seat_device->ref_cnt);
	log_debugf("Closing device %s for client %d on %s", seat_device->path, client->session,
		   client->seat->seat_name);

	seat_device->ref_cnt--;
	if (seat_device->ref_cnt > 0) {


@@ 383,7 382,7 @@ static int seat_activate_device(struct client *client, struct seat_device *seat_
	switch (seat_device->type) {
	case SEAT_DEVICE_TYPE_DRM:
		if (drm_set_master(seat_device->fd) == -1) {
			log_errorf("could not make device fd drm master: %s", strerror(errno));
			log_errorf("Could not make device fd drm master: %s", strerror(errno));
		}
		seat_device->active = true;
		break;


@@ 391,7 390,7 @@ static int seat_activate_device(struct client *client, struct seat_device *seat_
		errno = EINVAL;
		return -1;
	default:
		log_error("invalid seat device type");
		log_error("Invalid seat device type");
		abort();
	}



@@ 407,11 406,11 @@ static int seat_activate(struct seat *seat) {

	struct client *next_client = NULL;
	if (seat->next_client != NULL) {
		log_debug("activating next queued client");
		log_debugf("Activating next queued client on %s", seat->seat_name);
		next_client = seat->next_client;
		seat->next_client = NULL;
	} else if (linked_list_empty(&seat->clients)) {
		log_info("no clients on seat to activate");
		log_infof("No clients on %s to activate", seat->seat_name);
		return -1;
	} else if (seat->vt_bound && seat->cur_vt == -1) {
		return -1;


@@ 420,16 419,16 @@ static int seat_activate(struct seat *seat) {
		     elem = elem->next) {
			struct client *client = (struct client *)elem;
			if (client->session == seat->cur_vt) {
				log_debugf("activating client belonging to VT %d", seat->cur_vt);
				log_debugf("Activating client belonging to VT %d", seat->cur_vt);
				next_client = client;
				goto done;
			}
		}

		log_infof("no clients belonging to VT %d to activate", seat->cur_vt);
		log_infof("No clients belonging to VT %d to activate", seat->cur_vt);
		return -1;
	} else {
		log_debug("activating first client on seat");
		log_debugf("Activating first client on %s", seat->seat_name);
		next_client = (struct client *)seat->clients.next;
	}



@@ 442,21 441,19 @@ int seat_open_client(struct seat *seat, struct client *client) {
	assert(client);

	if (client->state != CLIENT_NEW && client->state != CLIENT_DISABLED) {
		log_errorf("could not enable client %d: client is not new or disabled",
			   client->session);
		log_error("Could not enable client: client is not new or disabled");
		errno = EALREADY;
		return -1;
	}

	if (seat->active_client != NULL) {
		log_errorf("could not enable client %d: seat already has active client",
			   client->session);
		log_error("Could not enable client: seat already has an active client");
		errno = EBUSY;
		return -1;
	}

	if (seat->vt_bound && vt_open(seat, client->session) == -1) {
		log_errorf("could not open VT for client %d", client->session);
		log_error("Could not open VT for client");
		goto error;
	}



@@ 464,19 461,18 @@ int seat_open_client(struct seat *seat, struct client *client) {
	     elem = elem->next) {
		struct seat_device *device = (struct seat_device *)elem;
		if (seat_activate_device(client, device) == -1) {
			log_errorf("unable to activate '%s' for client %d: %s", device->path,
				   client->session, strerror(errno));
			log_errorf("Could not activate %s: %s", device->path, strerror(errno));
		}
	}

	client->state = CLIENT_ACTIVE;
	seat->active_client = client;
	if (client_send_enable_seat(client) == -1) {
		log_errorf("could not send enable signal to client %d", client->session);
		log_error("Could not send enable signal to client");
		goto error;
	}

	log_infof("enabled client %d", client->session);
	log_infof("Opened client %d on %s", client->session, seat->seat_name);
	return 0;

error:


@@ 495,7 491,7 @@ static int seat_close_client(struct client *client) {
	while (!linked_list_empty(&client->devices)) {
		struct seat_device *device = (struct seat_device *)client->devices.next;
		if (seat_close_device(client, device) == -1) {
			log_errorf("unable to close '%s': %s", device->path, strerror(errno));
			log_errorf("Could not close %s: %s", device->path, strerror(errno));
		}
	}



@@ 509,18 505,18 @@ static int seat_close_client(struct client *client) {
		if (was_current && seat->active_client == NULL) {
			// This client was current, but there were no clients
			// waiting to take this VT, so clean it up.
			log_debug("closing active VT");
			log_debug("Closing active VT");
			vt_close(seat);
		} else if (!was_current && client->state != CLIENT_CLOSED) {
			// This client was not current, but as the client was
			// running, we need to clean up the VT.
			log_debug("closing inactive VT");
			log_debug("Closing inactive VT");
			vt_close_num(client->session);
		}
	}

	client->state = CLIENT_CLOSED;
	log_infof("closed client %d", client->session);
	log_infof("Closed client %d on %s", client->session, seat->seat_name);

	return 0;
}


@@ 532,7 528,7 @@ static int seat_disable_client(struct client *client) {
	struct seat *seat = client->seat;

	if (client->state != CLIENT_ACTIVE) {
		log_error("client not active");
		log_error("Could not disable client: client is not active");
		errno = EBUSY;
		return -1;
	}


@@ 546,17 542,17 @@ static int seat_disable_client(struct client *client) {
	     elem = elem->next) {
		struct seat_device *device = (struct seat_device *)elem;
		if (seat_deactivate_device(device) == -1) {
			log_errorf("unable to deactivate '%s': %s", device->path, strerror(errno));
			log_errorf("Could not deactivate %s: %s", device->path, strerror(errno));
		}
	}

	client->state = CLIENT_PENDING_DISABLE;
	if (client_send_disable_seat(seat->active_client) == -1) {
		log_error("could not send disable event");
		log_error("Could not send disable event");
		return -1;
	}

	log_infof("disabling client %d", client->session);
	log_infof("Disabling client %d on %s", client->session, seat->seat_name);
	return 0;
}



@@ 566,13 562,13 @@ int seat_ack_disable_client(struct client *client) {

	struct seat *seat = client->seat;
	if (client->state != CLIENT_PENDING_DISABLE) {
		log_error("client not pending disable");
		log_error("Could not ack disable: client is not pending disable");
		errno = EBUSY;
		return -1;
	}

	client->state = CLIENT_DISABLED;
	log_infof("disabled client %d", client->session);
	log_infof("Disabled client %d on %s", client->session, seat->seat_name);

	if (seat->active_client != client) {
		return 0;


@@ 594,32 590,32 @@ int seat_set_next_session(struct client *client, int session) {
	struct seat *seat = client->seat;

	if (client->state != CLIENT_ACTIVE) {
		log_error("client is not active");
		log_error("Could not set next session: client is not active");
		errno = EPERM;
		return -1;
	}
	assert(seat->active_client == client);

	if (session <= 0) {
		log_errorf("invalid session value: %d", session);
		log_errorf("Could not set next session: invalid session value %d", session);
		errno = EINVAL;
		return -1;
	}

	if (session == client->session) {
		log_info("requested session is already active");
		log_info("Could not set next session: requested session is already active");
		return 0;
	}

	if (seat->next_client != NULL) {
		log_info("switch is already queued");
		log_info("Could not set next session: switch is already queued");
		return 0;
	}

	if (seat->vt_bound) {
		log_infof("switching to VT %d from VT %d", session, seat->cur_vt);
		log_infof("Switching from VT %d to VT %d", seat->cur_vt, session);
		if (vt_switch(seat, session) == -1) {
			log_error("could not switch VT");
			log_error("Could not switch VT");
			return -1;
		}
		return 0;


@@ 636,12 632,12 @@ int seat_set_next_session(struct client *client, int session) {
	}

	if (target == NULL) {
		log_error("no valid switch available");
		log_error("Could not set next session: no such client");
		errno = EINVAL;
		return -1;
	}

	log_infof("queuing switch client with session %d", session);
	log_infof("Queuing switch to client %d on %s", session, seat->seat_name);
	seat->next_client = target;
	seat_disable_client(seat->active_client);
	return 0;


@@ 654,7 650,7 @@ int seat_vt_activate(struct seat *seat) {
		return -1;
	}
	seat_update_vt(seat);
	log_debug("activating VT");
	log_debug("Activating VT");
	vt_ack(seat, false);
	if (seat->active_client == NULL) {
		seat_activate(seat);


@@ 670,7 666,7 @@ int seat_vt_release(struct seat *seat) {
	}
	seat_update_vt(seat);

	log_debug("releasing VT");
	log_debug("Releasing VT");
	if (seat->active_client != NULL) {
		seat_disable_client(seat->active_client);
	}

M seatd/seatd.c => seatd/seatd.c +9 -9
@@ 24,7 24,7 @@ static int open_socket(const char *path, int uid, int gid) {
	} addr = {{0}};
	int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
	if (fd == -1) {
		log_errorf("could not create socket: %s", strerror(errno));
		log_errorf("Could not create socket: %s", strerror(errno));
		return -1;
	}



@@ 32,21 32,21 @@ static int open_socket(const char *path, int uid, int gid) {
	strncpy(addr.unix.sun_path, path, sizeof addr.unix.sun_path - 1);
	socklen_t size = offsetof(struct sockaddr_un, sun_path) + strlen(addr.unix.sun_path);
	if (bind(fd, &addr.generic, size) == -1) {
		log_errorf("could not bind socket: %s", strerror(errno));
		log_errorf("Could not bind socket: %s", strerror(errno));
		close(fd);
		return -1;
	}
	if (listen(fd, LISTEN_BACKLOG) == -1) {
		log_errorf("could not listen on socket: %s", strerror(errno));
		log_errorf("Could not listen on socket: %s", strerror(errno));
		close(fd);
		return -1;
	}
	if (uid != 0 || gid != 0) {
		if (chown(path, uid, gid) == -1) {
			log_errorf("could not chown socket to uid %d, gid %d: %s", uid, gid,
			log_errorf("Could not chown socket to uid %d, gid %d: %s", uid, gid,
				   strerror(errno));
		} else if (chmod(path, 0770) == -1) {
			log_errorf("could not chmod socket: %s", strerror(errno));
			log_errorf("Could not chmod socket: %s", strerror(errno));
		}
	}
	return fd;


@@ 122,7 122,7 @@ int main(int argc, char *argv[]) {
		socket_path = SEATD_DEFAULTPATH;
		struct stat st;
		if (stat(socket_path, &st) == 0) {
			log_info("removing leftover seatd socket");
			log_info("Removing leftover seatd socket");
			unlink(socket_path);
		}
	}


@@ 135,13 135,13 @@ int main(int argc, char *argv[]) {

	int socket_fd = open_socket(socket_path, uid, gid);
	if (socket_fd == -1) {
		log_errorf("could not create server socket: %s", strerror(errno));
		log_errorf("Could not create server socket: %s", strerror(errno));
		server_finish(&server);
		return 1;
	}
	if (poller_add_fd(&server.poller, socket_fd, EVENT_READABLE, server_handle_connection,
			  &server) == NULL) {
		log_errorf("could not add socket to poller: %s", strerror(errno));
		log_errorf("Could not add socket to poller: %s", strerror(errno));
		close(socket_fd);
		server_finish(&server);
		return 1;


@@ 151,7 151,7 @@ int main(int argc, char *argv[]) {

	while (server.running) {
		if (poller_poll(&server.poller) == -1) {
			log_errorf("poller failed: %s", strerror(errno));
			log_errorf("Poller failed: %s", strerror(errno));
			return 1;
		}
	}

M seatd/server.c => seatd/server.c +7 -7
@@ 111,11 111,11 @@ static int server_handle_kill(int signal, void *data) {
static int set_nonblock(int fd) {
	int flags;
	if ((flags = fcntl(fd, F_GETFD)) == -1 || fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) {
		log_errorf("could not set FD_CLOEXEC on socket: %s", strerror(errno));
		log_errorf("Could not set FD_CLOEXEC on socket: %s", strerror(errno));
		return -1;
	}
	if ((flags = fcntl(fd, F_GETFL)) == -1 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
		log_errorf("could not set O_NONBLOCK on socket: %s", strerror(errno));
		log_errorf("Could not set O_NONBLOCK on socket: %s", strerror(errno));
		return -1;
	}
	return 0;


@@ 124,7 124,7 @@ static int set_nonblock(int fd) {
int server_add_client(struct server *server, int fd) {
	if (set_nonblock(fd) != 0) {
		close(fd);
		log_errorf("could not prepare new client socket: %s", strerror(errno));
		log_errorf("Could not prepare new client socket: %s", strerror(errno));
		return -1;
	}



@@ 132,11 132,11 @@ int server_add_client(struct server *server, int fd) {
	client->event_source =
		poller_add_fd(&server->poller, fd, EVENT_READABLE, client_handle_connection, client);
	if (client->event_source == NULL) {
		log_errorf("could not add client socket to poller: %s", strerror(errno));
		log_errorf("Could not add client socket to poller: %s", strerror(errno));
		client_destroy(client);
		return -1;
	}
	log_infof("new client connected (pid: %d, uid: %d, gid: %d)", client->pid, client->uid,
	log_infof("New client connected (pid: %d, uid: %d, gid: %d)", client->pid, client->uid,
		  client->gid);
	return 0;
}


@@ 146,14 146,14 @@ int server_handle_connection(int fd, uint32_t mask, void *data) {
	if (mask & (EVENT_ERROR | EVENT_HANGUP)) {
		shutdown(fd, SHUT_RDWR);
		server->running = false;
		log_errorf("server socket recieved an error: %s", strerror(errno));
		log_errorf("Server socket recieved an error: %s", strerror(errno));
		return -1;
	}

	if (mask & EVENT_READABLE) {
		int new_fd = accept(fd, NULL, NULL);
		if (fd == -1) {
			log_errorf("could not accept client connection: %s", strerror(errno));
			log_errorf("Could not accept client connection: %s", strerror(errno));
			return 0;
		}