syslogd: Set unix socket modes atomically

Take advantage of the ability to atomically set unix socket modes to
ensure that /var/run/logpriv always has mode 0600.

MFC after:	1 month
This commit is contained in:
Mark Johnston 2024-11-03 14:41:15 +00:00
parent bfd03046d1
commit 2b8c3a05e0

View File

@ -3721,6 +3721,11 @@ socksetup(struct addrinfo *ai, const char *name, mode_t mode)
if (ai->ai_family == AF_LOCAL)
unlink(name);
if (ai->ai_family == AF_LOCAL || NoBind == 0 || name != NULL) {
if (ai->ai_family == AF_LOCAL && fchmod(s, mode) < 0) {
dprintf("fchmod %s: %s\n", name, strerror(errno));
close(s);
return (NULL);
}
if (bind(s, ai->ai_addr, ai->ai_addrlen) < 0) {
logerror("bind");
close(s);
@ -3729,11 +3734,6 @@ socksetup(struct addrinfo *ai, const char *name, mode_t mode)
if (ai->ai_family == AF_LOCAL || SecureMode == 0)
increase_rcvbuf(s);
}
if (ai->ai_family == AF_LOCAL && chmod(name, mode) < 0) {
dprintf("chmod %s: %s\n", name, strerror(errno));
close(s);
return (NULL);
}
dprintf("new socket fd is %d\n", s);
sl_recv = socklist_recv_sock;
#if defined(INET) || defined(INET6)