aboutsummaryrefslogtreecommitdiff
path: root/seatd
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2021-08-08 18:16:58 +0200
committerKenny Levinsen <kl@kl.wtf>2021-08-08 18:21:28 +0200
commit2cfc56d5ed87440c58ed7fa538c3a3dbf73fbfc2 (patch)
tree23c78b492472bcab39ef0151d0c7e17d84288b87 /seatd
parent48727a0b6bc2f7127f2115470be27aa09be7a4a7 (diff)
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.
Diffstat (limited to 'seatd')
-rw-r--r--seatd/seatd.c14
1 files 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[]) {