Yahoo Groups archive

Milter-greylist

Index last updated: 2026-04-28 23:32 UTC

Message

Re: [milter-greylist] [PATCH] Set CLOEXEC flags for sockets

2010-06-10 by manu@netbsd.org

Enrico Scholz <enrico.scholz@...-chemnitz.de> wrote:

> +#ifdef USE_CLOEXEC

Is there a reason why you don't you just include <fcntl.h> and test
#ifdef FD_CLOEXEC ?


> -     if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
> +     if ((sock = socket_cloexec(AF_UNIX, SOCK_STREAM, 0)) == -1) {
>           mg_log(LOG_ERR, "spamd socket failed: %s", strerror(errno));
>           return -1;

I think I would rather do something like this:

        if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
            mg_log(LOG_ERR, "spamd socket failed: %s", strerror(errno));
            return -1;
        }
        SET_CLOEXEC(sock);
        
With

#ifdef FD_CLOEXEC
#define SET_CLOEXEC(fd)  do {                           \
        int flags = fcntl((fd), F_GETFD, 0);                    \
                                                        \
        if (flags != -1)                                        \
                (void)fcntl((fd, F_SETFD, flags|FD_CLOEXEC);    \
} while (0 /* CONSTCOND */);
#else /* FD_CLOEXEC */
#define SET_CLOEXEC(fd)
#endif /* FD_CLOEXEC */

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu@...

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.