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

Unified Diff: runtime/bin/process_impl.dart

Issue 8227010: Fix deadlock in process exit handling (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from @ager Created 9 years, 2 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 | « runtime/bin/process.cc ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_impl.dart
diff --git a/runtime/bin/process_impl.dart b/runtime/bin/process_impl.dart
index 0e0b6957399b98d2cf57b6598ab0f8da525a4eda..98d72b4811ffc2f630c5209f487e6439854508dc 100644
--- a/runtime/bin/process_impl.dart
+++ b/runtime/bin/process_impl.dart
@@ -38,9 +38,37 @@ class _Process implements Process {
throw new ProcessException(status._errorMessage, status._errorCode);
}
_started = true;
- if (_exitHandlerCallback !== null) {
- setExitHandler(_exitHandlerCallback);
- }
+
+ // Setup an exit handler to handle internal cleanup and possible
+ // callback when a process terminates.
+ _exitHandler.setDataHandler(() {
+ List<int> buffer = new List<int>(8);
+ SocketInputStream input = _exitHandler.inputStream;
+
+ int exitCode(List<int> ints) {
+ return ints[4] + (ints[5] << 8) + (ints[6] << 16) + (ints[7] << 24);
+ }
+
+ int exitPid(List<int> ints) {
+ return ints[0] + (ints[1] << 8) + (ints[2] << 16) + (ints[3] << 24);
+ }
+
+ void handleExit() {
+ _processExit(exitPid(buffer));
+ if (_exitHandlerCallback != null) {
+ _exitHandlerCallback(exitCode(buffer));
+ }
+ }
+
+ void readData() {
+ handleExit();
+ }
+
+ bool result = input.read(buffer, 0, 8, readData);
+ if (result) {
+ handleExit();
+ }
+ });
}
bool _start(String path,
@@ -51,6 +79,8 @@ class _Process implements Process {
Socket exitHandler,
_ProcessStartStatus status) native "Process_Start";
+ void _processExit(int pid) native "Process_Exit";
+
InputStream get stdoutStream() {
if (_closed) {
throw new ProcessException("Process closed");
@@ -106,48 +136,18 @@ class _Process implements Process {
if (_killed) {
throw new ProcessException("Process killed");
}
- if (_started) {
- _exitHandler.setDataHandler(() {
- List<int> buffer = new List<int>(4);
- SocketInputStream input = _exitHandler.inputStream;
-
- int getExitValue(List<int> ints) {
- return ints[0] + (ints[1] << 8) + (ints[2] << 16) + (ints[3] << 24);
- }
-
- void readData() {
- callback(getExitValue(buffer));
- }
-
- bool result = input.read(buffer, 0, 4, readData);
- if (result) {
- callback(getExitValue(buffer));
- }
- });
- } else {
- _exitHandlerCallback = callback;
- }
+ _exitHandlerCallback = callback;
}
String _path;
-
ObjectArray<String> _arguments;
-
Socket _in;
-
Socket _out;
-
Socket _err;
-
Socket _exitHandler;
-
int _pid;
-
bool _closed;
-
bool _killed;
-
bool _started;
-
var _exitHandlerCallback;
}
« no previous file with comments | « runtime/bin/process.cc ('k') | runtime/bin/process_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698