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

Side by Side Diff: runtime/bin/process_macos.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 <unistd.h> 14 #include <unistd.h>
15 15
16 #include "bin/fdutils.h" 16 #include "bin/fdutils.h"
17 #include "bin/log.h"
17 #include "bin/thread.h" 18 #include "bin/thread.h"
18 19
19 extern char **environ; 20 extern char **environ;
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:
(...skipping 292 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 int event_fds[2]; 479 int event_fds[2];
480 result = TEMP_FAILURE_RETRY(pipe(event_fds)); 480 result = TEMP_FAILURE_RETRY(pipe(event_fds));
481 if (result < 0) { 481 if (result < 0) {
482 SetChildOsErrorMessage(os_error_message, os_error_message_len); 482 SetChildOsErrorMessage(os_error_message, os_error_message_len);
483 TEMP_FAILURE_RETRY(close(read_in[0])); 483 TEMP_FAILURE_RETRY(close(read_in[0]));
484 TEMP_FAILURE_RETRY(close(read_in[1])); 484 TEMP_FAILURE_RETRY(close(read_in[1]));
485 TEMP_FAILURE_RETRY(close(read_err[0])); 485 TEMP_FAILURE_RETRY(close(read_err[0]));
486 TEMP_FAILURE_RETRY(close(read_err[1])); 486 TEMP_FAILURE_RETRY(close(read_err[1]));
487 TEMP_FAILURE_RETRY(close(write_out[0])); 487 TEMP_FAILURE_RETRY(close(write_out[0]));
488 TEMP_FAILURE_RETRY(close(write_out[1])); 488 TEMP_FAILURE_RETRY(close(write_out[1]));
489 fprintf(stderr, "Error pipe creation failed: %s\n", os_error_message); 489 Log::PrintErr("Error pipe creation failed: %s\n", os_error_message);
490 return errno; 490 return errno;
491 } 491 }
492 492
493 ProcessInfoList::AddProcess(pid, event_fds[1]); 493 ProcessInfoList::AddProcess(pid, event_fds[1]);
494 *exit_event = event_fds[0]; 494 *exit_event = event_fds[0];
495 FDUtils::SetNonBlocking(event_fds[0]); 495 FDUtils::SetNonBlocking(event_fds[0]);
496 496
497 // Notify child process to start. 497 // Notify child process to start.
498 char msg = '1'; 498 char msg = '1';
499 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg)); 499 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 555
556 556
557 void Process::TerminateExitCodeHandler() { 557 void Process::TerminateExitCodeHandler() {
558 ExitCodeHandler::TerminateExitCodeThread(); 558 ExitCodeHandler::TerminateExitCodeThread();
559 } 559 }
560 560
561 561
562 intptr_t Process::CurrentProcessId() { 562 intptr_t Process::CurrentProcessId() {
563 return static_cast<intptr_t>(getpid()); 563 return static_cast<intptr_t>(getpid());
564 } 564 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698