osaf/libs/core/leap/os_defs.c | 21 +++++++++++++++------ 1 files changed, 15 insertions(+), 6 deletions(-)
New issues where freopen "freezes", use dup2 instead. Non async-signal-safe are used in ncs_os_process_execute_timed, sched_setscheduler, syslog, setenv, getenv and freopen. Syslog may "freeze" but are called only when an error has been detected. The remaining should be removed. diff --git a/osaf/libs/core/leap/os_defs.c b/osaf/libs/core/leap/os_defs.c --- a/osaf/libs/core/leap/os_defs.c +++ b/osaf/libs/core/leap/os_defs.c @@ -971,6 +971,7 @@ uint32_t ncs_os_process_execute_timed(NC /* By default we close all inherited file descriptors in the child */ if (getenv("OPENSAF_KEEP_FD_OPEN_AFTER_FORK") == NULL) { + int fd1; /* Close all inherited file descriptors */ int i = sysconf(_SC_OPEN_MAX); if (i == -1) { @@ -981,12 +982,20 @@ uint32_t ncs_os_process_execute_timed(NC (void) close(i); /* close all descriptors */ /* Redirect standard files to /dev/null */ - if (freopen("/dev/null", "r", stdin) == NULL) - syslog(LOG_ERR, "%s: freopen stdin failed - %s", __FUNCTION__, strerror(errno)); - if (freopen("/dev/null", "w", stdout) == NULL) - syslog(LOG_ERR, "%s: freopen stdout failed - %s", __FUNCTION__, strerror(errno)); - if (freopen("/dev/null", "w", stderr) == NULL) - syslog(LOG_ERR, "%s: freopen stderr failed - %s", __FUNCTION__, strerror(errno)); + if ((fd1 = open("/dev/null", O_RDWR)) < 0) { + syslog(LOG_ERR, "%s: open /dev/null failed - %s", __FUNCTION__, strerror(errno)); + } + else { + if (dup2(fd1, STDIN_FILENO) < 0) { + syslog(LOG_ERR, "%s: dup2 stdin failed - %s", __FUNCTION__, strerror(errno)); + } + if (dup2(fd1, STDOUT_FILENO) < 0) { + syslog(LOG_ERR, "%s: dup2 stdout failed - %s", __FUNCTION__, strerror(errno)); + } + if (dup2(fd1, STDERR_FILENO) < 0) { + syslog(LOG_ERR, "%s: dup2 stderr failed - %s", __FUNCTION__, strerror(errno)); + } + } } /* RUNASROOT gives the OpenSAF user a possibility to maintain the < 4.2 behaviour. ------------------------------------------------------------------------------ Start Your Social Network Today - Download eXo Platform Build your Enterprise Intranet with eXo Platform Software Java Based Open Source Intranet - Social, Extensible, Cloud Ready Get Started Now And Turn Your Intranet Into A Collaboration Platform http://p.sf.net/sfu/ExoPlatform _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel