mirror of
https://github.com/joleuger/vuinputd.git
synced 2026-07-17 16:36:03 +00:00
Fix bwrap-ipc test.
This commit is contained in:
parent
ad6a4cc696
commit
1683829780
3 changed files with 22 additions and 8 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use core::panic;
|
||||
use std::{str::from_utf8_unchecked, time::Duration};
|
||||
use std::{time::Duration};
|
||||
|
||||
use vuinputd_tests::bwrap::SandboxChildIpc;
|
||||
|
||||
|
|
@ -13,9 +13,11 @@ fn main() {
|
|||
let incoming_str =
|
||||
str::from_utf8(&incoming).expect("message received from ipc is not encoded as utf8");
|
||||
if incoming_str == "continue" {
|
||||
println!("child received continue");
|
||||
ipc.send(b"ok").unwrap();
|
||||
} else {
|
||||
ipc.send(b"nok").unwrap();
|
||||
println!("child received {}",incoming_str);
|
||||
panic!("expected ipc message to be 'continue'");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
// Author: Johannes Leupolz <dev@leupolz.eu>
|
||||
|
||||
use std::io;
|
||||
use std::os::fd::{FromRawFd, IntoRawFd, RawFd};
|
||||
use std::os::fd::{FromRawFd, IntoRawFd, OwnedFd, RawFd};
|
||||
use std::os::unix::net::UnixDatagram;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::process::{Command, Output};
|
||||
|
|
@ -76,7 +76,7 @@ impl SandboxChildIpc {
|
|||
#[derive(Default)]
|
||||
pub struct BwrapBuilder {
|
||||
args: Vec<String>,
|
||||
ipc_child_fd: Option<RawFd>,
|
||||
ipc_child_fd: Option<OwnedFd>,
|
||||
}
|
||||
|
||||
impl BwrapBuilder {
|
||||
|
|
@ -141,7 +141,7 @@ impl BwrapBuilder {
|
|||
let parent_sock = unsafe { UnixDatagram::from_raw_fd(parent.into_raw_fd()) };
|
||||
|
||||
// Child side must become FD 3 inside container
|
||||
self.ipc_child_fd = Some(child.into_raw_fd());
|
||||
self.ipc_child_fd = Some(child);
|
||||
|
||||
Ok((self, SandboxIpc { sock: parent_sock }))
|
||||
}
|
||||
|
|
@ -158,7 +158,11 @@ impl BwrapBuilder {
|
|||
|
||||
let mut cmd = Command::new("bwrap");
|
||||
|
||||
|
||||
if let Some(fd) = self.ipc_child_fd.take() {
|
||||
// give up ownership of ipc_child_fd in host process.
|
||||
let fd = fd.into_raw_fd();
|
||||
|
||||
// Move child FD to 3. Note that the FD 3 needs to be linked at the
|
||||
// beginning of the child program.
|
||||
unsafe {
|
||||
|
|
|
|||
|
|
@ -36,19 +36,27 @@ fn test_bwrap_ipc() {
|
|||
.with_ipc()
|
||||
.expect("failed to create IPC");
|
||||
|
||||
// Note that builder.run() will block. Thus, the send needs to happen before the child process blocks
|
||||
// the host process.
|
||||
ipc.send("continue".as_bytes())
|
||||
.unwrap_or_else(|e| panic!("failed to send data via ipc: {e}"));
|
||||
|
||||
let out = builder
|
||||
.command(bwrap_ipc)
|
||||
.run()
|
||||
.unwrap_or_else(|e| panic!("failed to run bwrap!: {e}"));
|
||||
ipc.send("continue".as_bytes())
|
||||
.unwrap_or_else(|e| panic!("failed to send data via ipc: {e}"));
|
||||
|
||||
ipc.recv(Some(Duration::from_secs(5)))
|
||||
.expect("error receiving input from ipc as host within 5 seconds");
|
||||
let result = ipc.recv(Some(Duration::from_secs(5)));
|
||||
|
||||
println!("Output");
|
||||
println!("stdout: {}", str::from_utf8(&out.stdout).unwrap());
|
||||
println!("stderr: {}", str::from_utf8(&out.stderr).unwrap());
|
||||
|
||||
let result = result.expect("error receiving input from ipc as host within 5 seconds");
|
||||
let result_str =
|
||||
str::from_utf8(&result).expect("message received from ipc is not encoded as utf8");
|
||||
println!("host received {}",result_str);
|
||||
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "requires-root", feature = "requires-uinput"))]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue