-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid crashes on macOS by exec(2) after daemonize
We can encounter the following error if we continue without re-exec(2)-ing: objc[11602]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug. In Mairu's case, most these crashes are triggered in a copy_certificates_from_keychain dispatch queue thread. This is likely relevant to security-framework crate which utilise Security.framework for TLS functionality, and appears to be difficult to avoid; unforeseen risks remain ahead that could cause similar issues. We're avoiding by re-exec(2)-ing itself to prevent the issue at all. See also: https://www.sealiesoftware.com/blog/archive/2017/6/5/Objective-C_and_fork_in_macOS_1013.html
- Loading branch information
Showing
4 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pub(crate) fn set_cloexec<T>(fd: &T, value: bool) -> crate::Result<()> | ||
where | ||
T: std::os::fd::AsRawFd, | ||
{ | ||
use nix::fcntl::{fcntl, FdFlag, F_GETFD, F_SETFD}; | ||
let mut fdopts = FdFlag::from_bits(fcntl(fd.as_raw_fd(), F_GETFD)?).unwrap(); | ||
fdopts.set(FdFlag::FD_CLOEXEC, value); | ||
fcntl(fd.as_raw_fd(), F_SETFD(fdopts))?; | ||
Ok(()) | ||
} |