From c5352791a6936f9c42e9895464ee77761abff3cc Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 19 Sep 2014 21:28:32 +0000 Subject: Instead of doing the fcntl(2) and ioctl(2) song and dance just tell socket(2) and accept4(2) that we want non-blocking-close-on-exec sockets. OK benno@ --- slowcgi.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/slowcgi.c b/slowcgi.c index 7e66d16..445cf86 100644 --- a/slowcgi.c +++ b/slowcgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slowcgi.c,v 1.34 2014/07/13 21:46:25 claudio Exp $ */ +/* $OpenBSD: slowcgi.c,v 1.35 2014/09/19 21:28:32 florian Exp $ */ /* * Copyright (c) 2013 David Gwynne * Copyright (c) 2013 Florian Obser @@ -358,9 +358,9 @@ slowcgi_listen(char *path, struct passwd *pw) mode_t old_umask, mode; int fd; - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) + if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, + 0)) == -1) lerr(1, "slowcgi_listen: socket"); - fcntl(fd, F_SETFD, FD_CLOEXEC); bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; @@ -384,9 +384,6 @@ slowcgi_listen(char *path, struct passwd *pw) if (chown(path, pw->pw_uid, pw->pw_gid) == -1) lerr(1, "slowcgi_listen: chown: %s", path); - if (ioctl(fd, FIONBIO, &on) == -1) - lerr(1, "listener ioctl(FIONBIO)"); - if (listen(fd, 5) == -1) lerr(1, "listen"); @@ -420,7 +417,8 @@ accept_reserve(int sockfd, struct sockaddr *addr, socklen_t *addrlen, return -1; } - if ((ret = accept(sockfd, addr, addrlen)) > -1) { + if ((ret = accept4(sockfd, addr, addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC)) + > -1) { (*counter)++; ldebug("inflight incremented, now %d", *counter); } @@ -461,10 +459,6 @@ slowcgi_accept(int fd, short events, void *arg) } } - fcntl(s, F_SETFD, FD_CLOEXEC); - if (ioctl(s, FIONBIO, &on) == -1) - lerr(1, "request ioctl(FIONBIO)"); - c = calloc(1, sizeof(*c)); if (c == NULL) { lwarn("cannot calloc request"); -- cgit v1.2.3-2-gb3c3