struct sockaddr_un sun;
struct sigaction sa;
size_t sz;
+ mode_t omask;
/* --- Create services table --- */
/* --- Attempt to bind to the socket --- */
- umask(0077);
+ omask = umask(0077);
again:
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
die(EXIT_FAILURE, "couldn't create socket: %s", strerror(errno));
close(fd);
goto again;
}
- chmod(sun.sun_path, 0600);
+ if (chmod(sun.sun_path, 0600)) {
+ die(EXIT_FAILURE, "failed to set socket permissions: %s",
+ strerror(errno));
+ }
if (chown(sun.sun_path, u, g)) {
- T( trace(T_ADMIN,
- "admin: failed to give away socket: %s",
- strerror(errno)); )
+ die(EXIT_FAILURE, "failed to set socket owner: %s",
+ strerror(errno));
}
+ umask(omask);
fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
if (listen(fd, 5))
die(EXIT_FAILURE, "couldn't listen on socket: %s", strerror(errno));