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

Unified Diff: runtime/bin/process_win.cc

Issue 105083009: Revert "Signal handling." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 | « runtime/bin/process_patch.dart ('k') | runtime/bin/signal_blocker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_win.cc
diff --git a/runtime/bin/process_win.cc b/runtime/bin/process_win.cc
index 75524b395ed70bbf4e959985a83738308faef420..00514c775a60d437ea6a69daae7ce44ada2dab59 100644
--- a/runtime/bin/process_win.cc
+++ b/runtime/bin/process_win.cc
@@ -11,7 +11,6 @@
#include "bin/process.h"
#include "bin/eventhandler.h"
#include "bin/log.h"
-#include "bin/socket.h"
#include "bin/thread.h"
#include "bin/utils.h"
#include "bin/utils_win.h"
@@ -350,7 +349,27 @@ static bool EnsureInitialized() {
return delete_proc_thread_attr_list != NULL;
}
-int GenerateNames(int count, wchar_t* pipe_names[], int max_length) {
+
+int Process::Start(const char* path,
+ char* arguments[],
+ intptr_t arguments_length,
+ const char* working_directory,
+ char* environment[],
+ intptr_t environment_length,
+ intptr_t* in,
+ intptr_t* out,
+ intptr_t* err,
+ intptr_t* id,
+ intptr_t* exit_handler,
+ char** os_error_message) {
+ HANDLE stdin_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
+ HANDLE stdout_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
+ HANDLE stderr_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
+ HANDLE exit_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
+
+ // Generate unique pipe names for the four named pipes needed.
+ static const int kMaxPipeNameSize = 80;
+ wchar_t pipe_names[4][kMaxPipeNameSize];
UUID uuid;
RPC_STATUS status = UuidCreateSequential(&uuid);
if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) {
@@ -365,10 +384,10 @@ int GenerateNames(int count, wchar_t* pipe_names[], int max_length) {
Log::PrintErr("UuidToString failed %d\n", status);
return status;
}
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < 4; i++) {
static const wchar_t* prefix = L"\\\\.\\Pipe\\dart";
_snwprintf(pipe_names[i],
- max_length,
+ kMaxPipeNameSize,
L"%s_%s_%d", prefix, uuid_string, i + 1);
}
status = RpcStringFreeW(&uuid_string);
@@ -377,32 +396,6 @@ int GenerateNames(int count, wchar_t* pipe_names[], int max_length) {
Log::PrintErr("RpcStringFree failed %d\n", status);
return status;
}
- return 0;
-}
-
-
-int Process::Start(const char* path,
- char* arguments[],
- intptr_t arguments_length,
- const char* working_directory,
- char* environment[],
- intptr_t environment_length,
- intptr_t* in,
- intptr_t* out,
- intptr_t* err,
- intptr_t* id,
- intptr_t* exit_handler,
- char** os_error_message) {
- HANDLE stdin_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
- HANDLE stdout_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
- HANDLE stderr_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
- HANDLE exit_handles[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE };
-
- // Generate unique pipe names for the four named pipes needed.
- static const int kMaxPipeNameSize = 80;
- wchar_t pipe_names[4][kMaxPipeNameSize];
- int status = GenerateNames(4, pipe_names, kMaxPipeNameSize);
- if (status != 0) return status;
if (!CreateProcessPipe(stdin_handles, pipe_names[0], kInheritRead)) {
int error_code = SetOsErrorMessage(os_error_message);
@@ -856,105 +849,6 @@ intptr_t Process::CurrentProcessId() {
return static_cast<intptr_t>(GetCurrentProcessId());
}
-
-static SignalInfo* signal_handlers = NULL;
-static Mutex* signal_mutex = new Mutex();
-
-
-SignalInfo::~SignalInfo() {
- reinterpret_cast<FileHandle*>(fd_)->Close();
-}
-
-
-BOOL WINAPI SignalHandler(DWORD signal) {
- MutexLocker lock(signal_mutex);
- const SignalInfo* handler = signal_handlers;
- bool handled = false;
- while (handler != NULL) {
- if (handler->signal() == signal) {
- int value = 0;
- Socket::Write(handler->fd(), &value, 1);
- handled = true;
- }
- handler = handler->next();
- }
- return handled;
-}
-
-
-intptr_t GetWinSignal(intptr_t signal) {
- switch (signal) {
- case 1: // SIGHUP
- return CTRL_CLOSE_EVENT;
- case 2: // SIGINT
- return CTRL_C_EVENT;
- default:
- return -1;
- }
-}
-
-
-intptr_t Process::SetSignalHandler(intptr_t signal) {
- signal = GetWinSignal(signal);
- if (signal == -1) return -1;
-
- // Generate a unique pipe name for the named pipe.
- static const int kMaxPipeNameSize = 80;
- wchar_t pipe_name[kMaxPipeNameSize];
- GenerateNames(1, &pipe_name, kMaxPipeNameSize);
- if (status != 0) return status;
-
- HANDLE fds[2];
- if (!CreateProcessPipe(fds, pipe_name, kInheritNone)) {
- int error_code = GetLastError();
- CloseProcessPipe(fds);
- SetLastError(error_code);
- return -1;
- }
- MutexLocker lock(signal_mutex);
- FileHandle* write_handle = new FileHandle(fds[kWriteHandle]);
- write_handle->EnsureInitialized(EventHandler::delegate());
- intptr_t write_fd = reinterpret_cast<intptr_t>(write_handle);
- if (signal_handlers == NULL) {
- if (SetConsoleCtrlHandler(SignalHandler, true) == 0) {
- int error_code = GetLastError();
- delete write_handle;
- CloseProcessPipe(fds);
- SetLastError(error_code);
- return -1;
- }
- signal_handlers = new SignalInfo(write_fd, signal);
- } else {
- new SignalInfo(write_fd, signal, signal_handlers);
- }
- return reinterpret_cast<intptr_t>(new FileHandle(fds[kReadHandle]));
-}
-
-
-void Process::ClearSignalHandler(intptr_t signal) {
- signal = GetWinSignal(signal);
- if (signal == -1) return;
- MutexLocker lock(signal_mutex);
- SignalInfo* handler = signal_handlers;
- while (handler != NULL) {
- if (handler->port() == Dart_GetMainPortId() &&
- handler->signal() == signal) {
- handler->Unlink();
- break;
- }
- handler = handler->next();
- }
- if (handler != NULL) {
- if (signal_handlers == handler) {
- signal_handlers = handler->next();
- }
- if (signal_handlers == NULL) {
- USE(SetConsoleCtrlHandler(SignalHandler, false));
- }
- }
- delete handler;
-}
-
} // namespace bin
} // namespace dart
« no previous file with comments | « runtime/bin/process_patch.dart ('k') | runtime/bin/signal_blocker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698