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

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

Issue 10963024: Use native fields for process pid and fix bug that allowed killing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review commetns. Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/process.cc ('k') | tests/standalone/io/process_kill_unstarted_test.dart » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 _exit(int status) native "Exit"; 5 _exit(int status) native "Exit";
6 6
7 class _ProcessStartStatus { 7 class _ProcessStartStatus {
8 int _errorCode; // Set to OS error code if process start failed. 8 int _errorCode; // Set to OS error code if process start failed.
9 String _errorMessage; // Set to OS error message if process start failed. 9 String _errorMessage; // Set to OS error message if process start failed.
10 } 10 }
11 11
12 12
13 class _Process extends Process { 13 class _Process extends NativeFieldWrapperClass1 implements Process {
14 static Future<ProcessResult> run(String path, 14 static Future<ProcessResult> run(String path,
15 List<String> arguments, 15 List<String> arguments,
16 [ProcessOptions options]) { 16 [ProcessOptions options]) {
17 return new _NonInteractiveProcess._start(path, arguments, options)._result; 17 return new _NonInteractiveProcess._start(path, arguments, options)._result;
18 } 18 }
19 19
20 _Process.start(String path, 20 _Process.start(String path,
21 List<String> arguments, 21 List<String> arguments,
22 ProcessOptions options) { 22 ProcessOptions options) {
23 if (path is !String) { 23 if (path is !String) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 throw new ProcessException("Process closed"); 220 throw new ProcessException("Process closed");
221 } 221 }
222 return _out.outputStream; 222 return _out.outputStream;
223 } 223 }
224 224
225 void kill([ProcessSignal signal = ProcessSignal.SIGTERM]) { 225 void kill([ProcessSignal signal = ProcessSignal.SIGTERM]) {
226 if (signal is! ProcessSignal) { 226 if (signal is! ProcessSignal) {
227 throw new IllegalArgumentException( 227 throw new IllegalArgumentException(
228 "Argument 'signal' must be a ProcessSignal"); 228 "Argument 'signal' must be a ProcessSignal");
229 } 229 }
230 if (_closed && _pid === null) { 230 if (!_started) {
231 _reportError(new ProcessException("Process closed")); 231 var e = new ProcessException("Cannot kill process that is not started");
232 _reportError(e);
232 return; 233 return;
233 } 234 }
234 if (_ended) { 235 if (_ended) {
235 return; 236 return;
236 } 237 }
237 // TODO(ager): Make the actual kill operation asynchronous. 238 if (_kill(this, signal._signalNumber)) {
238 if (_kill(_pid, signal._signalNumber)) {
239 return; 239 return;
240 } 240 }
241 _reportError(new ProcessException("Could not kill process")); 241 _reportError(new ProcessException("Could not kill process"));
242 return; 242 return;
243 } 243 }
244 244
245 bool _kill(int pid, int signal) native "Process_Kill"; 245 bool _kill(Process p, int signal) native "Process_Kill";
246 246
247 void close() { 247 void close() {
248 if (_closed) { 248 if (_closed) {
249 throw new ProcessException("Process closed"); 249 throw new ProcessException("Process closed");
250 } 250 }
251 _in.close(); 251 _in.close();
252 _out.close(); 252 _out.close();
253 _err.close(); 253 _err.close();
254 _exitHandler.close(); 254 _exitHandler.close();
255 _closed = true; 255 _closed = true;
(...skipping 27 matching lines...) Expand all
283 283
284 String _path; 284 String _path;
285 ObjectArray<String> _arguments; 285 ObjectArray<String> _arguments;
286 String _workingDirectory; 286 String _workingDirectory;
287 List<String> _environment; 287 List<String> _environment;
288 // Private methods of _Socket are used by _in, _out, and _err. 288 // Private methods of _Socket are used by _in, _out, and _err.
289 _Socket _in; 289 _Socket _in;
290 _Socket _out; 290 _Socket _out;
291 _Socket _err; 291 _Socket _err;
292 Socket _exitHandler; 292 Socket _exitHandler;
293 int _pid;
294 bool _closed; 293 bool _closed;
295 bool _ended; 294 bool _ended;
296 bool _started; 295 bool _started;
297 Function _onExit; 296 Function _onExit;
298 Function _onError; 297 Function _onError;
299 Function _onStart; 298 Function _onStart;
300 } 299 }
301 300
302 301
303 // _NonInteractiveProcess is a wrapper around an interactive process 302 // _NonInteractiveProcess is a wrapper around an interactive process
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 390
392 class _ProcessResult implements ProcessResult { 391 class _ProcessResult implements ProcessResult {
393 const _ProcessResult(int this.exitCode, 392 const _ProcessResult(int this.exitCode,
394 String this.stdout, 393 String this.stdout,
395 String this.stderr); 394 String this.stderr);
396 395
397 final int exitCode; 396 final int exitCode;
398 final String stdout; 397 final String stdout;
399 final String stderr; 398 final String stderr;
400 } 399 }
OLDNEW
« no previous file with comments | « runtime/bin/process.cc ('k') | tests/standalone/io/process_kill_unstarted_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698