From 6e4d2063012dfbcd07a4c1b4f99a13f3e2a37907 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Fri, 21 Oct 2005 17:02:49 +0000 Subject: [PATCH] restore code closing most open files between fork and exec --- src/libCom/osi/os/posix/osdProcess.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libCom/osi/os/posix/osdProcess.c b/src/libCom/osi/os/posix/osdProcess.c index cd81f2ebf..03ec38527 100644 --- a/src/libCom/osi/os/posix/osdProcess.c +++ b/src/libCom/osi/os/posix/osdProcess.c @@ -81,10 +81,18 @@ epicsShareFunc osiSpawnDetachedProcessReturn epicsShareAPI osiSpawnDetachedProce } /* - * since all epics sockets are created with the FD_CLOEXEC - * option then we no-longer need to blindly close all open - * files here. + * close all open files except for STDIO so they will not + * be inherited by the spawned process. */ + { + int fd, maxfd = sysconf ( _SC_OPEN_MAX ); + for ( fd = 0; fd <= maxfd; fd++ ) { + if (fd==STDIN_FILENO) continue; + if (fd==STDOUT_FILENO) continue; + if (fd==STDERR_FILENO) continue; + close (fd); + } + } /* * overlay the specified executable