diff options
author | 2016-10-05 17:31:28 +0000 | |
---|---|---|
committer | 2016-10-05 17:31:28 +0000 | |
commit | 68dc821bbd44a975c1f144e59dc780d3167327ed (patch) | |
tree | 8f34bac726afe725b486bbbc001871c6097161b4 /usr.sbin/switchd/proc.c | |
parent | Replace one u_int8_t with uint8_t (finger memory) (diff) | |
download | wireguard-openbsd-68dc821bbd44a975c1f144e59dc780d3167327ed.tar.xz wireguard-openbsd-68dc821bbd44a975c1f144e59dc780d3167327ed.zip |
Sync with httpd(8) proc file. Check for dup2() usage to avoid oldd == newd
and remove the CLOEXEC with fcntl() if necessary.
ok reyk@
Diffstat (limited to 'usr.sbin/switchd/proc.c')
-rw-r--r-- | usr.sbin/switchd/proc.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.sbin/switchd/proc.c b/usr.sbin/switchd/proc.c index 839e4696760..37e4667f330 100644 --- a/usr.sbin/switchd/proc.c +++ b/usr.sbin/switchd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.6 2016/10/05 17:09:59 reyk Exp $ */ +/* $OpenBSD: proc.c,v 1.7 2016/10/05 17:31:28 rzalamena Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org> @@ -22,6 +22,7 @@ #include <sys/socket.h> #include <sys/wait.h> +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -135,7 +136,12 @@ proc_exec(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc, fatal("setsid"); /* Prepare parent socket. */ - dup2(fd, PROC_PARENT_SOCK_FILENO); + if (fd != PROC_PARENT_SOCK_FILENO) { + if (dup2(fd, PROC_PARENT_SOCK_FILENO) + == -1) + fatal("dup2"); + } else if (fcntl(fd, F_SETFD, 0) == -1) + fatal("fcntl"); execvp(argv[0], nargv); fatal("%s: execvp", __func__); |