Yahoo Groups archive

Milter-greylist

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

Message

Re: [PATCH] Set CLOEXEC flags for sockets

2010-06-10 by Enrico Scholz

manu-S783fYmB3Ccdnm+yROfE0A@... writes:

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

The wrapped

  socket(_domain, (_type) | SOCK_CLOEXEC, _protocol)
                         ~~~~~~~~~~~~~~~

call is very runtime specific (requires Linux 2.6.27+) and there are
major Linux distributions which ship older kernels.  Doing a buildtime
check seems too risky for me.


>> -     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);

your decision... I used the socket_cloexec() to generate more efficient
code (especially when SOCK_CLOEXEC works).


Enrico

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.