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 }; let timeout = if block { -1 } else { 0 };
libc::poll(&mut pfd, 1, timeout); libc::poll(&mut pfd, 1, timeout);
if pfd.revents != 0 && pfd.revents & libc::POLLIN == 0 { if pfd.revents & !libc::POLLIN != 0 {
return false; return false;
} }
} }

View File

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