Skip to content

Commit

Permalink
Fix git on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Nov 14, 2011
1 parent e2943e7 commit 53eae78
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 55 deletions.
9 changes: 8 additions & 1 deletion src/cpp/core/system/Win32ChildProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ Error ChildProcess::run()
lpEnv = &envBlock[0];
}

LPCSTR lpWorkingDir = NULL;
if (!options_.workingDir.empty())
{
lpWorkingDir = string_utils::utf8ToSystem(
options_.workingDir.absolutePathNative()).c_str();

This comment has been minimized.

Copy link
@jjallaire

jjallaire Nov 15, 2011

Member

When you take a c_str from a string then the memory is not guaranteed to survive the destruction of the string. Since in this case the string is a temporary I think this c_str could become invalid immediately. You should have a std::string outside the if clause which holds the return from c_str.

}

// Start the child process.
PROCESS_INFORMATION pi;
::ZeroMemory( &pi, sizeof(PROCESS_INFORMATION));
Expand All @@ -381,7 +388,7 @@ Error ChildProcess::run()
TRUE, // Set handle inheritance to TRUE
dwFlags, // Creation flags
lpEnv, // Environment block
NULL, // Use parent's starting directory
lpWorkingDir, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ); // Pointer to PROCESS_INFORMATION structure

Expand Down
46 changes: 44 additions & 2 deletions src/cpp/session/modules/SessionConsoleProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ ConsoleProcess::ConsoleProcess(const std::string& command,
: command_(command), options_(options), caption_(caption), dialog_(dialog),
started_(false), interrupt_(false), outputBuffer_(OUTPUT_BUFFER_SIZE),
onExit_(onExit)
{
commonInit();
}

ConsoleProcess::ConsoleProcess(const std::string& program,
const std::vector<std::string>& args,
const core::system::ProcessOptions& options,
const std::string& caption,
bool dialog,
const boost::function<void()>& onExit)
: program_(program), args_(args), options_(options), caption_(caption), dialog_(dialog),
started_(false), interrupt_(false), outputBuffer_(OUTPUT_BUFFER_SIZE),
onExit_(onExit)
{
commonInit();
}

void ConsoleProcess::commonInit()
{
handle_ = core::system::generateUuid(false);

Expand All @@ -82,8 +100,17 @@ Error ConsoleProcess::start()
if (started_)
return Success();

Error error = module_context::processSupervisor().runCommand(
Error error;
if (!command_.empty())
{
error = module_context::processSupervisor().runCommand(
command_, options_, createProcessCallbacks());
}
else
{
error = module_context::processSupervisor().runProgram(
program_, args_, options_, createProcessCallbacks());
}
if (!error)
started_ = true;
return error;
Expand Down Expand Up @@ -276,7 +303,7 @@ Error procReap(const json::JsonRpcRequest& request,
}

boost::shared_ptr<ConsoleProcess> ConsoleProcess::create(
const std::string &command,
const std::string& command,
core::system::ProcessOptions options,
const std::string& caption,
bool dialog,
Expand All @@ -289,6 +316,21 @@ boost::shared_ptr<ConsoleProcess> ConsoleProcess::create(
return ptrProc;
}

boost::shared_ptr<ConsoleProcess> ConsoleProcess::create(
const std::string& program,
const std::vector<std::string>& args,
core::system::ProcessOptions options,
const std::string& caption,
bool dialog,
const boost::function<void()>& onExit)
{
options.terminateChildren = true;
boost::shared_ptr<ConsoleProcess> ptrProc(
new ConsoleProcess(program, args, options, caption, dialog, onExit));
s_procs[ptrProc->handle()] = ptrProc;
return ptrProc;
}

core::json::Array processesAsJson()
{
json::Array procInfos;
Expand Down
20 changes: 20 additions & 0 deletions src/cpp/session/modules/SessionConsoleProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class ConsoleProcess : boost::noncopyable,
bool dialog,
const boost::function<void()>& onExit);

ConsoleProcess(
const std::string& program,
const std::vector<std::string>& args,
const core::system::ProcessOptions& options,
const std::string& caption,
bool dialog,
const boost::function<void()>& onExit);

void commonInit();

public:
static boost::shared_ptr<ConsoleProcess> create(
const std::string& command,
Expand All @@ -52,6 +62,14 @@ class ConsoleProcess : boost::noncopyable,
bool dialog,
const boost::function<void()>& onExit=boost::function<void()>());

static boost::shared_ptr<ConsoleProcess> create(
const std::string& program,
const std::vector<std::string>& args,
core::system::ProcessOptions options,
const std::string& caption,
bool dialog,
const boost::function<void()>& onExit=boost::function<void()>());

virtual ~ConsoleProcess() {}

std::string handle() const { return handle_; }
Expand All @@ -78,6 +96,8 @@ class ConsoleProcess : boost::noncopyable,
private:
// Command and options that will be used when start() is called
std::string command_;
std::string program_;
std::vector<std::string> args_;
core::system::ProcessOptions options_;

std::string caption_;
Expand Down
Loading

0 comments on commit 53eae78

Please sign in to comment.