aboutsummaryrefslogtreecommitdiff
path: root/libseat
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-10-11 20:30:24 +0200
committerKenny Levinsen <kl@kl.wtf>2020-10-11 23:31:07 +0200
commit29ba210958c23a2a406d43f554b87dc1961af6e2 (patch)
tree555db842aaa275fc3e7a08a8abeb5df35089948d /libseat
parent7d785ea9936a07608994e0264726d4e2d98e6919 (diff)
libseat: Better error reporting from open_seat
Diffstat (limited to 'libseat')
-rw-r--r--libseat/libseat.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/libseat/libseat.c b/libseat/libseat.c
index 11d3786..b1e8bb2 100644
--- a/libseat/libseat.c
+++ b/libseat/libseat.c
@@ -40,22 +40,39 @@ struct libseat *libseat_open_seat(struct libseat_seat_listener *listener, void *
log_init();
char *backend_type = getenv("LIBSEAT_BACKEND");
+ if (backend_type != NULL) {
+ const struct named_backend *iter = impls;
+ while (iter->backend != NULL && strcmp(backend_type, iter->name) != 0) {
+ iter++;
+ }
+ if (iter == NULL || iter->backend == NULL) {
+ log_errorf("No backend matched name '%s'", backend_type);
+ errno = EINVAL;
+ return NULL;
+ }
+ struct libseat *backend = iter->backend->open_seat(listener, data);
+ if (backend == NULL) {
+ log_errorf("Backend '%s' failed to open seat: %s", iter->name,
+ strerror(errno));
+ return NULL;
+ }
+ log_infof("Seat opened with backend '%s'", iter->name);
+ return backend;
+ }
+
struct libseat *backend = NULL;
for (const struct named_backend *iter = impls; iter->backend != NULL; iter++) {
- if (backend_type != NULL && strcmp(backend_type, iter->name) != 0) {
- continue;
- }
- log_infof("Trying backend '%s'", iter->name);
backend = iter->backend->open_seat(listener, data);
if (backend != NULL) {
log_infof("Seat opened with backend '%s'", iter->name);
- break;
+ return backend;
}
+ log_infof("Backend '%s' failed to open seat, skipping", iter->name);
}
- if (backend == NULL) {
- errno = ENOSYS;
- }
- return backend;
+
+ log_error("No backend was able to open a seat");
+ errno = ENOSYS;
+ return NULL;
}
int libseat_disable_seat(struct libseat *seat) {