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

Side by Side Diff: runtime/bin/process_impl.dart

Issue 8506013: Correct the sign of exit codes for the process library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/process_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class _ProcessStartStatus { 5 class _ProcessStartStatus {
6 int _errorCode; // Set to OS error code if process start failed. 6 int _errorCode; // Set to OS error code if process start failed.
7 String _errorMessage; // Set to OS error message if process start failed. 7 String _errorMessage; // Set to OS error message if process start failed.
8 } 8 }
9 9
10 10
(...skipping 21 matching lines...) Expand all
32 _in = new _Socket._internalOutputOnly(); 32 _in = new _Socket._internalOutputOnly();
33 _out = new _Socket._internalInputOnly(); 33 _out = new _Socket._internalInputOnly();
34 _err = new _Socket._internalOutputOnly(); 34 _err = new _Socket._internalOutputOnly();
35 _exitHandler = new _Socket._internal(); 35 _exitHandler = new _Socket._internal();
36 _closed = false; 36 _closed = false;
37 _killed = false; 37 _killed = false;
38 _started = false; 38 _started = false;
39 _exitHandlerCallback = null; 39 _exitHandlerCallback = null;
40 } 40 }
41 41
42 int _intFromBytes(List<int> bytes, int offset) {
43 return (bytes[offset] +
44 (bytes[offset + 1] << 8) +
45 (bytes[offset + 2] << 16) +
46 (bytes[offset + 3] << 24));
47 }
48
42 void start() { 49 void start() {
43 var status = new _ProcessStartStatus(); 50 var status = new _ProcessStartStatus();
44 bool success = _start( 51 bool success = _start(
45 _path, _arguments, _in, _out, _err, _exitHandler, status); 52 _path, _arguments, _in, _out, _err, _exitHandler, status);
46 if (!success) { 53 if (!success) {
47 close(); 54 close();
48 throw new ProcessException(status._errorMessage, status._errorCode); 55 throw new ProcessException(status._errorMessage, status._errorCode);
49 } 56 }
50 _started = true; 57 _started = true;
51 58
52 // Make sure to activate socket handlers now that the file 59 // Make sure to activate socket handlers now that the file
53 // descriptors have been set. 60 // descriptors have been set.
54 _in._activateHandlers(); 61 _in._activateHandlers();
55 _out._activateHandlers(); 62 _out._activateHandlers();
56 _err._activateHandlers(); 63 _err._activateHandlers();
57 64
58 // Setup an exit handler to handle internal cleanup and possible 65 // Setup an exit handler to handle internal cleanup and possible
59 // callback when a process terminates. 66 // callback when a process terminates.
60 _exitHandler.dataHandler = () { 67 _exitHandler.dataHandler = () {
61 final int EXIT_DATA_SIZE = 8; 68 final int EXIT_DATA_SIZE = 12;
62 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE); 69 List<int> exitDataBuffer = new List<int>(EXIT_DATA_SIZE);
63 InputStream input = _exitHandler.inputStream; 70 InputStream input = _exitHandler.inputStream;
64 int exitDataRead = 0; 71 int exitDataRead = 0;
65 72
66 int exitCode(List<int> ints) { 73 int exitCode(List<int> ints) {
67 return ints[4] + (ints[5] << 8) + (ints[6] << 16) + (ints[7] << 24); 74 var code = _intFromBytes(ints, 4);
75 var negative = _intFromBytes(ints, 8);
76 assert(negative == 0 || negative == 1);
77 return (negative == 0) ? code : -code;
68 } 78 }
69 79
70 int exitPid(List<int> ints) { 80 int exitPid(List<int> ints) {
71 return ints[0] + (ints[1] << 8) + (ints[2] << 16) + (ints[3] << 24); 81 return _intFromBytes(ints, 0);
72 } 82 }
73 83
74 void handleExit() { 84 void handleExit() {
75 _processExit(exitPid(exitDataBuffer)); 85 _processExit(exitPid(exitDataBuffer));
76 if (_exitHandlerCallback !== null) { 86 if (_exitHandlerCallback !== null) {
77 _exitHandlerCallback(exitCode(exitDataBuffer)); 87 _exitHandlerCallback(exitCode(exitDataBuffer));
78 } 88 }
79 } 89 }
80 90
81 void exitData() { 91 void exitData() {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 Socket _in; 171 Socket _in;
162 Socket _out; 172 Socket _out;
163 Socket _err; 173 Socket _err;
164 Socket _exitHandler; 174 Socket _exitHandler;
165 int _pid; 175 int _pid;
166 bool _closed; 176 bool _closed;
167 bool _killed; 177 bool _killed;
168 bool _started; 178 bool _started;
169 var _exitHandlerCallback; 179 var _exitHandlerCallback;
170 } 180 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/process_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698