<rdar://problem/10840355>

Fixed STDERR to not be opened as readable. Also cleaned up some of the code that implemented the file actions as some of the code was using the wrong variables, they now use the right ones (in for stdin, out for stdout, err for stderr).

llvm-svn: 152102
This commit is contained in:
Greg Clayton 2012-03-06 04:01:04 +00:00
parent 97f7e81891
commit 9845a8d54d
4 changed files with 37 additions and 35 deletions

View File

@ -520,12 +520,12 @@ public:
m_monitor_callback_baton (NULL),
m_monitor_signals (false)
{
if (stderr_path)
if (stdin_path)
{
ProcessLaunchInfo::FileAction file_action;
const bool read = true;
const bool write = true;
if (file_action.Open(STDERR_FILENO, stderr_path, read, write))
const bool write = false;
if (file_action.Open(STDIN_FILENO, stdin_path, read, write))
AppendFileAction (file_action);
}
if (stdout_path)
@ -536,12 +536,12 @@ public:
if (file_action.Open(STDOUT_FILENO, stdout_path, read, write))
AppendFileAction (file_action);
}
if (stdin_path)
if (stderr_path)
{
ProcessLaunchInfo::FileAction file_action;
const bool read = true;
const bool write = false;
if (file_action.Open(STDIN_FILENO, stdin_path, read, write))
const bool read = false;
const bool write = true;
if (file_action.Open(STDERR_FILENO, stderr_path, read, write))
AppendFileAction (file_action);
}
if (working_directory)

View File

@ -815,7 +815,7 @@ GDBRemoteCommunicationServer::Handle_QSetSTDERR (StringExtractorGDBRemote &packe
std::string path;
packet.GetHexByteString(path);
const bool read = true;
const bool write = true;
const bool write = false;
if (file_action.Open(STDERR_FILENO, path.c_str(), read, write))
{
m_process_launch_info.AppendFileAction(file_action);

View File

@ -259,9 +259,9 @@ ProcessLaunchInfo::FinalizeFileActions (Target *target, bool default_to_use_pty)
{
if (m_flags.Test(eLaunchFlagDisableSTDIO))
{
AppendSuppressFileAction (STDERR_FILENO, true , true );
AppendSuppressFileAction (STDIN_FILENO , true , false);
AppendSuppressFileAction (STDOUT_FILENO, false, true );
AppendSuppressFileAction (STDIN_FILENO , true, false);
AppendSuppressFileAction (STDOUT_FILENO, false, true);
AppendSuppressFileAction (STDERR_FILENO, false, true);
}
else
{
@ -274,9 +274,9 @@ ProcessLaunchInfo::FinalizeFileActions (Target *target, bool default_to_use_pty)
const char *err_path = NULL;
if (target)
{
in_path = target->GetStandardErrorPath();
out_path = target->GetStandardInputPath();
err_path = target->GetStandardOutputPath();
in_path = target->GetStandardInputPath();
out_path = target->GetStandardOutputPath();
err_path = target->GetStandardErrorPath();
}
if (default_to_use_pty && (!in_path && !out_path && !err_path))
@ -288,13 +288,14 @@ ProcessLaunchInfo::FinalizeFileActions (Target *target, bool default_to_use_pty)
}
if (in_path)
AppendOpenFileAction(STDERR_FILENO, in_path, true, true);
AppendOpenFileAction(STDIN_FILENO, in_path, true, false);
if (out_path)
AppendOpenFileAction(STDIN_FILENO, out_path, true, false);
AppendOpenFileAction(STDOUT_FILENO, out_path, false, true);
if (err_path)
AppendOpenFileAction(STDOUT_FILENO, err_path, false, true);
AppendOpenFileAction(STDERR_FILENO, err_path, false, true);
}
}
}
@ -518,18 +519,10 @@ ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *op
launch_info.GetFlags().Set (eLaunchFlagStopAtEntry);
break;
case 'e': // STDERR for read + write
{
ProcessLaunchInfo::FileAction action;
if (action.Open(STDERR_FILENO, option_arg, true, true))
launch_info.AppendFileAction (action);
}
break;
case 'i': // STDIN for read only
{
ProcessLaunchInfo::FileAction action;
if (action.Open(STDIN_FILENO, option_arg, true, false))
if (action.Open (STDIN_FILENO, option_arg, true, false))
launch_info.AppendFileAction (action);
}
break;
@ -537,11 +530,20 @@ ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *op
case 'o': // Open STDOUT for write only
{
ProcessLaunchInfo::FileAction action;
if (action.Open(STDOUT_FILENO, option_arg, false, true))
if (action.Open (STDOUT_FILENO, option_arg, false, true))
launch_info.AppendFileAction (action);
}
break;
case 'e': // STDERR for write only
{
ProcessLaunchInfo::FileAction action;
if (action.Open (STDERR_FILENO, option_arg, false, true))
launch_info.AppendFileAction (action);
}
break;
case 'p': // Process plug-in name
launch_info.SetProcessPluginName (option_arg);
break;
@ -549,11 +551,11 @@ ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *op
case 'n': // Disable STDIO
{
ProcessLaunchInfo::FileAction action;
if (action.Open(STDERR_FILENO, "/dev/null", true, true))
if (action.Open (STDIN_FILENO, "/dev/null", true, false))
launch_info.AppendFileAction (action);
if (action.Open(STDOUT_FILENO, "/dev/null", false, true))
if (action.Open (STDOUT_FILENO, "/dev/null", false, true))
launch_info.AppendFileAction (action);
if (action.Open(STDIN_FILENO, "/dev/null", true, false))
if (action.Open (STDERR_FILENO, "/dev/null", false, true))
launch_info.AppendFileAction (action);
}
break;

View File

@ -1723,7 +1723,7 @@ MachProcess::PosixSpawnChildForPTraceDebugging
err.LogThreaded ("::posix_spawn_file_actions_addopen (&file_actions, filedes=STDOUT_FILENO, path=/dev/null)");
err.SetError( ::posix_spawn_file_actions_addopen (&file_actions, STDERR_FILENO, "/dev/null",
O_RDWR | O_NOCTTY, 0), DNBError::POSIX);
O_WRONLY | O_NOCTTY, 0), DNBError::POSIX);
if (err.Fail() || DNBLogCheckLogBit (LOG_PROCESS))
err.LogThreaded ("::posix_spawn_file_actions_addopen (&file_actions, filedes=STDERR_FILENO, path=/dev/null)");
}
@ -1733,9 +1733,9 @@ MachProcess::PosixSpawnChildForPTraceDebugging
if (stdout_path == NULL) stdout_path = "/dev/null";
if (stderr_path == NULL) stderr_path = "/dev/null";
int slave_fd_err = open (stderr_path, O_NOCTTY | O_CREAT | O_RDWR , 0640);
int slave_fd_in = open (stdin_path , O_NOCTTY | O_RDONLY);
int slave_fd_out = open (stdout_path, O_NOCTTY | O_CREAT | O_WRONLY , 0640);
const int slave_fd_in = open (stdin_path , O_NOCTTY | O_RDONLY);
const int slave_fd_out = open (stdout_path, O_NOCTTY | O_CREAT | O_WRONLY , 0640);
const int slave_fd_err = open (stderr_path, O_NOCTTY | O_CREAT | O_WRONLY , 0640);
err.SetError( ::posix_spawn_file_actions_adddup2(&file_actions, slave_fd_err, STDERR_FILENO), DNBError::POSIX);
if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS))