From 4b312c1389ebc2ec73612bb4b9b4e7ea5f844f50 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Mon, 22 Oct 2018 09:59:35 +0100 Subject: [PATCH 1/2] swaylock: exit early if unable to inhibit input This stops the program from going into a spinlock without exiting --- main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.c b/main.c index f2bb5c3..8ed8adf 100644 --- a/main.c +++ b/main.c @@ -925,6 +925,11 @@ int main(int argc, char **argv) { } zwlr_input_inhibit_manager_v1_get_inhibitor(state.input_inhibit_manager); + if (wl_display_roundtrip(state.display) == -1) { + wlr_log(WLR_ERROR, "Exiting - failed to inhibit input:" + " is another lockscreen already running?"); + return 2; + } if (state.zxdg_output_manager) { struct swaylock_surface *surface; From 274179a804e67e0f191312350c52c10778c6e5c7 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Tue, 23 Oct 2018 11:46:51 +0100 Subject: [PATCH 2/2] swaylock: exit on display error --- main.c | 10 ++++++++-- password.c | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 8ed8adf..ebc2b26 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,7 @@ #define _POSIX_C_SOURCE 200112L #include #include +#include #include #include #include @@ -841,7 +842,9 @@ static int load_config(char *path, struct swaylock_state *state, static struct swaylock_state state; static void display_in(int fd, short mask, void *data) { - wl_display_dispatch(state.display); + if (wl_display_dispatch(state.display) == -1) { + state.run_display = false; + } } int main(int argc, char **argv) { @@ -961,7 +964,10 @@ int main(int argc, char **argv) { state.run_display = true; while (state.run_display) { - wl_display_flush(state.display); + errno = 0; + if (wl_display_flush(state.display) == -1 && errno != EAGAIN) { + break; + } loop_poll(state.eventloop); } diff --git a/password.c b/password.c index fecaecb..6138e1f 100644 --- a/password.c +++ b/password.c @@ -1,5 +1,6 @@ #define _XOPEN_SOURCE 500 #include +#include #include #include #include @@ -97,7 +98,10 @@ void swaylock_handle_key(struct swaylock_state *state, state->eventloop, 50, handle_preverify_timeout, state); while (state->run_display && state->verify_password_timer) { - wl_display_flush(state->display); + errno = 0; + if (wl_display_flush(state->display) == -1 && errno != EAGAIN) { + break; + } loop_poll(state->eventloop); bool ok = 1;