From 2cfc56d5ed87440c58ed7fa538c3a3dbf73fbfc2 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sun, 8 Aug 2021 18:16:58 +0200 Subject: seatd: Improve socket permission error handling chmod/chown errors were logged, but did not result in failure opening the seatd socket. This meant that errors would not get caught by CI. --- seatd/seatd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/seatd/seatd.c b/seatd/seatd.c index 826b994..4587e50 100644 --- a/seatd/seatd.c +++ b/seatd/seatd.c @@ -33,23 +33,27 @@ static int open_socket(const char *path, int uid, int gid) { socklen_t size = offsetof(struct sockaddr_un, sun_path) + strlen(addr.unix.sun_path); if (bind(fd, &addr.generic, size) == -1) { log_errorf("Could not bind socket: %s", strerror(errno)); - close(fd); - return -1; + goto error; } if (listen(fd, LISTEN_BACKLOG) == -1) { log_errorf("Could not listen on socket: %s", strerror(errno)); - close(fd); - return -1; + goto error; } if (uid != -1 || gid != -1) { if (fchown(fd, uid, gid) == -1) { log_errorf("Could not chown socket to uid %d, gid %d: %s", uid, gid, strerror(errno)); - } else if (fchmod(fd, 0770) == -1) { + goto error; + } + if (fchmod(fd, 0770) == -1) { log_errorf("Could not chmod socket: %s", strerror(errno)); + goto error; } } return fd; +error: + close(fd); + return -1; } int main(int argc, char *argv[]) { -- cgit v1.2.3