| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/mac/relauncher.h" | 5 #include "chrome/browser/mac/relauncher.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include <AvailabilityMacros.h> | 9 #include <AvailabilityMacros.h> |
| 10 #include <crt_externs.h> | 10 #include <crt_externs.h> |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 int pipe_fds[2]; | 123 int pipe_fds[2]; |
| 124 if (HANDLE_EINTR(pipe(pipe_fds)) != 0) { | 124 if (HANDLE_EINTR(pipe(pipe_fds)) != 0) { |
| 125 PLOG(ERROR) << "pipe"; | 125 PLOG(ERROR) << "pipe"; |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // The parent process will only use pipe_read_fd as the read side of the | 129 // The parent process will only use pipe_read_fd as the read side of the |
| 130 // pipe. It can close the write side as soon as the relauncher process has | 130 // pipe. It can close the write side as soon as the relauncher process has |
| 131 // forked off. The relauncher process will only use pipe_write_fd as the | 131 // forked off. The relauncher process will only use pipe_write_fd as the |
| 132 // write side of the pipe. In that process, the read side will be closed by | 132 // write side of the pipe. In that process, the read side will be closed by |
| 133 // base::LaunchApp because it won't be present in fd_map, and the write side | 133 // base::LaunchApp because it won't be present in fds_to_remap, and the write |
| 134 // will be remapped to kRelauncherSyncFD by fd_map. | 134 // side will be remapped to kRelauncherSyncFD by fds_to_remap. |
| 135 base::ScopedFD pipe_read_fd(pipe_fds[0]); | 135 base::ScopedFD pipe_read_fd(pipe_fds[0]); |
| 136 base::ScopedFD pipe_write_fd(pipe_fds[1]); | 136 base::ScopedFD pipe_write_fd(pipe_fds[1]); |
| 137 | 137 |
| 138 // Make sure kRelauncherSyncFD is a safe value. base::LaunchProcess will | 138 // Make sure kRelauncherSyncFD is a safe value. base::LaunchProcess will |
| 139 // preserve these three FDs in forked processes, so kRelauncherSyncFD should | 139 // preserve these three FDs in forked processes, so kRelauncherSyncFD should |
| 140 // not conflict with them. | 140 // not conflict with them. |
| 141 static_assert(kRelauncherSyncFD != STDIN_FILENO && | 141 static_assert(kRelauncherSyncFD != STDIN_FILENO && |
| 142 kRelauncherSyncFD != STDOUT_FILENO && | 142 kRelauncherSyncFD != STDOUT_FILENO && |
| 143 kRelauncherSyncFD != STDERR_FILENO, | 143 kRelauncherSyncFD != STDERR_FILENO, |
| 144 "kRelauncherSyncFD must not conflict with stdio fds"); | 144 "kRelauncherSyncFD must not conflict with stdio fds"); |
| 145 | 145 |
| 146 base::FileHandleMappingVector fd_map; | |
| 147 fd_map.push_back(std::make_pair(pipe_write_fd.get(), kRelauncherSyncFD)); | |
| 148 | |
| 149 base::LaunchOptions options; | 146 base::LaunchOptions options; |
| 150 options.fds_to_remap = &fd_map; | 147 options.fds_to_remap.push_back( |
| 148 std::make_pair(pipe_write_fd.get(), kRelauncherSyncFD)); |
| 151 if (!base::LaunchProcess(relaunch_args, options).IsValid()) { | 149 if (!base::LaunchProcess(relaunch_args, options).IsValid()) { |
| 152 LOG(ERROR) << "base::LaunchProcess failed"; | 150 LOG(ERROR) << "base::LaunchProcess failed"; |
| 153 return false; | 151 return false; |
| 154 } | 152 } |
| 155 | 153 |
| 156 // The relauncher process is now starting up, or has started up. The | 154 // The relauncher process is now starting up, or has started up. The |
| 157 // original parent process continues. | 155 // original parent process continues. |
| 158 | 156 |
| 159 pipe_write_fd.reset(); // close(pipe_fds[1]); | 157 pipe_write_fd.reset(); // close(pipe_fds[1]); |
| 160 | 158 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 if (!dmg_bsd_device_name.empty()) { | 365 if (!dmg_bsd_device_name.empty()) { |
| 368 EjectAndTrashDiskImage(dmg_bsd_device_name); | 366 EjectAndTrashDiskImage(dmg_bsd_device_name); |
| 369 } | 367 } |
| 370 | 368 |
| 371 return 0; | 369 return 0; |
| 372 } | 370 } |
| 373 | 371 |
| 374 } // namespace internal | 372 } // namespace internal |
| 375 | 373 |
| 376 } // namespace mac_relauncher | 374 } // namespace mac_relauncher |
| OLD | NEW |