summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comm.c16
-rw-r--r--include/comm.h2
-rw-r--r--main.c22
3 files changed, 25 insertions, 15 deletions
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) {
diff --git a/include/comm.h b/include/comm.h
index defc2f4..cd94094 100644
--- a/include/comm.h
+++ b/include/comm.h
@@ -11,7 +11,7 @@ bool write_comm_reply(bool success);
// Requests the provided password to be checked. The password is always cleared
// when the function returns.
bool write_comm_request(struct swaylock_password *pw);
-bool read_comm_reply(void);
+bool read_comm_reply(bool *auth_success);
// FD to poll for password authentication replies.
int get_comm_reply_fd(void);
diff --git a/main.c b/main.c
index c0d7226..3a3a68f 100644
--- a/main.c
+++ b/main.c
@@ -1035,17 +1035,23 @@ static void display_in(int fd, short mask, void *data) {
}
static void comm_in(int fd, short mask, void *data) {
- if (read_comm_reply()) {
- // Authentication succeeded
- state.run_display = false;
+ if (mask & POLLIN) {
+ bool auth_success = false;
+ if (!read_comm_reply(&auth_success)) {
+ exit(EXIT_FAILURE);
+ }
+ if (auth_success) {
+ // Authentication succeeded
+ state.run_display = false;
+ } else {
+ state.auth_state = AUTH_STATE_INVALID;
+ schedule_auth_idle(&state);
+ ++state.failed_attempts;
+ damage_state(&state);
+ }
} else if (mask & (POLLHUP | POLLERR)) {
swaylock_log(LOG_ERROR, "Password checking subprocess crashed; exiting.");
exit(EXIT_FAILURE);
- } else {
- state.auth_state = AUTH_STATE_INVALID;
- schedule_auth_idle(&state);
- ++state.failed_attempts;
- damage_state(&state);
}
}