| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/posix/global_descriptors.h" |
| 5 #include "base/test/multiprocess_test.h" | 6 #include "base/test/multiprocess_test.h" |
| 6 | 7 |
| 7 #include <unistd.h> | 8 #include <unistd.h> |
| 8 | 9 |
| 9 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "testing/multiprocess_func_list.h" | 12 #include "testing/multiprocess_func_list.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 35 if (pid > 0) { | 36 if (pid > 0) { |
| 36 // Parent process. | 37 // Parent process. |
| 37 return pid; | 38 return pid; |
| 38 } | 39 } |
| 39 // Child process. | 40 // Child process. |
| 40 std::hash_set<int> fds_to_keep_open; | 41 std::hash_set<int> fds_to_keep_open; |
| 41 for (FileHandleMappingVector::const_iterator it = fds_to_remap->begin(); | 42 for (FileHandleMappingVector::const_iterator it = fds_to_remap->begin(); |
| 42 it != fds_to_remap->end(); ++it) { | 43 it != fds_to_remap->end(); ++it) { |
| 43 fds_to_keep_open.insert(it->first); | 44 fds_to_keep_open.insert(it->first); |
| 44 } | 45 } |
| 45 // Keep stdin, stdout and stderr open since this is not meant to spawn a | 46 // Keep standard FDs (stdin, stdout, stderr, etc.) open since this |
| 46 // daemon. | 47 // is not meant to spawn a daemon. |
| 47 const int kFdForAndroidLogging = 3; // FD used by __android_log_write(). | 48 int base = GlobalDescriptors::kBaseDescriptor; |
| 48 for (int fd = kFdForAndroidLogging + 1; fd < getdtablesize(); ++fd) { | 49 for (int fd = base; fd < getdtablesize(); ++fd) { |
| 49 if (fds_to_keep_open.find(fd) == fds_to_keep_open.end()) { | 50 if (fds_to_keep_open.find(fd) == fds_to_keep_open.end()) { |
| 50 close(fd); | 51 close(fd); |
| 51 } | 52 } |
| 52 } | 53 } |
| 53 for (FileHandleMappingVector::const_iterator it = fds_to_remap->begin(); | 54 for (FileHandleMappingVector::const_iterator it = fds_to_remap->begin(); |
| 54 it != fds_to_remap->end(); ++it) { | 55 it != fds_to_remap->end(); ++it) { |
| 55 int old_fd = it->first; | 56 int old_fd = it->first; |
| 56 int new_fd = it->second; | 57 int new_fd = it->second; |
| 57 if (dup2(old_fd, new_fd) < 0) { | 58 if (dup2(old_fd, new_fd) < 0) { |
| 58 PLOG(FATAL) << "dup2"; | 59 PLOG(FATAL) << "dup2"; |
| 59 } | 60 } |
| 60 close(old_fd); | 61 close(old_fd); |
| 61 } | 62 } |
| 62 _exit(multi_process_function_list::InvokeChildProcessTest(procname)); | 63 _exit(multi_process_function_list::InvokeChildProcessTest(procname)); |
| 63 return 0; | 64 return 0; |
| 64 } | 65 } |
| 65 | 66 |
| 66 } // namespace base | 67 } // namespace base |
| OLD | NEW |