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

Side by Side Diff: runtime/bin/process_android.cc

Issue 11312242: Revised CL for customisable logging (replacing printfs). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
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 #include "bin/process.h" 5 #include "bin/process.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <poll.h> 9 #include <poll.h>
10 #include <signal.h> 10 #include <signal.h>
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <stdlib.h> 12 #include <stdlib.h>
13 #include <string.h> 13 #include <string.h>
14 #include <sys/wait.h> 14 #include <sys/wait.h>
15 #include <unistd.h> 15 #include <unistd.h>
16 16
17 #include "bin/fdutils.h" 17 #include "bin/fdutils.h"
18 #include "bin/log.h"
18 #include "bin/thread.h" 19 #include "bin/thread.h"
19 20
20 21
21 // ProcessInfo is used to map a process id to the file descriptor for 22 // ProcessInfo is used to map a process id to the file descriptor for
22 // the pipe used to communicate the exit code of the process to Dart. 23 // the pipe used to communicate the exit code of the process to Dart.
23 // ProcessInfo objects are kept in the static singly-linked 24 // ProcessInfo objects are kept in the static singly-linked
24 // ProcessInfoList. 25 // ProcessInfoList.
25 class ProcessInfo { 26 class ProcessInfo {
26 public: 27 public:
27 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { } 28 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 pid_t pid; 320 pid_t pid;
320 int read_in[2]; // Pipe for stdout to child process. 321 int read_in[2]; // Pipe for stdout to child process.
321 int read_err[2]; // Pipe for stderr to child process. 322 int read_err[2]; // Pipe for stderr to child process.
322 int write_out[2]; // Pipe for stdin to child process. 323 int write_out[2]; // Pipe for stdin to child process.
323 int exec_control[2]; // Pipe to get the result from exec. 324 int exec_control[2]; // Pipe to get the result from exec.
324 int result; 325 int result;
325 326
326 bool initialized = ExitCodeHandler::EnsureInitialized(); 327 bool initialized = ExitCodeHandler::EnsureInitialized();
327 if (!initialized) { 328 if (!initialized) {
328 SetChildOsErrorMessage(os_error_message, os_error_message_len); 329 SetChildOsErrorMessage(os_error_message, os_error_message_len);
329 fprintf(stderr, 330 Log::PrintErr("Error initializing exit code handler: %s\n",
330 "Error initializing exit code handler: %s\n", 331 os_error_message);
331 os_error_message);
332 return errno; 332 return errno;
333 } 333 }
334 334
335 result = TEMP_FAILURE_RETRY(pipe(read_in)); 335 result = TEMP_FAILURE_RETRY(pipe(read_in));
336 if (result < 0) { 336 if (result < 0) {
337 SetChildOsErrorMessage(os_error_message, os_error_message_len); 337 SetChildOsErrorMessage(os_error_message, os_error_message_len);
338 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 338 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
339 return errno; 339 return errno;
340 } 340 }
341 341
342 result = TEMP_FAILURE_RETRY(pipe(read_err)); 342 result = TEMP_FAILURE_RETRY(pipe(read_err));
343 if (result < 0) { 343 if (result < 0) {
344 SetChildOsErrorMessage(os_error_message, os_error_message_len); 344 SetChildOsErrorMessage(os_error_message, os_error_message_len);
345 TEMP_FAILURE_RETRY(close(read_in[0])); 345 TEMP_FAILURE_RETRY(close(read_in[0]));
346 TEMP_FAILURE_RETRY(close(read_in[1])); 346 TEMP_FAILURE_RETRY(close(read_in[1]));
347 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 347 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
348 return errno; 348 return errno;
349 } 349 }
350 350
351 result = TEMP_FAILURE_RETRY(pipe(write_out)); 351 result = TEMP_FAILURE_RETRY(pipe(write_out));
352 if (result < 0) { 352 if (result < 0) {
353 SetChildOsErrorMessage(os_error_message, os_error_message_len); 353 SetChildOsErrorMessage(os_error_message, os_error_message_len);
354 TEMP_FAILURE_RETRY(close(read_in[0])); 354 TEMP_FAILURE_RETRY(close(read_in[0]));
355 TEMP_FAILURE_RETRY(close(read_in[1])); 355 TEMP_FAILURE_RETRY(close(read_in[1]));
356 TEMP_FAILURE_RETRY(close(read_err[0])); 356 TEMP_FAILURE_RETRY(close(read_err[0]));
357 TEMP_FAILURE_RETRY(close(read_err[1])); 357 TEMP_FAILURE_RETRY(close(read_err[1]));
358 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 358 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
359 return errno; 359 return errno;
360 } 360 }
361 361
362 result = TEMP_FAILURE_RETRY(pipe(exec_control)); 362 result = TEMP_FAILURE_RETRY(pipe(exec_control));
363 if (result < 0) { 363 if (result < 0) {
364 SetChildOsErrorMessage(os_error_message, os_error_message_len); 364 SetChildOsErrorMessage(os_error_message, os_error_message_len);
365 TEMP_FAILURE_RETRY(close(read_in[0])); 365 TEMP_FAILURE_RETRY(close(read_in[0]));
366 TEMP_FAILURE_RETRY(close(read_in[1])); 366 TEMP_FAILURE_RETRY(close(read_in[1]));
367 TEMP_FAILURE_RETRY(close(read_err[0])); 367 TEMP_FAILURE_RETRY(close(read_err[0]));
368 TEMP_FAILURE_RETRY(close(read_err[1])); 368 TEMP_FAILURE_RETRY(close(read_err[1]));
369 TEMP_FAILURE_RETRY(close(write_out[0])); 369 TEMP_FAILURE_RETRY(close(write_out[0]));
370 TEMP_FAILURE_RETRY(close(write_out[1])); 370 TEMP_FAILURE_RETRY(close(write_out[1]));
371 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 371 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
372 return errno; 372 return errno;
373 } 373 }
374 374
375 // Set close on exec on the write file descriptor of the exec control pipe. 375 // Set close on exec on the write file descriptor of the exec control pipe.
376 result = TEMP_FAILURE_RETRY( 376 result = TEMP_FAILURE_RETRY(
377 fcntl(exec_control[1], 377 fcntl(exec_control[1],
378 F_SETFD, 378 F_SETFD,
379 TEMP_FAILURE_RETRY(fcntl(exec_control[1], F_GETFD)) | FD_CLOEXEC)); 379 TEMP_FAILURE_RETRY(fcntl(exec_control[1], F_GETFD)) | FD_CLOEXEC));
380 if (result < 0) { 380 if (result < 0) {
381 SetChildOsErrorMessage(os_error_message, os_error_message_len); 381 SetChildOsErrorMessage(os_error_message, os_error_message_len);
382 TEMP_FAILURE_RETRY(close(read_in[0])); 382 TEMP_FAILURE_RETRY(close(read_in[0]));
383 TEMP_FAILURE_RETRY(close(read_in[1])); 383 TEMP_FAILURE_RETRY(close(read_in[1]));
384 TEMP_FAILURE_RETRY(close(read_err[0])); 384 TEMP_FAILURE_RETRY(close(read_err[0]));
385 TEMP_FAILURE_RETRY(close(read_err[1])); 385 TEMP_FAILURE_RETRY(close(read_err[1]));
386 TEMP_FAILURE_RETRY(close(write_out[0])); 386 TEMP_FAILURE_RETRY(close(write_out[0]));
387 TEMP_FAILURE_RETRY(close(write_out[1])); 387 TEMP_FAILURE_RETRY(close(write_out[1]));
388 TEMP_FAILURE_RETRY(close(exec_control[0])); 388 TEMP_FAILURE_RETRY(close(exec_control[0]));
389 TEMP_FAILURE_RETRY(close(exec_control[1])); 389 TEMP_FAILURE_RETRY(close(exec_control[1]));
390 fprintf(stderr, "fcntl failed: %s\n", os_error_message); 390 Log::PrintErr("fcntl failed: %s\n", os_error_message);
391 return errno; 391 return errno;
392 } 392 }
393 393
394 char** program_arguments = new char*[arguments_length + 2]; 394 char** program_arguments = new char*[arguments_length + 2];
395 program_arguments[0] = const_cast<char*>(path); 395 program_arguments[0] = const_cast<char*>(path);
396 for (int i = 0; i < arguments_length; i++) { 396 for (int i = 0; i < arguments_length; i++) {
397 program_arguments[i + 1] = arguments[i]; 397 program_arguments[i + 1] = arguments[i];
398 } 398 }
399 program_arguments[arguments_length + 1] = NULL; 399 program_arguments[arguments_length + 1] = NULL;
400 400
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 int event_fds[2]; 481 int event_fds[2];
482 result = TEMP_FAILURE_RETRY(pipe(event_fds)); 482 result = TEMP_FAILURE_RETRY(pipe(event_fds));
483 if (result < 0) { 483 if (result < 0) {
484 SetChildOsErrorMessage(os_error_message, os_error_message_len); 484 SetChildOsErrorMessage(os_error_message, os_error_message_len);
485 TEMP_FAILURE_RETRY(close(read_in[0])); 485 TEMP_FAILURE_RETRY(close(read_in[0]));
486 TEMP_FAILURE_RETRY(close(read_in[1])); 486 TEMP_FAILURE_RETRY(close(read_in[1]));
487 TEMP_FAILURE_RETRY(close(read_err[0])); 487 TEMP_FAILURE_RETRY(close(read_err[0]));
488 TEMP_FAILURE_RETRY(close(read_err[1])); 488 TEMP_FAILURE_RETRY(close(read_err[1]));
489 TEMP_FAILURE_RETRY(close(write_out[0])); 489 TEMP_FAILURE_RETRY(close(write_out[0]));
490 TEMP_FAILURE_RETRY(close(write_out[1])); 490 TEMP_FAILURE_RETRY(close(write_out[1]));
491 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 491 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
492 return errno; 492 return errno;
493 } 493 }
494 494
495 ProcessInfoList::AddProcess(pid, event_fds[1]); 495 ProcessInfoList::AddProcess(pid, event_fds[1]);
496 *exit_event = event_fds[0]; 496 *exit_event = event_fds[0];
497 FDUtils::SetNonBlocking(event_fds[0]); 497 FDUtils::SetNonBlocking(event_fds[0]);
498 498
499 // Notify child process to start. 499 // Notify child process to start.
500 char msg = '1'; 500 char msg = '1';
501 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg)); 501 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 561
562 562
563 void Process::TerminateExitCodeHandler() { 563 void Process::TerminateExitCodeHandler() {
564 ExitCodeHandler::TerminateExitCodeThread(); 564 ExitCodeHandler::TerminateExitCodeThread();
565 } 565 }
566 566
567 567
568 intptr_t Process::CurrentProcessId() { 568 intptr_t Process::CurrentProcessId() {
569 return static_cast<intptr_t>(getpid()); 569 return static_cast<intptr_t>(getpid());
570 } 570 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698