From 1b585cc71302358211c27fc94e8bd6cb2cc45183 Mon Sep 17 00:00:00 2001 From: Tonya Souther Date: Tue, 16 Oct 2012 12:16:39 -0500 Subject: [PATCH] Better fix for reopening files to /dev/null for web browser on Linux. --- indra/llwindow/llwindowsdl.cpp | 30 ++++++++++++++++++++++--- indra/newview/linux_tools/launch_url.sh | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/indra/llwindow/llwindowsdl.cpp b/indra/llwindow/llwindowsdl.cpp index 7c837205fe..71747a9205 100644 --- a/indra/llwindow/llwindowsdl.cpp +++ b/indra/llwindow/llwindowsdl.cpp @@ -58,6 +58,7 @@ extern "C" { # include # include # include +# include #endif // LL_LINUX || LL_SOLARIS extern BOOL gDebugWindowProc; @@ -2507,9 +2508,32 @@ void exec_cmd(const std::string& cmd, const std::string& arg) { // child // disconnect from stdin/stdout/stderr, or child will // keep our output pipe undesirably alive if it outlives us. - close(0); - close(1); - close(2); + // close(0); + // close(1); + // close(2); + // Reopen stdin, stdout, and stderr to /dev/null. + // It's good practice to always have those file + // descriptors open to something, lest the exec'd + // program actually try to use them. + FILE *result; + result = freopen("/dev/null","r",stdin); + if (result == NULL) + { + llwarns << "Error reopening stdin for web browser: " + << strerror(errno) << llendl; + } + result = freopen("/dev/null","w",stdout); + if (result == NULL) + { + llwarns << "Error reopening stdout for web browser: " + << strerror(errno) << llendl; + } + result = freopen("/dev/null","w",stderr); + if (result == NULL) + { + llwarns << "Error reopening stderr for web browser: " + << strerror(errno) << llendl; + } // end ourself by running the command execv(cmd.c_str(), argv); /* Flawfinder: ignore */ // if execv returns at all, there was a problem. diff --git a/indra/newview/linux_tools/launch_url.sh b/indra/newview/linux_tools/launch_url.sh index f62dce269a..404ea36f26 100755 --- a/indra/newview/linux_tools/launch_url.sh +++ b/indra/newview/linux_tools/launch_url.sh @@ -77,7 +77,7 @@ BROWSER_COMMANDS=" \ netscape" for browser_cmd in $BROWSER_COMMANDS; do if which $browser_cmd >/dev/null; then - $browser_cmd "$URL" >/dev/null 2>&1 & + $browser_cmd "$URL" & exit fi done