Better fix for reopening files to /dev/null for web browser on Linux.

Tonya Souther 2012-10-16 12:16:39 -05:00
parent 36e18a898f
commit 1b585cc713
2 changed files with 28 additions and 4 deletions

View File

@ -58,6 +58,7 @@ extern "C" {
# include <unistd.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <stdio.h>
#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);
// <FS:TS> 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.

View File

@ -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