set close-on-exec flag
This commit is contained in:
@@ -57,6 +57,11 @@
|
||||
/* kernels that support multicast */
|
||||
/*
|
||||
* $Log$
|
||||
* Revision 1.84.4.6 2003/06/13 00:27:26 jhill
|
||||
* set retry number to 4 when there is a beacon anomaly or when a
|
||||
* channel disconnects. This starts the searcch delay at .4 seconds
|
||||
* instead of at 0.25 seconds.
|
||||
*
|
||||
* Revision 1.84.4.5 2002/07/12 22:16:02 jba
|
||||
* Updated license comments.
|
||||
*
|
||||
@@ -321,6 +326,7 @@ int net_proto
|
||||
UNLOCK;
|
||||
return ECA_SOCK;
|
||||
}
|
||||
setCloseOnExec ( sock );
|
||||
|
||||
piiu->sock_chan = sock;
|
||||
|
||||
@@ -471,6 +477,7 @@ int net_proto
|
||||
UNLOCK;
|
||||
return ECA_SOCK;
|
||||
}
|
||||
setCloseOnExec ( sock );
|
||||
|
||||
piiu->sock_chan = sock;
|
||||
|
||||
@@ -1659,6 +1666,7 @@ int repeater_installed()
|
||||
UNLOCK;
|
||||
return installed;
|
||||
}
|
||||
setCloseOnExec ( sock );
|
||||
|
||||
memset((char *)&bd,0,sizeof bd);
|
||||
bd.sin_family = AF_INET;
|
||||
|
||||
+1
-34
@@ -156,32 +156,6 @@ char *localUserName()
|
||||
|
||||
return pTmp;
|
||||
}
|
||||
|
||||
/*
|
||||
* max_unix_fd()
|
||||
*
|
||||
* attempt to determine the maximum file descriptor
|
||||
* on all UNIX systems
|
||||
*/
|
||||
int max_unix_fd( )
|
||||
{
|
||||
int max;
|
||||
static const int bestGuess = 1024;
|
||||
|
||||
# if defined(OPEN_MAX)
|
||||
max = OPEN_MAX; /* posix */
|
||||
# elif defined(_SC_OPEN_MAX)
|
||||
max = sysconf (_SC_OPEN_MAX);
|
||||
if (max<0) {
|
||||
max = bestGuess;
|
||||
}
|
||||
# else
|
||||
max = bestGuess;
|
||||
# endif
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ca_spawn_repeater()
|
||||
@@ -211,16 +185,9 @@ void ca_spawn_repeater()
|
||||
}
|
||||
|
||||
/*
|
||||
* close all open files except for STDIO so they will not
|
||||
* all open sockets closed by CLOSEXC flag so they will not
|
||||
* be inherited by the repeater task
|
||||
*/
|
||||
maxfd = max_unix_fd ();
|
||||
for (fd = 0; fd<=maxfd; fd++) {
|
||||
if (fd==STDIN_FILENO) continue;
|
||||
if (fd==STDOUT_FILENO) continue;
|
||||
if (fd==STDERR_FILENO) continue;
|
||||
close (fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* running in the repeater process
|
||||
|
||||
@@ -333,6 +333,7 @@ LOCAL makeSocketReturn makeSocket(unsigned short port, int reuseAddr)
|
||||
msr.pErrStr = SOCKERRSTR;
|
||||
return msr;
|
||||
}
|
||||
setCloseOnExec ( msr.sock );
|
||||
|
||||
/*
|
||||
* no need to bind if unconstrained
|
||||
|
||||
@@ -115,6 +115,7 @@ caStatus casDGIntfIO::init(const caNetAddr &addr, unsigned connectWithThisPortIn
|
||||
"CAS: unable to create cast socket\n");
|
||||
return S_cas_noMemory;
|
||||
}
|
||||
setCloseOnExec ( this->sock );
|
||||
|
||||
status = setsockopt(
|
||||
this->sock,
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
//
|
||||
//
|
||||
// $Log$
|
||||
// Revision 1.7.8.4 2002/07/12 22:16:51 jba
|
||||
// Updated license comments.
|
||||
//
|
||||
// Revision 1.7.8.3 2001/03/06 00:24:42 jhill
|
||||
// fixed R3.13 for Linux's new socklen_t
|
||||
//
|
||||
@@ -89,6 +92,7 @@ caStatus casIntfIO::init(const caNetAddr &addrIn, casDGClient &dgClientIn,
|
||||
printf("No socket error was %s\n", SOCKERRSTR);
|
||||
return S_cas_noFD;
|
||||
}
|
||||
setCloseOnExec ( this->sock );
|
||||
|
||||
/*
|
||||
* release the port in case we exit early
|
||||
@@ -247,6 +251,8 @@ casStreamOS *casIntfIO::newStreamClient(caServerI &cas) const
|
||||
ca_printf("CAS: accept returned bad address len?\n");
|
||||
return NULL;
|
||||
}
|
||||
setCloseOnExec ( newSock );
|
||||
|
||||
|
||||
ioArgsToNewStreamIO args;
|
||||
args.addr = newAddr;
|
||||
|
||||
@@ -52,6 +52,8 @@ epicsShareFunc const char * epicsShareAPI getLastWSAErrorAsString();
|
||||
epicsShareFunc unsigned epicsShareAPI wsaMajorVersion();
|
||||
#endif
|
||||
|
||||
epicsShareFunc void epicsShareAPI setCloseOnExec ( SOCKET sock );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -110,3 +110,10 @@ epicsShareFunc int epicsShareAPI hostToIPAddr
|
||||
*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* setCloseOnExec()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI setCloseOnExec ( SOCKET sock )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -181,3 +181,10 @@ epicsShareFunc int epicsShareAPI hostToIPAddr
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* setCloseOnExec()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI setCloseOnExec ( SOCKET sock )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define epicsExportSharedSymbols
|
||||
#include "bsdSocketResource.h"
|
||||
@@ -110,3 +112,17 @@ epicsShareFunc int epicsShareAPI hostToIPAddr
|
||||
*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* setCloseOnExec()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI setCloseOnExec ( SOCKET sock )
|
||||
{
|
||||
int status = fcntl ( sock, F_SETFD, FD_CLOEXEC );
|
||||
if ( status < 0 ) {
|
||||
errlogPrintf (
|
||||
"epicsSocketCreate: failed to "
|
||||
"fcntl FD_CLOEXEC\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,4 +97,11 @@ epicsShareFunc int epicsShareAPI hostToIPAddr
|
||||
* success
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* setCloseOnExec()
|
||||
*/
|
||||
epicsShareFunc void epicsShareAPI setCloseOnExec ( SOCKET sock )
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user