Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_command: wait for command to run indefinitely #59

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,16 @@ impl Qemu {
let _ = updates.send(Output::Command(line));
};

// Set read timeout to None so we can block indefinitely in case the VM
// is having a hard time, like being overloaded. See #40.
// But reset it back to the old value when we're done.
let old_timeout = qga.read_timeout()?;
scopeguard::defer! {
// Restore old timeout
let _ = qga.set_read_timeout(old_timeout);
}
qga.set_read_timeout(None)?;

let output_stream = connect_to_uds(&self.command_sock)
.context("Failed to connect to command output socket")?;

Expand Down
15 changes: 15 additions & 0 deletions src/qga.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ impl QgaWrapper {
bail!("Timed out waiting for QGA connection");
}

/// Set the read timeout of the inner UnixStream.
///
/// If the provided value is [`None`], then [`read`] calls will block
/// indefinitely. An [`Err`] is returned if the zero [`Duration`] is passed to this
/// method.
pub fn set_read_timeout(&self, timeout: Option<Duration>) -> Result<()> {
self.stream.set_read_timeout(timeout)?;
Ok(())
}

/// Returns the read timeout of the inner UnixStream.
pub fn read_timeout(&self) -> Result<Option<Duration>> {
Ok(self.stream.read_timeout()?)
}

/// Run a command inside the guest
pub fn guest_exec(
&self,
Expand Down
Loading