nix::unistd::daemon will kill all other threads
Because libc's daemon() forks and then exits in the parent, only the thread that calls daemon() will survive in the child. Usually this means that one would only want to call daemon() from a single-threaded process. I am not certain whether it makes nix::unistd::daemon unsafe, but it seems like noting it in some way in the documentation would be a good idea.
That's an excellent question. I myself have marked a function as unsafe for doing the same thing: https://docs.rs/capsicum/latest/capsicum/casper/struct.Casper.html#method.new . But it's not totally clear to me that that's correct. You might consider starting a thread on the Rust forums to discuss whether such functions ought to be considered unsafe.
This issue indicates that forking a multithreaded process was considered unsafe enough that before_exec was marked unsafe and deprecated and replaced by pre_exec. So it seems to me that, by the same logic, daemon is unsafe.
Good find. Would you care to submit a patch?
Good find. Would you care to submit a patch?
Done, see https://github.com/nix-rust/nix/pull/2664.
It was counterintuitive having to add a changelog file with the PR number in the name, since I couldn't get the PR number before I submitted the PR, but I dealt with that by submitting it and then force-pushing afterward.