From cb0209f4932879dd429dd74dc62a98007bd85605 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Thu, 15 Jul 1999 21:01:29 +0000 Subject: [PATCH] close all non-stdio files before repeater exec --- src/ca/posix_depen.c | 47 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/src/ca/posix_depen.c b/src/ca/posix_depen.c index eec7823e0..14d884a48 100644 --- a/src/ca/posix_depen.c +++ b/src/ca/posix_depen.c @@ -29,6 +29,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.25 1998/08/12 16:36:54 jhill + * allow the user name to change when they use su + * * Revision 1.24 1998/04/13 19:14:34 jhill * fixed task variable problem * @@ -88,7 +91,7 @@ void cac_gettimeval(struct timeval *pt) */ void cac_block_for_io_completion(struct timeval *pTV) { - cac_mux_io (pTV); + cac_mux_io (pTV, TRUE); } /* @@ -96,7 +99,7 @@ void cac_block_for_io_completion(struct timeval *pTV) */ void cac_block_for_sg_completion(CASG *pcasg, struct timeval *pTV) { - cac_mux_io (pTV); + cac_mux_io (pTV, TRUE); } @@ -204,6 +207,30 @@ 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; +} /* @@ -213,7 +240,9 @@ void ca_spawn_repeater() { int status; char *pImageName; - + int fd; + int maxfd; + /* * create a duplicate process */ @@ -231,6 +260,18 @@ void ca_spawn_repeater() return; } + /* + * close all open files except for STDIO 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 * if here