Browse Source

[mod_cgi] fall back to pipe() if pipe2() fails

This change should fix an issue with lighttpd on Debian kfreebsd-* arch
  (kfreebsd-amd64 and kfreebsd-i386)
.libs/mod_cgi.o: In function `cgi_create_env':
./src/mod_cgi.c:1103: warning: pipe2 is not implemented and will always fail

lighttpd is single-threaded so there is no race with pipe()
and then fcntl() F_SETFD FD_CLOEXEC on the pair of pipe fds.
Using pipe2() where available is still slightly more efficient
by eliding the syscalls to set FD_CLOEXEC.
personal/stbuehler/mod-csrf
Glenn Strauss 5 years ago
parent
commit
c718064911
  1. 24
      src/mod_cgi.c

24
src/mod_cgi.c

@ -35,18 +35,18 @@
#include <stdio.h>
#include <fcntl.h>
#ifdef HAVE_PIPE2
#define pipe_cloexec(pipefd) pipe2((pipefd), O_CLOEXEC)
#elif defined FD_CLOEXEC
#define pipe_cloexec(pipefd) \
( 0 == pipe(pipefd) \
&& 0 == fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) \
&& 0 == fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) \
? 0 \
: -1)
#else
#define pipe_cloexec(pipefd) pipe(pipefd)
#endif
static int pipe_cloexec(int pipefd[2]) {
#ifdef HAVE_PIPE2
if (0 == pipe2(pipefd, O_CLOEXEC)) return 0;
#endif
return 0 == pipe(pipefd)
#ifdef FD_CLOEXEC
&& 0 == fcntl(pipefd[0], F_SETFD, FD_CLOEXEC)
&& 0 == fcntl(pipefd[1], F_SETFD, FD_CLOEXEC)
#endif
? 0
: -1;
}
enum {EOL_UNSET, EOL_N, EOL_RN};

Loading…
Cancel
Save