Ignore:
Timestamp:
Aug 30, 2011 9:16:50 AM (13 years ago)
Author:
ldelgass
Message:

Fall back to fcntl to set FD_CLOEXEC on socket if accept4 isn't available

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanoscale/server2.c

    r2430 r2449  
    1515#include <syslog.h>
    1616#include <unistd.h>
     17#include <fcntl.h>
    1718
    1819#include <tcl.h>
     20
     21#include "config.h"
    1922
    2023#define TRUE    1
     
    381384            /* Accept the new connection. */
    382385            length = sizeof(newaddr);
     386#ifdef HAVE_ACCEPT4
    383387            f = accept4(serverPtr->listenerFd, (struct sockaddr *)&newaddr,
    384388                        &length, SOCK_CLOEXEC);
     389#else
     390            f = accept(serverPtr->listenerFd, (struct sockaddr *)&newaddr,
     391                       &length);
     392#endif
    385393            if (f < 0) {
    386394                ERROR("Can't accept server \"%s\": %s", serverPtr->name,
     
    388396                exit(1);
    389397            }
     398#ifndef HAVE_ACCEPT4
     399            int flags = fcntl(f, F_GETFD);
     400            flags |= FD_CLOEXEC;
     401            if (fcntl(f, F_SETFD, flags) < 0) {
     402                ERROR("Can't set FD_CLOEXEC on socket \"%s\": %s", serverPtr->name,
     403                      strerror(errno));
     404                exit(1);
     405            }
     406#endif
    390407            INFO("Connecting \"%s\" to %s\n", serverPtr->name,
    391408                 inet_ntoa(newaddr.sin_addr));
Note: See TracChangeset for help on using the changeset viewer.