From 56602e4ff91c042bc500c7919ba03bebe5309a38 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Wed, 1 Mar 2000 23:09:59 +0000 Subject: [PATCH] added maxPosixFD() --- src/libCom/osi/os/posix/osdProcess.c | 40 +++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/libCom/osi/os/posix/osdProcess.c b/src/libCom/osi/os/posix/osdProcess.c index a51a5ab01..d854d5fad 100644 --- a/src/libCom/osi/os/posix/osdProcess.c +++ b/src/libCom/osi/os/posix/osdProcess.c @@ -8,19 +8,18 @@ * */ -/* ANSI C */ -#include #include #include -#include - -/* POSIX */ +#include +#include +#include /* OPEN_MAX defined here */ #include #include #include #define epicsExportSharedSymbols #include "osiProcess.h" +#include "errlog.h" epicsShareFunc osiGetUserNameReturn epicsShareAPI osiGetUserName (char *pBuf, unsigned bufSizeIn) { @@ -53,6 +52,35 @@ epicsShareFunc osiGetUserNameReturn epicsShareAPI osiGetUserName (char *pBuf, un } } +/* + * maxPosixFD () + * + * attempt to determine the maximum file descriptor + * on all posix systems + */ +static int maxPosixFD ( ) +{ + int max; + static const int bestGuess = 1024; + +# if defined (_SC_OPEN_MAX) /* posix */ + max = sysconf (_SC_OPEN_MAX); + if (max<0) { +# if defined (OPEN_MAX) + max = OPEN_MAX; +# else + max = bestGuess; +# endif + } +# elif defined (OPEN_MAX) /* posix */ + max = OPEN_MAX; +# else + max = bestGuess; +# endif + + return max; +} + epicsShareFunc osiSpawnDetachedProcessReturn epicsShareAPI osiSpawnDetachedProcess (const char *pProcessName, const char *pBaseExecutableName) { @@ -80,7 +108,7 @@ epicsShareFunc osiSpawnDetachedProcessReturn epicsShareAPI osiSpawnDetachedProce * close all open files except for STDIO so they will not * be inherited by the spawned process */ - maxfd = max_unix_fd (); + maxfd = maxPosixFD (); for (fd = 0; fd<=maxfd; fd++) { if (fd==STDIN_FILENO) continue; if (fd==STDOUT_FILENO) continue;