Added a new directory type for the "bool Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)" function: ePathTypeLLDBTempSystemDir

This will get the temporary directory on the current system.

Removed a call to tmpnam() and replaced it with a call to mktemp() using a template that will be in the temp directory.

llvm-svn: 196397
This commit is contained in:
Greg Clayton 2013-12-04 18:53:50 +00:00
parent 6a439adf44
commit c6931fcf49
2 changed files with 46 additions and 5 deletions

View File

@ -117,7 +117,9 @@ typedef enum PathType
ePathTypeHeaderDir, // Find LLDB header file directory
ePathTypePythonDir, // Find Python modules (PYTHONPATH) directory
ePathTypeLLDBSystemPlugins, // System plug-ins directory
ePathTypeLLDBUserPlugins // User plug-ins directory
ePathTypeLLDBUserPlugins, // User plug-ins directory
ePathTypeLLDBTempSystemDir // The LLDB temp directory for this system
} PathType;

View File

@ -13,6 +13,7 @@
#include <errno.h>
#include <limits.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef _WIN32
#include "lldb/Host/windows/windows.h"
#include <winsock2.h>
@ -1224,6 +1225,29 @@ Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
// TODO: where would user LLDB plug-ins be located on other systems?
return false;
}
case ePathTypeLLDBTempSystemDir:
{
static ConstString g_lldb_tmp_dir;
if (!g_lldb_tmp_dir)
{
const char *tmpdir_cstr = getenv("TMPDIR");
if (tmpdir_cstr == NULL)
{
tmpdir_cstr = getenv("TMP");
if (tmpdir_cstr == NULL)
tmpdir_cstr = getenv("TEMP");
}
if (tmpdir_cstr)
{
g_lldb_tmp_dir.SetCString(tmpdir_cstr);
if (log)
log->Printf("Host::GetLLDBPath(ePathTypeLLDBTempSystemDir) => '%s'", g_lldb_tmp_dir.GetCString());
}
}
file_spec.GetDirectory() = g_lldb_tmp_dir;
return (bool)file_spec.GetDirectory();
}
}
return false;
@ -1473,21 +1497,36 @@ Host::RunShellCommand (const char *command,
if (working_dir)
launch_info.SetWorkingDirectory(working_dir);
char output_file_path_buffer[L_tmpnam];
char output_file_path_buffer[PATH_MAX];
const char *output_file_path = NULL;
if (command_output_ptr)
{
// Create a temporary file to get the stdout/stderr and redirect the
// output of the command into this file. We will later read this file
// if all goes well and fill the data into "command_output_ptr"
output_file_path = ::tmpnam(output_file_path_buffer);
launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
FileSpec tmpdir_file_spec;
if (Host::GetLLDBPath (ePathTypeLLDBTempSystemDir, tmpdir_file_spec))
{
tmpdir_file_spec.GetFilename().SetCString("lldb-shell-output.XXXXXX");
strncpy(output_file_path_buffer, tmpdir_file_spec.GetPath().c_str(), sizeof(output_file_path_buffer));
}
else
{
strncpy(output_file_path_buffer, "/tmp/lldb-shell-output.XXXXXX", sizeof(output_file_path_buffer));
}
output_file_path = ::mktemp(output_file_path_buffer);
}
launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
if (output_file_path)
{
launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_path, false, true);
launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
}
else
{
launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
}