fix check_unix_socket

This commit is contained in:
5ec1cff
2023-12-08 19:47:06 +08:00
parent b34015b5f0
commit 0254623166
2 changed files with 3 additions and 10 deletions

View File

@@ -204,7 +204,7 @@ pub fn check_unix_socket(stream: &UnixStream, block: bool) -> bool {
};
let timeout = if block { -1 } else { 0 };
libc::poll(&mut pfd, 1, timeout);
if pfd.revents != 0 && pfd.revents & libc::POLLIN == 0 {
if pfd.revents & !libc::POLLIN != 0 {
return false;
}
}

View File

@@ -35,19 +35,13 @@ pub fn main() -> Result<()> {
let arch = get_arch()?;
log::debug!("Daemon architecture: {arch}");
log::info!("Load modules");
let modules = load_modules(arch)?;
let context = Context {
modules,
};
let context = Arc::new(context);
log::info!("Create socket");
let listener = create_daemon_socket()?;
log::info!("Handle zygote connections");
for stream in listener.incoming() {
let mut stream = stream?;
let context = Arc::clone(&context);
@@ -259,8 +253,8 @@ fn handle_daemon_action(action: DaemonSocketAction, mut stream: UnixStream, cont
}
match companion.as_ref() {
Some(Some(sock)) => {
if let Err(_) = sock.send_fd(stream.as_raw_fd()) {
log::error!("Failed to send companion fd socket of module `{}`", module.name);
if let Err(e) = sock.send_fd(stream.as_raw_fd()) {
log::error!("Failed to send companion fd socket of module `{}`: {}", module.name, e);
stream.write_u8(0)?;
}
// Ok: Send by companion
@@ -269,7 +263,6 @@ fn handle_daemon_action(action: DaemonSocketAction, mut stream: UnixStream, cont
stream.write_u8(0)?;
}
}
log::info!("companion done");
}
DaemonSocketAction::GetModuleDir => {
let index = stream.read_usize()?;