aboutsummaryrefslogtreecommitdiff
path: root/seatd/seat.c
diff options
context:
space:
mode:
Diffstat (limited to 'seatd/seat.c')
-rw-r--r--seatd/seat.c128
1 files changed, 62 insertions, 66 deletions
diff --git a/seatd/seat.c b/seatd/seat.c
index 9c9f7eb..9ad4af2 100644
--- a/seatd/seat.c
+++ b/seatd/seat.c
@@ -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);
}