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.
This commit is contained in:
parent
48727a0b6b
commit
2cfc56d5ed
1 changed files with 9 additions and 5 deletions
|
@ -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);
|
socklen_t size = offsetof(struct sockaddr_un, sun_path) + strlen(addr.unix.sun_path);
|
||||||
if (bind(fd, &addr.generic, size) == -1) {
|
if (bind(fd, &addr.generic, size) == -1) {
|
||||||
log_errorf("Could not bind socket: %s", strerror(errno));
|
log_errorf("Could not bind socket: %s", strerror(errno));
|
||||||
close(fd);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
if (listen(fd, LISTEN_BACKLOG) == -1) {
|
if (listen(fd, LISTEN_BACKLOG) == -1) {
|
||||||
log_errorf("Could not listen on socket: %s", strerror(errno));
|
log_errorf("Could not listen on socket: %s", strerror(errno));
|
||||||
close(fd);
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
if (uid != -1 || gid != -1) {
|
if (uid != -1 || gid != -1) {
|
||||||
if (fchown(fd, uid, gid) == -1) {
|
if (fchown(fd, uid, gid) == -1) {
|
||||||
log_errorf("Could not chown socket to uid %d, gid %d: %s", uid, gid,
|
log_errorf("Could not chown socket to uid %d, gid %d: %s", uid, gid,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
} else if (fchmod(fd, 0770) == -1) {
|
goto error;
|
||||||
|
}
|
||||||
|
if (fchmod(fd, 0770) == -1) {
|
||||||
log_errorf("Could not chmod socket: %s", strerror(errno));
|
log_errorf("Could not chmod socket: %s", strerror(errno));
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
|
error:
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue