Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1531)

Unified Diff: base/process/launch_win.cc

Issue 1809383004: Set current directory when launching Native Messaging processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/launch.h ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/launch_win.cc
diff --git a/base/process/launch_win.cc b/base/process/launch_win.cc
index 985dccc0a3214b3d5d704127ab10721b5dd301ad..ee6bac05adbfc8a031e4d9c2cf83624c60a8dcd3 100644
--- a/base/process/launch_win.cc
+++ b/base/process/launch_win.cc
@@ -49,14 +49,14 @@ const DWORD kProcessKilledExitCode = 1;
bool GetAppOutputInternal(const StringPiece16& cl,
bool include_stderr,
std::string* output) {
- HANDLE out_read = NULL;
- HANDLE out_write = NULL;
+ HANDLE out_read = nullptr;
+ HANDLE out_write = nullptr;
SECURITY_ATTRIBUTES sa_attr;
// Set the bInheritHandle flag so pipe handles are inherited.
sa_attr.nLength = sizeof(SECURITY_ATTRIBUTES);
sa_attr.bInheritHandle = TRUE;
- sa_attr.lpSecurityDescriptor = NULL;
+ sa_attr.lpSecurityDescriptor = nullptr;
// Create the pipe for the child process's STDOUT.
if (!CreatePipe(&out_read, &out_write, &sa_attr, 0)) {
@@ -92,11 +92,10 @@ bool GetAppOutputInternal(const StringPiece16& cl,
// Create the child process.
PROCESS_INFORMATION temp_process_info = {};
- if (!CreateProcess(NULL,
- &writable_command_line_string[0],
- NULL, NULL,
+ if (!CreateProcess(nullptr, &writable_command_line_string[0], nullptr,
+ nullptr,
TRUE, // Handles are inherited.
- 0, NULL, NULL, &start_info, &temp_process_info)) {
+ 0, nullptr, nullptr, &start_info, &temp_process_info)) {
NOTREACHED() << "Failed to start process";
return false;
}
@@ -112,7 +111,8 @@ bool GetAppOutputInternal(const StringPiece16& cl,
for (;;) {
DWORD bytes_read = 0;
- BOOL success = ReadFile(out_read, buffer, kBufferSize, &bytes_read, NULL);
+ BOOL success =
+ ReadFile(out_read, buffer, kBufferSize, &bytes_read, nullptr);
if (!success || bytes_read == 0)
break;
output->append(buffer, bytes_read);
@@ -188,7 +188,7 @@ void RouteStdioToConsole(bool create_console_if_not_found) {
enum { kOutputBufferSize = 64 * 1024 };
if (freopen("CONOUT$", "w", stdout)) {
- setvbuf(stdout, NULL, _IOLBF, kOutputBufferSize);
+ setvbuf(stdout, nullptr, _IOLBF, kOutputBufferSize);
// Overwrite FD 1 for the benefit of any code that uses this FD
// directly. This is safe because the CRT allocates FDs 0, 1 and
// 2 at startup even if they don't have valid underlying Windows
@@ -197,7 +197,7 @@ void RouteStdioToConsole(bool create_console_if_not_found) {
_dup2(_fileno(stdout), 1);
}
if (freopen("CONOUT$", "w", stderr)) {
- setvbuf(stderr, NULL, _IOLBF, kOutputBufferSize);
+ setvbuf(stderr, nullptr, _IOLBF, kOutputBufferSize);
_dup2(_fileno(stderr), 2);
}
@@ -290,22 +290,24 @@ Process LaunchProcess(const string16& cmdline,
PROCESS_INFORMATION temp_process_info = {};
+ LPCTSTR current_directory = options.current_directory.empty()
+ ? nullptr
+ : options.current_directory.value().c_str();
+
string16 writable_cmdline(cmdline);
if (options.as_user) {
flags |= CREATE_UNICODE_ENVIRONMENT;
- void* enviroment_block = NULL;
+ void* enviroment_block = nullptr;
if (!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE)) {
DPLOG(ERROR);
return Process();
}
- BOOL launched =
- CreateProcessAsUser(options.as_user, NULL,
- &writable_cmdline[0],
- NULL, NULL, inherit_handles, flags,
- enviroment_block, NULL, startup_info,
- &temp_process_info);
+ BOOL launched = CreateProcessAsUser(
+ options.as_user, nullptr, &writable_cmdline[0], nullptr, nullptr,
+ inherit_handles, flags, enviroment_block, current_directory,
+ startup_info, &temp_process_info);
DestroyEnvironmentBlock(enviroment_block);
if (!launched) {
DPLOG(ERROR) << "Command line:" << std::endl << UTF16ToUTF8(cmdline)
@@ -313,9 +315,8 @@ Process LaunchProcess(const string16& cmdline,
return Process();
}
} else {
- if (!CreateProcess(NULL,
- &writable_cmdline[0], NULL, NULL,
- inherit_handles, flags, NULL, NULL,
+ if (!CreateProcess(nullptr, &writable_cmdline[0], nullptr, nullptr,
+ inherit_handles, flags, nullptr, current_directory,
startup_info, &temp_process_info)) {
DPLOG(ERROR) << "Command line:" << std::endl << UTF16ToUTF8(cmdline)
<< std::endl;
@@ -354,9 +355,9 @@ Process LaunchElevatedProcess(const CommandLine& cmdline,
shex_info.lpVerb = L"runas";
shex_info.lpFile = file.c_str();
shex_info.lpParameters = arguments.c_str();
- shex_info.lpDirectory = NULL;
+ shex_info.lpDirectory = nullptr;
shex_info.nShow = options.start_hidden ? SW_HIDE : SW_SHOW;
- shex_info.hInstApp = NULL;
+ shex_info.hInstApp = nullptr;
if (!ShellExecuteEx(&shex_info)) {
DPLOG(ERROR);
« no previous file with comments | « base/process/launch.h ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698