From 8c8e8d774163e5c258209136666f841cefeb6d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Thu, 12 Dec 2024 15:22:37 +0100 Subject: [PATCH 1/2] Fixed podman call dead lock When calling the flake and stdout/stderr gets redirected into a pipe like `flake | grep ... | cut ...` the pilot binary runs in a dead lock because there is no reader/writer to feed the pipe from the child process (podman) executed via the pilot. This commit fixes it by making sure all data from the child gets read first and then passed along to stdout/stderr of the caller. --- podman-pilot/src/podman.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/podman-pilot/src/podman.rs b/podman-pilot/src/podman.rs index 6e79898..0ace497 100644 --- a/podman-pilot/src/podman.rs +++ b/podman-pilot/src/podman.rs @@ -33,6 +33,7 @@ use flakes::command::{CommandError, CommandExtTrait}; use flakes::container::Container; use flakes::config::get_podman_ids_dir; +use std::io; use std::path::Path; use std::process::{Command, Output, Stdio}; use std::env; @@ -478,7 +479,8 @@ pub fn call_instance( let RuntimeSection { resume, .. } = config().runtime(); let mut call = user.run("podman"); - if action == "rm_force" { + if action == "rm" || action == "rm_force" { + call.stdout(Stdio::null()); call.arg("rm").arg("--force"); } else { call.arg(action); @@ -508,19 +510,16 @@ pub fn call_instance( if Lookup::is_debug() { debug!("{:?}", call.get_args()); } - if action == "rm" || action == "rm_force" { - match call.perform() { - Ok(output) => { - output - } - Err(_) => { - let _ = Container::podman_setup_permissions(); - call.perform()? - } - }; - } else { - call.status()?; - } + match call.output() { + Ok(output) => { + let _ = io::stdout().write_all(&output.stdout); + let _ = io::stderr().write_all(&output.stderr); + }, + Err(_) => { + let _ = Container::podman_setup_permissions(); + call.output()?; + } + }; Ok(()) } From 651dfd4325cba73b5bf5045372a465ed4ec8854c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Thu, 12 Dec 2024 15:39:51 +0100 Subject: [PATCH 2/2] Make sure interactive processes can run --- doc/podman-pilot.rst | 4 ++++ podman-pilot/src/podman.rs | 30 ++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/doc/podman-pilot.rst b/doc/podman-pilot.rst index e4cf7b4..de82631 100644 --- a/doc/podman-pilot.rst +++ b/doc/podman-pilot.rst @@ -148,6 +148,10 @@ OPTIONS even if there are files missing. This can lead to a non functional instance of course, you have been warned. +%interactive + + Use when running interactive processes like a shell + DEBUGGING --------- diff --git a/podman-pilot/src/podman.rs b/podman-pilot/src/podman.rs index 0ace497..8a7ddf9 100644 --- a/podman-pilot/src/podman.rs +++ b/podman-pilot/src/podman.rs @@ -478,6 +478,12 @@ pub fn call_instance( let RuntimeSection { resume, .. } = config().runtime(); + let pilot_options = Lookup::get_pilot_run_options(); + let mut interactive = false; + if pilot_options.contains_key("%interactive") { + interactive = true; + } + let mut call = user.run("podman"); if action == "rm" || action == "rm_force" { call.stdout(Stdio::null()); @@ -510,16 +516,20 @@ pub fn call_instance( if Lookup::is_debug() { debug!("{:?}", call.get_args()); } - match call.output() { - Ok(output) => { - let _ = io::stdout().write_all(&output.stdout); - let _ = io::stderr().write_all(&output.stderr); - }, - Err(_) => { - let _ = Container::podman_setup_permissions(); - call.output()?; - } - }; + if interactive { + call.status()?; + } else { + match call.output() { + Ok(output) => { + let _ = io::stdout().write_all(&output.stdout); + let _ = io::stderr().write_all(&output.stderr); + }, + Err(_) => { + let _ = Container::podman_setup_permissions(); + call.output()?; + } + }; + } Ok(()) }