version 1.34, 2018/08/08 22:31:43 |
version 1.35, 2019/06/29 21:23:18 |
|
|
sigfillset(&sa.sa_mask); |
sigfillset(&sa.sa_mask); |
sa.sa_flags = SA_RESTART; |
sa.sa_flags = SA_RESTART; |
sa.sa_handler = sigint; |
sa.sa_handler = sigint; |
if (sigaction(SIGINT, &sa, NULL) < 0) |
if (sigaction(SIGINT, &sa, NULL) == -1) |
err(1, "sigaction(int) failed"); |
err(1, "sigaction(int) failed"); |
if (sigaction(SIGTERM, &sa, NULL) < 0) |
if (sigaction(SIGTERM, &sa, NULL) == -1) |
err(1, "sigaction(term) failed"); |
err(1, "sigaction(term) failed"); |
if (sigaction(SIGHUP, &sa, NULL) < 0) |
if (sigaction(SIGHUP, &sa, NULL) == -1) |
err(1, "sigaction(hup) failed"); |
err(1, "sigaction(hup) failed"); |
} |
} |
|
|
|
|
sigfillset(&sa.sa_mask); |
sigfillset(&sa.sa_mask); |
sa.sa_flags = SA_RESTART; |
sa.sa_flags = SA_RESTART; |
sa.sa_handler = SIG_DFL; |
sa.sa_handler = SIG_DFL; |
if (sigaction(SIGHUP, &sa, NULL) < 0) |
if (sigaction(SIGHUP, &sa, NULL) == -1) |
err(1, "unsetsig(hup): sigaction failed"); |
err(1, "unsetsig(hup): sigaction failed"); |
if (sigaction(SIGTERM, &sa, NULL) < 0) |
if (sigaction(SIGTERM, &sa, NULL) == -1) |
err(1, "unsetsig(term): sigaction failed"); |
err(1, "unsetsig(term): sigaction failed"); |
if (sigaction(SIGINT, &sa, NULL) < 0) |
if (sigaction(SIGINT, &sa, NULL) == -1) |
err(1, "unsetsig(int): sigaction failed"); |
err(1, "unsetsig(int): sigaction failed"); |
} |
} |
|
|
|
|
snprintf(base, SOCKPATH_MAX, SOCKPATH_DIR "-%u", uid); |
snprintf(base, SOCKPATH_MAX, SOCKPATH_DIR "-%u", uid); |
} |
} |
omask = umask(mask); |
omask = umask(mask); |
if (mkdir(base, 0777) < 0) { |
if (mkdir(base, 0777) == -1) { |
if (errno != EEXIST) |
if (errno != EEXIST) |
err(1, "mkdir(\"%s\")", base); |
err(1, "mkdir(\"%s\")", base); |
} |
} |
umask(omask); |
umask(omask); |
if (stat(base, &sb) < 0) |
if (stat(base, &sb) == -1) |
err(1, "stat(\"%s\")", base); |
err(1, "stat(\"%s\")", base); |
if (!S_ISDIR(sb.st_mode)) |
if (!S_ISDIR(sb.st_mode)) |
errx(1, "%s is not a directory", base); |
errx(1, "%s is not a directory", base); |
|
|
if (strncmp(name, prefix, prefix_len) != 0) |
if (strncmp(name, prefix, prefix_len) != 0) |
errx(1, "%s: unsupported device or port format", name); |
errx(1, "%s: unsupported device or port format", name); |
snprintf(path, sizeof(path), "%s%s", path_prefix, name + prefix_len); |
snprintf(path, sizeof(path), "%s%s", path_prefix, name + prefix_len); |
if (unveil(path, "rw") < 0) |
if (unveil(path, "rw") == -1) |
err(1, "unveil"); |
err(1, "unveil"); |
} |
} |
|
|
|
|
errx(1, "unknown user %s", SNDIO_PRIV_USER); |
errx(1, "unknown user %s", SNDIO_PRIV_USER); |
} else |
} else |
pw = NULL; |
pw = NULL; |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) < 0) { |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == -1) { |
perror("socketpair"); |
perror("socketpair"); |
return 0; |
return 0; |
} |
} |
|
|
if (background) { |
if (background) { |
log_flush(); |
log_flush(); |
log_level = 0; |
log_level = 0; |
if (daemon(0, 0) < 0) |
if (daemon(0, 0) == -1) |
err(1, "daemon"); |
err(1, "daemon"); |
} |
} |
if (pw != NULL) { |
if (pw != NULL) { |
|
|
dounveil(d->path, "rsnd/", "/dev/audio"); |
dounveil(d->path, "rsnd/", "/dev/audio"); |
for (p = port_list; p != NULL; p = p->next) |
for (p = port_list; p != NULL; p = p->next) |
dounveil(p->path, "rmidi/", "/dev/rmidi"); |
dounveil(p->path, "rmidi/", "/dev/rmidi"); |
if (pledge("stdio sendfd rpath wpath", NULL) < 0) |
if (pledge("stdio sendfd rpath wpath", NULL) == -1) |
err(1, "pledge"); |
err(1, "pledge"); |
while (file_poll()) |
while (file_poll()) |
; /* nothing */ |
; /* nothing */ |
|
|
if (background) { |
if (background) { |
log_flush(); |
log_flush(); |
log_level = 0; |
log_level = 0; |
if (daemon(0, 0) < 0) |
if (daemon(0, 0) == -1) |
err(1, "daemon"); |
err(1, "daemon"); |
} |
} |
if (pw != NULL) { |
if (pw != NULL) { |
if (setpriority(PRIO_PROCESS, 0, SNDIO_PRIO) < 0) |
if (setpriority(PRIO_PROCESS, 0, SNDIO_PRIO) == -1) |
err(1, "setpriority"); |
err(1, "setpriority"); |
if (chroot(pw->pw_dir) != 0 || chdir("/") != 0) |
if (chroot(pw->pw_dir) == -1 || chdir("/") == -1) |
err(1, "cannot chroot to %s", pw->pw_dir); |
err(1, "cannot chroot to %s", pw->pw_dir); |
if (setgroups(1, &pw->pw_gid) || |
if (setgroups(1, &pw->pw_gid) == -1 || |
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || |
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1 || |
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) |
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1 ) |
err(1, "cannot drop privileges"); |
err(1, "cannot drop privileges"); |
} |
} |
if (tcpaddr_list) { |
if (tcpaddr_list) { |