diff --git a/loop.c b/loop.c index 674b310..8cbfaa6 100644 --- a/loop.c +++ b/loop.c @@ -82,7 +82,7 @@ void loop_poll(struct loop *loop) { } int ret = poll(loop->fds, loop->fd_length, ms); - if (ret < 0) { + if (ret < 0 && errno != EINTR) { swaylock_log_errno(LOG_ERROR, "poll failed"); exit(1); } diff --git a/main.c b/main.c index a4279e0..b37cd8f 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -392,6 +393,12 @@ static const struct wl_registry_listener registry_listener = { .global_remove = handle_global_remove, }; +static int sigusr_fds[2] = {-1, -1}; + +void do_sigusr(int sig) { + (void)write(sigusr_fds[1], "1", 1); +} + static cairo_surface_t *select_image(struct swaylock_state *state, struct swaylock_surface *surface) { struct swaylock_image *image; @@ -1124,6 +1131,10 @@ static void comm_in(int fd, short mask, void *data) { } } +static void term_in(int fd, short mask, void *data) { + state.run_display = false; +} + int main(int argc, char **argv) { swaylock_log_init(LOG_ERROR); initialize_pw_backend(argc, argv); @@ -1195,6 +1206,11 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } + if (pipe(sigusr_fds) != 0) { + swaylock_log(LOG_ERROR, "Failed to pipe"); + return 1; + } + wl_list_init(&state.surfaces); state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); state.display = wl_display_connect(NULL); @@ -1255,6 +1271,9 @@ int main(int argc, char **argv) { loop_add_fd(state.eventloop, get_comm_reply_fd(), POLLIN, comm_in, NULL); + loop_add_fd(state.eventloop, sigusr_fds[0], POLLIN, term_in, NULL); + signal(SIGUSR1, do_sigusr); + state.run_display = true; while (state.run_display) { errno = 0; diff --git a/swaylock.1.scd b/swaylock.1.scd index f8aac67..61691eb 100644 --- a/swaylock.1.scd +++ b/swaylock.1.scd @@ -189,6 +189,11 @@ Locks your Wayland session. *--text-wrong-color* Sets the color of the text when invalid. +# SIGNALS + +*SIGUSR1* + Unlock the screen and exit. + # AUTHORS Maintained by Drew DeVault , who is assisted by other open