mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Remove deprecated libc::daemon call
Since version 10.5 of macOS the libc::daemon call has been deprecated. While it is recommended by macOS to use launchd instead, this is not easily available on other unix platforms. However since we just spawn a daemon process to prevent Alacritty from spawning zombies, we can manually invoke `fork` in the child process to cause a double-fork and re-parent the child process under init so it can be reaped automatically. Since the daemon call is not part of POSIX, using the double fork on all unix platforms also has some portability advantages.
This commit is contained in:
parent
c6ab2a8867
commit
32cb48774a
1 changed files with 7 additions and 3 deletions
10
src/util.rs
10
src/util.rs
|
@ -15,6 +15,7 @@
|
||||||
use std::{cmp, io};
|
use std::{cmp, io};
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use std::process::Stdio;
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
|
@ -22,8 +23,6 @@ use std::os::unix::process::CommandExt;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::os::windows::process::CommandExt;
|
use std::os::windows::process::CommandExt;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::process::Stdio;
|
|
||||||
#[cfg(windows)]
|
|
||||||
use winapi::um::winbase::{CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW};
|
use winapi::um::winbase::{CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW};
|
||||||
|
|
||||||
/// Threading utilities
|
/// Threading utilities
|
||||||
|
@ -94,8 +93,13 @@ pub fn start_daemon<I, S>(program: &str, args: I) -> io::Result<()>
|
||||||
{
|
{
|
||||||
Command::new(program)
|
Command::new(program)
|
||||||
.args(args)
|
.args(args)
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
.before_exec(|| unsafe {
|
.before_exec(|| unsafe {
|
||||||
::libc::daemon(1, 0);
|
if ::libc::fork() != 0 {
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.spawn()?
|
.spawn()?
|
||||||
|
|
Loading…
Reference in a new issue