const char *helper;
if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd)) {
const char *helper;
if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd)) {
if (!helper) helper = PRIVSEP_HELPER;
fdflags(fd[0], 0, 0, FD_CLOEXEC, FD_CLOEXEC);
fdflags(fd[1], 0, 0, FD_CLOEXEC, FD_CLOEXEC);
if (!helper) helper = PRIVSEP_HELPER;
fdflags(fd[0], 0, 0, FD_CLOEXEC, FD_CLOEXEC);
fdflags(fd[1], 0, 0, FD_CLOEXEC, FD_CLOEXEC);
kid = fork();
if (kid == 0) {
signal(SIGCHLD, SIG_DFL);
if (detachp) detachtty();
kid = fork();
if (kid == 0) {
signal(SIGCHLD, SIG_DFL);
if (detachp) detachtty();
- if (dup2(fd[0], 0) < 0) goto lose;
- close(fd[0]); close(fd[1]);
+ close(fd[1]);
+ md[0].cur = fd[0]; md[0].want = STDIN_FILENO;
+ if (mdup(md, 1)) goto lose;
execl(helper, helper, (char *)0);
lose:
fprintf(stderr, "helper: failed to run helper: %s\n", strerror(errno));
execl(helper, helper, (char *)0);
lose:
fprintf(stderr, "helper: failed to run helper: %s\n", strerror(errno));