init: Fix boot stuck caused by driver exiting
This commit is contained in:
+6
-5
@@ -1,7 +1,7 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::ffi::OsString;
|
||||
use std::io::Read;
|
||||
use std::os::fd::{AsRawFd, OwnedFd};
|
||||
use std::os::fd::{AsRawFd, RawFd};
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::Command;
|
||||
use std::{env, io};
|
||||
@@ -47,7 +47,7 @@ impl Service {
|
||||
command.envs(base_envs).envs(&self.envs);
|
||||
|
||||
let (mut read_pipe, write_pipe) = io::pipe().unwrap();
|
||||
unsafe { pass_fd(&mut command, "INIT_NOTIFY", write_pipe.into()) };
|
||||
unsafe { pass_fd(&mut command, "INIT_NOTIFY", write_pipe.as_raw_fd()) };
|
||||
|
||||
let mut child = match command.spawn() {
|
||||
Ok(child) => child,
|
||||
@@ -56,6 +56,7 @@ impl Service {
|
||||
return;
|
||||
}
|
||||
};
|
||||
drop(write_pipe);
|
||||
|
||||
match &self.type_ {
|
||||
ServiceType::Notify => match read_pipe.read_exact(&mut [0]) {
|
||||
@@ -117,12 +118,12 @@ impl Service {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn pass_fd(cmd: &mut Command, env: &str, fd: OwnedFd) {
|
||||
cmd.env(env, format!("{}", fd.as_raw_fd()));
|
||||
unsafe fn pass_fd(cmd: &mut Command, env: &str, fd: RawFd) {
|
||||
cmd.env(env, format!("{}", fd));
|
||||
unsafe {
|
||||
cmd.pre_exec(move || {
|
||||
// Pass notify pipe to child
|
||||
if libc::fcntl(fd.as_raw_fd(), libc::F_SETFD, 0) == -1 {
|
||||
if libc::fcntl(fd, libc::F_SETFD, 0) == -1 {
|
||||
Err(io::Error::last_os_error())
|
||||
} else {
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user