lib/socket-util-unix.c
/* Binds Unix domain socket 'fd' to a file with permissions 0700. */
Binds Unix domain socket 'fd' to a file with permissions 0700.
Binds Unix domain socket ' fd ' to a file with permissions 0700 .
static int bind_unix_socket(int fd, struct sockaddr *sun, socklen_t sun_len)
{
    const mode_t mode = 0770;    
    if (LINUX) {
        if (fchmod(fd, mode)) {
            return errno;
        }
        if (bind(fd, sun, sun_len)) {
            return errno;
        }
        return 0;
    } else {
        pid_t pid = fork();
        if (!pid) {
            umask(mode ^ 0777);
            _exit(bind(fd, sun, sun_len) ? errno : 0);
        } else if (pid > 0) {
            int status;
            int error;
            do {
                error = waitpid(pid, &status, 0) < 0 ? errno : 0;
            } while (error == EINTR);
            return (error ? error
                    : WIFEXITED(status) ? WEXITSTATUS(status)
                    : WIFSIGNALED(status) ? EINTR
                    : ECHILD );
        } else {
            return errno;
        }
    }
}
static int bind_unix_socket ( int fd , struct sockaddr * sun , socklen_t sun_len ) { const mode_t mode = 0770 ; if ( LINUX ) { if ( fchmod ( fd , mode ) ) { return errno ; } if ( bind ( fd , sun , sun_len ) ) { return errno ; } return 0 ; } else { pid_t pid = fork ( ) ; if ( ! pid ) { umask ( mode ^ 0777 ) ; _exit ( bind ( fd , sun , sun_len ) ? errno : 0 ) ; } else if ( pid > 0 ) { int status ; int error ; do { error = waitpid ( pid , & status , 0 ) < 0 ? errno : 0 ; } while ( error == EINTR ) ; return ( error ? error : WIFEXITED ( status ) ? WEXITSTATUS ( status ) : WIFSIGNALED ( status ) ? EINTR : ECHILD ) ; } else { return errno ; } } }
Binds Unix domain socket 'fd' to a file with permissions 0700.
Binds Unix domain socket ' fd ' to a file with permissions 0700 .
/* Allow both user and group access. */ /* On Linux, the fd's permissions become the file's permissions.
         * fchmod() does not affect other files, like umask() does. */ /* Must be after fchmod(). */ /* On FreeBSD and NetBSD, only the umask affects permissions.  The
         * umask is process-wide rather than thread-specific, so we have to use
         * a subprocess for safety. */ /* WTF? */