From 34e0aabc51074a2476d27148c4f755d558da3ec9 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 12 Mar 2025 01:31:21 +0100 Subject: Better handle subprocess crashes On my machine EOF doesn't trigger POLLHUP (not sure why), instead read() returns zero. It just prints the following message in a loop: [comm.c:101] Failed to read pw result: Success Better handle this case in read_comm_reply() by making a difference between a failed read() and a failed authentication. --- comm.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'comm.c') diff --git a/comm.c b/comm.c index 6add38a..28e0504 100644 --- a/comm.c +++ b/comm.c @@ -95,13 +95,17 @@ out: return result; } -bool read_comm_reply(void) { - bool result = false; - if (read(comm[1][0], &result, sizeof(result)) != sizeof(result)) { - swaylock_log_errno(LOG_ERROR, "Failed to read pw result"); - result = false; +bool read_comm_reply(bool *auth_success) { + ssize_t n = read(comm[1][0], auth_success, sizeof(*auth_success)); + if (n != sizeof(*auth_success)) { + if (n < 0) { + swaylock_log_errno(LOG_ERROR, "Failed to read pw result"); + } else { + swaylock_log(LOG_ERROR, "Failed to read pw result: short read of %zd bytes", n); + } + return false; } - return result; + return true; } int get_comm_reply_fd(void) { -- cgit v1.2.3