| 153 | } |
| 154 | |
| 155 | void FileDescriptorInfo::Detach(fail_fn_t fail_fn) const { |
| 156 | const int dev_null_fd = TEMP_FAILURE_RETRY(open("/dev/null", O_RDWR | O_CLOEXEC)); |
| 157 | if (dev_null_fd < 0) { |
| 158 | fail_fn(android::base::StringPrintf("Failed to open /dev/null: %s", strerror(errno))); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | if (TEMP_FAILURE_RETRY(dup3(dev_null_fd, fd, O_CLOEXEC)) == -1) { |
| 163 | fail_fn(android::base::StringPrintf("Failed dup3 on descriptor %d to /dev/null: %s", |
| 164 | fd, |
| 165 | strerror(errno))); |
| 166 | // close(dev_null_fd) should still be attempted |
| 167 | } |
| 168 | |
| 169 | if (TEMP_FAILURE_RETRY(close(dev_null_fd)) == -1) { |
| 170 | fail_fn(android::base::StringPrintf("Failed close(/dev/null temp fd %d): %s", dev_null_fd, strerror(errno))); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void FileDescriptorInfo::ReopenOrDetach(fail_fn_t fail_fn, bool prefer_detach_to_dev_null) const { |
| 175 | if (is_sock) { |
nothing calls this directly
no test coverage detected