aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-09-19 21:58:09 +0200
committerKenny Levinsen <kl@kl.wtf>2020-09-22 01:01:46 +0200
commit6fa82930d0c5660eea3102989c765dc864514e36 (patch)
treee69a06151de0b5c211b41e6259743965b4747a97
parent4c22c7b00414ad93809adc619062ca89345aeaa1 (diff)
libseat: Execute bg events after IPC calls
If a background event was queued during call dispatch, and no unread data was left on the socket, there would be no incentive for the user to call dispatch, and as a result, the events would never be executed. Execute events at the end of IPC calls that read from the socket to avoid stalls.
-rw-r--r--libseat/backend/seatd.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/libseat/backend/seatd.c b/libseat/backend/seatd.c
index 2f7b384..b0e023f 100644
--- a/libseat/backend/seatd.c
+++ b/libseat/backend/seatd.c
@@ -379,6 +379,7 @@ static struct libseat *_open_seat(struct libseat_seat_listener *listener, void *
goto backend_error;
}
+ execute_events(backend);
return &backend->base;
backend_error:
@@ -412,10 +413,12 @@ static int close_seat(struct libseat *base) {
goto error;
}
+ execute_events(backend);
destroy(backend);
return 0;
error:
+ execute_events(backend);
destroy(backend);
return -1;
}
@@ -447,16 +450,21 @@ static int open_device(struct libseat *base, const char *path, int *fd) {
if (conn_put(backend, &header, sizeof header) == -1 ||
conn_put(backend, &msg, sizeof msg) == -1 || conn_put(backend, path, pathlen) == -1 ||
dispatch(backend) == -1) {
- return -1;
+ goto error;
}
struct proto_server_device_opened rmsg;
if (read_header(backend, SERVER_DEVICE_OPENED, sizeof rmsg, false) == SIZE_MAX ||
conn_get(backend, &rmsg, sizeof rmsg) == -1 || conn_get_fd(backend, fd)) {
- return -1;
+ goto error;
}
+ execute_events(backend);
return rmsg.device_id;
+
+error:
+ execute_events(backend);
+ return -1;
}
static int close_device(struct libseat *base, int device_id) {
@@ -479,14 +487,19 @@ static int close_device(struct libseat *base, int device_id) {
};
if (conn_put(backend, &header, sizeof header) == -1 ||
conn_put(backend, &msg, sizeof msg) == -1 || dispatch(backend) == -1) {
- return -1;
+ goto error;
}
if (read_header(backend, SERVER_DEVICE_CLOSED, 0, false) == SIZE_MAX) {
- return -1;
+ goto error;
}
+ execute_events(backend);
return 0;
+
+error:
+ execute_events(backend);
+ return -1;
}
static int switch_session(struct libseat *base, int session) {