| 396 | |
| 397 | # if defined(DEATH_TARGET_UNIX) |
| 398 | static bool RedirectFileDescriptorToNull(std::int32_t fd) |
| 399 | { |
| 400 | if (fd < 0) { |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | std::int32_t tempfd; |
| 405 | do { |
| 406 | tempfd = ::open("/dev/null", O_RDWR | O_NOCTTY); |
| 407 | } while (tempfd == -1 && errno == EINTR); |
| 408 | |
| 409 | if (tempfd == -1) { |
| 410 | return false; |
| 411 | } |
| 412 | |
| 413 | if (tempfd != fd) { |
| 414 | if (::dup2(tempfd, fd) == -1) { |
| 415 | ::close(tempfd); |
| 416 | return false; |
| 417 | } |
| 418 | if (::close(tempfd) == -1) { |
| 419 | return false; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | return true; |
| 424 | } |
| 425 | |
| 426 | static void TryCloseAllFileDescriptors() |
| 427 | { |
no outgoing calls
no test coverage detected