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

Side by Side Diff: runtime/bin/process_linux.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 extern char **environ; 21 extern char **environ;
21 22
22 // ProcessInfo is used to map a process id to the file descriptor for 23 // ProcessInfo is used to map a process id to the file descriptor for
23 // the pipe used to communicate the exit code of the process to Dart. 24 // the pipe used to communicate the exit code of the process to Dart.
24 // ProcessInfo objects are kept in the static singly-linked 25 // ProcessInfo objects are kept in the static singly-linked
25 // ProcessInfoList. 26 // ProcessInfoList.
26 class ProcessInfo { 27 class ProcessInfo {
27 public: 28 public:
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 pid_t pid; 321 pid_t pid;
321 int read_in[2]; // Pipe for stdout to child process. 322 int read_in[2]; // Pipe for stdout to child process.
322 int read_err[2]; // Pipe for stderr to child process. 323 int read_err[2]; // Pipe for stderr to child process.
323 int write_out[2]; // Pipe for stdin to child process. 324 int write_out[2]; // Pipe for stdin to child process.
324 int exec_control[2]; // Pipe to get the result from exec. 325 int exec_control[2]; // Pipe to get the result from exec.
325 int result; 326 int result;
326 327
327 bool initialized = ExitCodeHandler::EnsureInitialized(); 328 bool initialized = ExitCodeHandler::EnsureInitialized();
328 if (!initialized) { 329 if (!initialized) {
329 SetChildOsErrorMessage(os_error_message, os_error_message_len); 330 SetChildOsErrorMessage(os_error_message, os_error_message_len);
330 fprintf(stderr, 331 Log::PrintErr(
331 "Error initializing exit code handler: %s\n", 332 "Error initializing exit code handler: %s\n",
332 os_error_message); 333 os_error_message);
333 return errno; 334 return errno;
334 } 335 }
335 336
336 result = TEMP_FAILURE_RETRY(pipe(read_in)); 337 result = TEMP_FAILURE_RETRY(pipe(read_in));
337 if (result < 0) { 338 if (result < 0) {
338 SetChildOsErrorMessage(os_error_message, os_error_message_len); 339 SetChildOsErrorMessage(os_error_message, os_error_message_len);
339 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 340 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
340 return errno; 341 return errno;
341 } 342 }
342 343
343 result = TEMP_FAILURE_RETRY(pipe(read_err)); 344 result = TEMP_FAILURE_RETRY(pipe(read_err));
344 if (result < 0) { 345 if (result < 0) {
345 SetChildOsErrorMessage(os_error_message, os_error_message_len); 346 SetChildOsErrorMessage(os_error_message, os_error_message_len);
346 TEMP_FAILURE_RETRY(close(read_in[0])); 347 TEMP_FAILURE_RETRY(close(read_in[0]));
347 TEMP_FAILURE_RETRY(close(read_in[1])); 348 TEMP_FAILURE_RETRY(close(read_in[1]));
348 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 349 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
349 return errno; 350 return errno;
350 } 351 }
351 352
352 result = TEMP_FAILURE_RETRY(pipe(write_out)); 353 result = TEMP_FAILURE_RETRY(pipe(write_out));
353 if (result < 0) { 354 if (result < 0) {
354 SetChildOsErrorMessage(os_error_message, os_error_message_len); 355 SetChildOsErrorMessage(os_error_message, os_error_message_len);
355 TEMP_FAILURE_RETRY(close(read_in[0])); 356 TEMP_FAILURE_RETRY(close(read_in[0]));
356 TEMP_FAILURE_RETRY(close(read_in[1])); 357 TEMP_FAILURE_RETRY(close(read_in[1]));
357 TEMP_FAILURE_RETRY(close(read_err[0])); 358 TEMP_FAILURE_RETRY(close(read_err[0]));
358 TEMP_FAILURE_RETRY(close(read_err[1])); 359 TEMP_FAILURE_RETRY(close(read_err[1]));
359 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 360 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
360 return errno; 361 return errno;
361 } 362 }
362 363
363 result = TEMP_FAILURE_RETRY(pipe(exec_control)); 364 result = TEMP_FAILURE_RETRY(pipe(exec_control));
364 if (result < 0) { 365 if (result < 0) {
365 SetChildOsErrorMessage(os_error_message, os_error_message_len); 366 SetChildOsErrorMessage(os_error_message, os_error_message_len);
366 TEMP_FAILURE_RETRY(close(read_in[0])); 367 TEMP_FAILURE_RETRY(close(read_in[0]));
367 TEMP_FAILURE_RETRY(close(read_in[1])); 368 TEMP_FAILURE_RETRY(close(read_in[1]));
368 TEMP_FAILURE_RETRY(close(read_err[0])); 369 TEMP_FAILURE_RETRY(close(read_err[0]));
369 TEMP_FAILURE_RETRY(close(read_err[1])); 370 TEMP_FAILURE_RETRY(close(read_err[1]));
370 TEMP_FAILURE_RETRY(close(write_out[0])); 371 TEMP_FAILURE_RETRY(close(write_out[0]));
371 TEMP_FAILURE_RETRY(close(write_out[1])); 372 TEMP_FAILURE_RETRY(close(write_out[1]));
372 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 373 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
373 return errno; 374 return errno;
374 } 375 }
375 376
376 // Set close on exec on the write file descriptor of the exec control pipe. 377 // Set close on exec on the write file descriptor of the exec control pipe.
377 result = TEMP_FAILURE_RETRY( 378 result = TEMP_FAILURE_RETRY(
378 fcntl(exec_control[1], 379 fcntl(exec_control[1],
379 F_SETFD, 380 F_SETFD,
380 TEMP_FAILURE_RETRY(fcntl(exec_control[1], F_GETFD)) | FD_CLOEXEC)); 381 TEMP_FAILURE_RETRY(fcntl(exec_control[1], F_GETFD)) | FD_CLOEXEC));
381 if (result < 0) { 382 if (result < 0) {
382 SetChildOsErrorMessage(os_error_message, os_error_message_len); 383 SetChildOsErrorMessage(os_error_message, os_error_message_len);
383 TEMP_FAILURE_RETRY(close(read_in[0])); 384 TEMP_FAILURE_RETRY(close(read_in[0]));
384 TEMP_FAILURE_RETRY(close(read_in[1])); 385 TEMP_FAILURE_RETRY(close(read_in[1]));
385 TEMP_FAILURE_RETRY(close(read_err[0])); 386 TEMP_FAILURE_RETRY(close(read_err[0]));
386 TEMP_FAILURE_RETRY(close(read_err[1])); 387 TEMP_FAILURE_RETRY(close(read_err[1]));
387 TEMP_FAILURE_RETRY(close(write_out[0])); 388 TEMP_FAILURE_RETRY(close(write_out[0]));
388 TEMP_FAILURE_RETRY(close(write_out[1])); 389 TEMP_FAILURE_RETRY(close(write_out[1]));
389 TEMP_FAILURE_RETRY(close(exec_control[0])); 390 TEMP_FAILURE_RETRY(close(exec_control[0]));
390 TEMP_FAILURE_RETRY(close(exec_control[1])); 391 TEMP_FAILURE_RETRY(close(exec_control[1]));
391 fprintf(stderr, "fcntl failed: %s\n", os_error_message); 392 Log::PrintErr("fcntl failed: %s\n", os_error_message);
392 return errno; 393 return errno;
393 } 394 }
394 395
395 char** program_arguments = new char*[arguments_length + 2]; 396 char** program_arguments = new char*[arguments_length + 2];
396 program_arguments[0] = const_cast<char*>(path); 397 program_arguments[0] = const_cast<char*>(path);
397 for (int i = 0; i < arguments_length; i++) { 398 for (int i = 0; i < arguments_length; i++) {
398 program_arguments[i + 1] = arguments[i]; 399 program_arguments[i + 1] = arguments[i];
399 } 400 }
400 program_arguments[arguments_length + 1] = NULL; 401 program_arguments[arguments_length + 1] = NULL;
401 402
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 int event_fds[2]; 481 int event_fds[2];
481 result = TEMP_FAILURE_RETRY(pipe(event_fds)); 482 result = TEMP_FAILURE_RETRY(pipe(event_fds));
482 if (result < 0) { 483 if (result < 0) {
483 SetChildOsErrorMessage(os_error_message, os_error_message_len); 484 SetChildOsErrorMessage(os_error_message, os_error_message_len);
484 TEMP_FAILURE_RETRY(close(read_in[0])); 485 TEMP_FAILURE_RETRY(close(read_in[0]));
485 TEMP_FAILURE_RETRY(close(read_in[1])); 486 TEMP_FAILURE_RETRY(close(read_in[1]));
486 TEMP_FAILURE_RETRY(close(read_err[0])); 487 TEMP_FAILURE_RETRY(close(read_err[0]));
487 TEMP_FAILURE_RETRY(close(read_err[1])); 488 TEMP_FAILURE_RETRY(close(read_err[1]));
488 TEMP_FAILURE_RETRY(close(write_out[0])); 489 TEMP_FAILURE_RETRY(close(write_out[0]));
489 TEMP_FAILURE_RETRY(close(write_out[1])); 490 TEMP_FAILURE_RETRY(close(write_out[1]));
490 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 491 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
491 return errno; 492 return errno;
492 } 493 }
493 494
494 ProcessInfoList::AddProcess(pid, event_fds[1]); 495 ProcessInfoList::AddProcess(pid, event_fds[1]);
495 *exit_event = event_fds[0]; 496 *exit_event = event_fds[0];
496 FDUtils::SetNonBlocking(event_fds[0]); 497 FDUtils::SetNonBlocking(event_fds[0]);
497 498
498 // Notify child process to start. 499 // Notify child process to start.
499 char msg = '1'; 500 char msg = '1';
500 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg)); 501 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 557
557 558
558 void Process::TerminateExitCodeHandler() { 559 void Process::TerminateExitCodeHandler() {
559 ExitCodeHandler::TerminateExitCodeThread(); 560 ExitCodeHandler::TerminateExitCodeThread();
560 } 561 }
561 562
562 563
563 intptr_t Process::CurrentProcessId() { 564 intptr_t Process::CurrentProcessId() {
564 return static_cast<intptr_t>(getpid()); 565 return static_cast<intptr_t>(getpid());
565 } 566 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698