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

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

Issue 11644017: Set close-on-exec flag on pipe() and epoll() file descriptors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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_android.cc ('k') | no next file » | 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 #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>
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if (initialized_) { 118 if (initialized_) {
119 return true; 119 return true;
120 } 120 }
121 121
122 // Allocate a pipe that the signal handler can write a byte to and 122 // Allocate a pipe that the signal handler can write a byte to and
123 // that the exit handler thread can poll. 123 // that the exit handler thread can poll.
124 int result = TEMP_FAILURE_RETRY(pipe(sig_chld_fds_)); 124 int result = TEMP_FAILURE_RETRY(pipe(sig_chld_fds_));
125 if (result < 0) { 125 if (result < 0) {
126 return false; 126 return false;
127 } 127 }
128 FDUtils::SetCloseOnExec(sig_chld_fds_[0]);
129 FDUtils::SetCloseOnExec(sig_chld_fds_[1]);
128 130
129 // Start thread that polls the pipe and handles process exits when 131 // Start thread that polls the pipe and handles process exits when
130 // data is received on the pipe. 132 // data is received on the pipe.
131 result = dart::Thread::Start(ExitCodeHandlerEntry, sig_chld_fds_[0]); 133 result = dart::Thread::Start(ExitCodeHandlerEntry, sig_chld_fds_[0]);
132 if (result != 0) { 134 if (result != 0) {
133 FATAL1("Failed to start exit code handler worker thread %d", result); 135 FATAL1("Failed to start exit code handler worker thread %d", result);
134 } 136 }
135 137
136 // Mark write end non-blocking. 138 // Mark write end non-blocking.
137 FDUtils::SetNonBlocking(sig_chld_fds_[1]); 139 FDUtils::SetNonBlocking(sig_chld_fds_[1]);
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 SetChildOsErrorMessage(os_error_message); 477 SetChildOsErrorMessage(os_error_message);
476 TEMP_FAILURE_RETRY(close(read_in[0])); 478 TEMP_FAILURE_RETRY(close(read_in[0]));
477 TEMP_FAILURE_RETRY(close(read_in[1])); 479 TEMP_FAILURE_RETRY(close(read_in[1]));
478 TEMP_FAILURE_RETRY(close(read_err[0])); 480 TEMP_FAILURE_RETRY(close(read_err[0]));
479 TEMP_FAILURE_RETRY(close(read_err[1])); 481 TEMP_FAILURE_RETRY(close(read_err[1]));
480 TEMP_FAILURE_RETRY(close(write_out[0])); 482 TEMP_FAILURE_RETRY(close(write_out[0]));
481 TEMP_FAILURE_RETRY(close(write_out[1])); 483 TEMP_FAILURE_RETRY(close(write_out[1]));
482 Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message); 484 Log::PrintErr("Error pipe creation failed: %s\n", *os_error_message);
483 return errno; 485 return errno;
484 } 486 }
487 FDUtils::SetCloseOnExec(event_fds[0]);
488 FDUtils::SetCloseOnExec(event_fds[1]);
485 489
486 ProcessInfoList::AddProcess(pid, event_fds[1]); 490 ProcessInfoList::AddProcess(pid, event_fds[1]);
487 *exit_event = event_fds[0]; 491 *exit_event = event_fds[0];
488 FDUtils::SetNonBlocking(event_fds[0]); 492 FDUtils::SetNonBlocking(event_fds[0]);
489 493
490 // Notify child process to start. 494 // Notify child process to start.
491 char msg = '1'; 495 char msg = '1';
492 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg)); 496 result = FDUtils::WriteToBlocking(read_in[1], &msg, sizeof(msg));
493 if (result != sizeof(msg)) { 497 if (result != sizeof(msg)) {
494 perror("Failed sending notification message"); 498 perror("Failed sending notification message");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 555
552 556
553 void Process::TerminateExitCodeHandler() { 557 void Process::TerminateExitCodeHandler() {
554 ExitCodeHandler::TerminateExitCodeThread(); 558 ExitCodeHandler::TerminateExitCodeThread();
555 } 559 }
556 560
557 561
558 intptr_t Process::CurrentProcessId() { 562 intptr_t Process::CurrentProcessId() {
559 return static_cast<intptr_t>(getpid()); 563 return static_cast<intptr_t>(getpid());
560 } 564 }
OLDNEW
« no previous file with comments | « runtime/bin/process_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698