From ad44b85c977a6a93729c63a7b2e0117a22994a73 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Fri, 25 Nov 2022 08:02:00 -0800 Subject: [PATCH] Use process groups with tokio (also crate bump) (#63) * Use process groups with tokio (also flake/crate bump) * Use pgid0 * Maybe this checkout has a non-broken curl on mac * Don't update flake at all --- .cargo/config.toml | 2 +- .gitignore | 3 +- Cargo.lock | 68 +++++++++---------- Cargo.toml | 4 +- flake.nix | 2 +- .../base/configure_nix_daemon_service.rs | 22 +++--- src/action/base/create_group.rs | 13 ++-- src/action/base/create_user.rs | 11 +++ src/action/base/setup_default_profile.rs | 2 + src/action/darwin/bootstrap_volume.rs | 3 + src/action/darwin/create_synthetic_objects.rs | 4 ++ src/action/darwin/create_volume.rs | 2 + src/action/darwin/enable_ownership.rs | 2 + src/action/darwin/encrypt_volume.rs | 7 +- .../darwin/kickstart_launchctl_service.rs | 1 + src/action/darwin/unmount_volume.rs | 2 + src/action/linux/start_systemd_unit.rs | 4 +- src/action/linux/systemd_sysext_merge.rs | 2 + src/lib.rs | 2 - 19 files changed, 95 insertions(+), 61 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index c252d7f..0da0a84 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [build] -rustflags=["--cfg", "tracing_unstable"] \ No newline at end of file +rustflags=["--cfg", "tracing_unstable", "--cfg", "tokio_unstable"] \ No newline at end of file diff --git a/.gitignore b/.gitignore index e2a5842..ae1d7ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -.ci-store \ No newline at end of file +.ci-store +.direnv \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 0921f08..698b536 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -241,9 +241,9 @@ dependencies = [ [[package]] name = "bytes" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "cache-padded" @@ -253,9 +253,9 @@ checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" [[package]] name = "cc" -version = "1.0.76" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" [[package]] name = "cfg-if" @@ -376,9 +376,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "crossbeam-utils" -version = "0.8.12" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ "cfg-if", ] @@ -421,9 +421,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888" +checksum = "d4a41a86530d0fe7f5d9ea779916b7cadd2d4f9add748b99c2c029cbbdfaf453" dependencies = [ "cc", "cxxbridge-flags", @@ -433,9 +433,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3" +checksum = "06416d667ff3e3ad2df1cd8cd8afae5da26cf9cec4d0825040f88b5ca659a2f0" dependencies = [ "cc", "codespan-reporting", @@ -448,15 +448,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f" +checksum = "820a9a2af1669deeef27cb271f476ffd196a2c4b6731336011e0ba63e2c7cf71" [[package]] name = "cxxbridge-macro" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" +checksum = "a08a6e2fcc370a089ad3b4aaf54db3b1b4cee38ddabce5896b33eb693275f470" dependencies = [ "proc-macro2", "quote", @@ -762,7 +762,7 @@ version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" dependencies = [ - "bytes 1.2.1", + "bytes 1.3.0", "fnv", "futures-core", "futures-sink", @@ -782,7 +782,7 @@ dependencies = [ "async-tar", "async-trait", "atty", - "bytes 1.2.1", + "bytes 1.3.0", "clap", "color-eyre", "crossterm", @@ -851,7 +851,7 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ - "bytes 1.2.1", + "bytes 1.3.0", "fnv", "itoa", ] @@ -862,7 +862,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ - "bytes 1.2.1", + "bytes 1.3.0", "http", "pin-project-lite", ] @@ -885,7 +885,7 @@ version = "0.14.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" dependencies = [ - "bytes 1.2.1", + "bytes 1.3.0", "futures-channel", "futures-core", "futures-util", @@ -964,9 +964,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", @@ -1208,9 +1208,9 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "os_str_bytes" -version = "6.4.0" +version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5bf27447411e9ee3ff51186bf7a08e16c341efdde93f4d823e8844429bed7e" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "overload" @@ -1515,7 +1515,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" dependencies = [ "base64", - "bytes 1.2.1", + "bytes 1.3.0", "encoding_rs", "futures-core", "futures-util", @@ -1655,9 +1655,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" +checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" dependencies = [ "itoa", "ryu", @@ -1678,9 +1678,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f2d60d049ea019a84dcd6687b0d1e0030fe663ae105039bdf967ed5e6a9a7" +checksum = "25bf4a5a814902cd1014dbccfa4d4560fb8432c779471e96e035602519f82eef" dependencies = [ "base64", "chrono", @@ -1694,9 +1694,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ccadfacf6cf10faad22bbadf55986bdd0856edfb5d9210aa1dcf1f516e84e93" +checksum = "e3452b4c0f6c1e357f73fdb87cd1efabaa12acf328c7a528e252893baeb3f4aa" dependencies = [ "darling", "proc-macro2", @@ -1931,12 +1931,12 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.21.2" +version = "1.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" dependencies = [ "autocfg", - "bytes 1.2.1", + "bytes 1.3.0", "libc", "memchr", "mio", @@ -1989,7 +1989,7 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ - "bytes 1.2.1", + "bytes 1.3.0", "futures-core", "futures-sink", "pin-project-lite", diff --git a/Cargo.toml b/Cargo.toml index 507fe0b..fd91666 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ crossterm = { version = "0.25.0", features = ["event-stream"] } eyre = "0.6.8" futures = "0.3.24" glob = "0.3.0" -nix = { version = "0.25.0", features = ["user", "fs", "process"], default-features = false } +nix = { version = "0.25.0", features = ["user", "fs", "process", "term"], default-features = false } owo-colors = { version = "3.5.0", features = [ "supports-colors" ] } reqwest = { version = "0.11.11", default-features = false, features = ["rustls-tls", "stream"] } serde = { version = "1.0.144", features = ["derive"] } @@ -32,7 +32,7 @@ tar = "0.4.38" target-lexicon = "0.12.4" tempdir = { version = "0.3.7"} thiserror = "1.0.33" -tokio = { version = "1.21.0", features = ["time", "io-std", "process", "fs", "signal", "tracing", "rt-multi-thread", "macros", "io-util", "parking_lot"] } +tokio = { version = "1.21.0", features = ["time", "io-std", "process", "fs", "signal", "tracing", "rt-multi-thread", "macros", "io-util", "parking_lot" ] } tokio-util = { version = "0.7", features = ["io"] } tracing = { version = "0.1.36", features = [ "valuable" ] } tracing-error = "0.2.0" diff --git a/flake.nix b/flake.nix index 3672b02..06bbce3 100644 --- a/flake.nix +++ b/flake.nix @@ -128,7 +128,7 @@ ]); doCheck = true; - RUSTFLAGS = "--cfg tracing_unstable"; + RUSTFLAGS = "--cfg tracing_unstable --cfg tokio_unstable"; override = { preBuild ? "", ... }: { preBuild = preBuild + '' diff --git a/src/action/base/configure_nix_daemon_service.rs b/src/action/base/configure_nix_daemon_service.rs index 8acca11..dd9c0da 100644 --- a/src/action/base/configure_nix_daemon_service.rs +++ b/src/action/base/configure_nix_daemon_service.rs @@ -65,12 +65,7 @@ impl Action for ConfigureNixDaemonService { #[tracing::instrument(skip_all)] async fn execute(&mut self) -> Result<(), Box> { - let Self { action_state } = self; - if *action_state == ActionState::Completed { - tracing::trace!("Already completed: Configuring nix daemon service"); - return Ok(()); - } - tracing::debug!("Configuring nix daemon service"); + let Self { action_state: _ } = self; match OperatingSystem::host() { OperatingSystem::MacOSX { @@ -93,6 +88,7 @@ impl Action for ConfigureNixDaemonService { execute_command( Command::new("launchctl") + .process_group(0) .arg("load") .arg(DARWIN_NIX_DAEMON_DEST) .stdin(std::process::Stdio::null()), @@ -115,6 +111,7 @@ impl Action for ConfigureNixDaemonService { execute_command( Command::new("systemd-tmpfiles") + .process_group(0) .arg("--create") .arg("--prefix=/nix/var/nix") .stdin(std::process::Stdio::null()), @@ -124,6 +121,7 @@ impl Action for ConfigureNixDaemonService { execute_command( Command::new("systemctl") + .process_group(0) .arg("link") .arg(SERVICE_SRC) .stdin(std::process::Stdio::null()), @@ -133,6 +131,7 @@ impl Action for ConfigureNixDaemonService { execute_command( Command::new("systemctl") + .process_group(0) .arg("link") .arg(SOCKET_SRC) .stdin(std::process::Stdio::null()), @@ -142,6 +141,7 @@ impl Action for ConfigureNixDaemonService { execute_command( Command::new("systemctl") + .process_group(0) .arg("daemon-reload") .stdin(std::process::Stdio::null()), ) @@ -150,6 +150,7 @@ impl Action for ConfigureNixDaemonService { execute_command( Command::new("systemctl") + .process_group(0) .arg("enable") .arg("--now") .arg("nix-daemon.socket") @@ -160,8 +161,6 @@ impl Action for ConfigureNixDaemonService { }, }; - tracing::trace!("Configured nix daemon service"); - *action_state = ActionState::Completed; Ok(()) } @@ -188,6 +187,7 @@ impl Action for ConfigureNixDaemonService { | OperatingSystem::Darwin => { execute_command( Command::new("launchctl") + .process_group(0) .arg("unload") .arg(DARWIN_NIX_DAEMON_DEST), ) @@ -205,6 +205,7 @@ impl Action for ConfigureNixDaemonService { if socket_is_active { execute_command( Command::new("systemctl") + .process_group(0) .args(["stop", "nix-daemon.socket"]) .stdin(std::process::Stdio::null()), ) @@ -215,6 +216,7 @@ impl Action for ConfigureNixDaemonService { if socket_is_enabled { execute_command( Command::new("systemctl") + .process_group(0) .args(["disable", "nix-daemon.socket"]) .stdin(std::process::Stdio::null()), ) @@ -225,6 +227,7 @@ impl Action for ConfigureNixDaemonService { if service_is_active { execute_command( Command::new("systemctl") + .process_group(0) .args(["stop", "nix-daemon.service"]) .stdin(std::process::Stdio::null()), ) @@ -235,6 +238,7 @@ impl Action for ConfigureNixDaemonService { if service_is_enabled { execute_command( Command::new("systemctl") + .process_group(0) .args(["disable", "nix-daemon.service"]) .stdin(std::process::Stdio::null()), ) @@ -244,6 +248,7 @@ impl Action for ConfigureNixDaemonService { execute_command( Command::new("systemd-tmpfiles") + .process_group(0) .arg("--remove") .arg("--prefix=/nix/var/nix") .stdin(std::process::Stdio::null()), @@ -258,6 +263,7 @@ impl Action for ConfigureNixDaemonService { execute_command( Command::new("systemctl") + .process_group(0) .arg("daemon-reload") .stdin(std::process::Stdio::null()), ) diff --git a/src/action/base/create_group.rs b/src/action/base/create_group.rs index 41dee0f..ffec368 100644 --- a/src/action/base/create_group.rs +++ b/src/action/base/create_group.rs @@ -53,13 +53,8 @@ impl Action for CreateGroup { let Self { name, gid, - action_state, + action_state: _, } = self; - if *action_state == ActionState::Completed { - tracing::trace!("Already completed: Creating group"); - return Ok(()); - } - tracing::debug!("Creating group"); use target_lexicon::OperatingSystem; match target_lexicon::OperatingSystem::host() { @@ -70,6 +65,7 @@ impl Action for CreateGroup { } | OperatingSystem::Darwin => { if Command::new("/usr/bin/dscl") + .process_group(0) .args([".", "-read", &format!("/Groups/{name}")]) .stdin(std::process::Stdio::null()) .stdout(std::process::Stdio::null()) @@ -81,6 +77,7 @@ impl Action for CreateGroup { } else { execute_command( Command::new("/usr/sbin/dseditgroup") + .process_group(0) .args([ "-o", "create", @@ -99,6 +96,7 @@ impl Action for CreateGroup { _ => { execute_command( Command::new("groupadd") + .process_group(0) .args(["-g", &gid.to_string(), "--system", &name]) .stdin(std::process::Stdio::null()), ) @@ -107,8 +105,6 @@ impl Action for CreateGroup { }, }; - tracing::trace!("Created group"); - *action_state = ActionState::Completed; Ok(()) } @@ -159,6 +155,7 @@ impl Action for CreateGroup { _ => { execute_command( Command::new("groupdel") + .process_group(0) .arg(&name) .stdin(std::process::Stdio::null()), ) diff --git a/src/action/base/create_user.rs b/src/action/base/create_user.rs index f945e6c..67336bf 100644 --- a/src/action/base/create_user.rs +++ b/src/action/base/create_user.rs @@ -74,6 +74,7 @@ impl Action for CreateUser { // Right now, our test machines do not have a secure token and cannot delete users. if Command::new("/usr/bin/dscl") + .process_group(0) .args([".", "-read", &format!("/Users/{name}")]) .stdin(std::process::Stdio::null()) .stdout(std::process::Stdio::null()) @@ -85,6 +86,7 @@ impl Action for CreateUser { } else { execute_command( Command::new("/usr/bin/dscl") + .process_group(0) .args([".", "-create", &format!("/Users/{name}")]) .stdin(std::process::Stdio::null()), ) @@ -92,6 +94,7 @@ impl Action for CreateUser { .map_err(|e| CreateUserError::Command(e).boxed())?; execute_command( Command::new("/usr/bin/dscl") + .process_group(0) .args([ ".", "-create", @@ -105,6 +108,7 @@ impl Action for CreateUser { .map_err(|e| CreateUserError::Command(e).boxed())?; execute_command( Command::new("/usr/bin/dscl") + .process_group(0) .args([ ".", "-create", @@ -118,6 +122,7 @@ impl Action for CreateUser { .map_err(|e| CreateUserError::Command(e).boxed())?; execute_command( Command::new("/usr/bin/dscl") + .process_group(0) .args([ ".", "-create", @@ -131,6 +136,7 @@ impl Action for CreateUser { .map_err(|e| CreateUserError::Command(e).boxed())?; execute_command( Command::new("/usr/bin/dscl") + .process_group(0) .args([ ".", "-create", @@ -144,6 +150,7 @@ impl Action for CreateUser { .map_err(|e| CreateUserError::Command(e).boxed())?; execute_command( Command::new("/usr/bin/dscl") + .process_group(0) .args([ ".", "-append", @@ -157,6 +164,7 @@ impl Action for CreateUser { .map_err(|e| CreateUserError::Command(e).boxed())?; execute_command( Command::new("/usr/bin/dscl") + .process_group(0) .args([".", "-create", &format!("/Users/{name}"), "IsHidden", "1"]) .stdin(std::process::Stdio::null()), ) @@ -164,6 +172,7 @@ impl Action for CreateUser { .map_err(|e| CreateUserError::Command(e).boxed())?; execute_command( Command::new("/usr/sbin/dseditgroup") + .process_group(0) .args(["-o", "edit"]) .arg("-a") .arg(&name) @@ -179,6 +188,7 @@ impl Action for CreateUser { _ => { execute_command( Command::new("useradd") + .process_group(0) .args([ "--home-dir", "/var/empty", @@ -261,6 +271,7 @@ impl Action for CreateUser { _ => { execute_command( Command::new("userdel") + .process_group(0) .args([&name.to_string()]) .stdin(std::process::Stdio::null()), ) diff --git a/src/action/base/setup_default_profile.rs b/src/action/base/setup_default_profile.rs index c9e70e9..6aa094d 100644 --- a/src/action/base/setup_default_profile.rs +++ b/src/action/base/setup_default_profile.rs @@ -87,6 +87,7 @@ impl Action for SetupDefaultProfile { // Install `nix` itself into the store execute_command( Command::new(nix_pkg.join("bin/nix-env")) + .process_group(0) .arg("-i") .arg(&nix_pkg) .arg("-i") @@ -124,6 +125,7 @@ impl Action for SetupDefaultProfile { if !channels.is_empty() { let mut command = Command::new(nix_pkg.join("bin/nix-channel")); + command.process_group(0); command.arg("--update"); for channel in channels { command.arg(channel); diff --git a/src/action/darwin/bootstrap_volume.rs b/src/action/darwin/bootstrap_volume.rs index 03c153f..2ec3027 100644 --- a/src/action/darwin/bootstrap_volume.rs +++ b/src/action/darwin/bootstrap_volume.rs @@ -49,6 +49,7 @@ impl Action for BootstrapVolume { execute_command( Command::new("launchctl") + .process_group(0) .args(["bootstrap", "system"]) .arg(path) .stdin(std::process::Stdio::null()), @@ -57,6 +58,7 @@ impl Action for BootstrapVolume { .map_err(|e| BootstrapVolumeError::Command(e).boxed())?; execute_command( Command::new("launchctl") + .process_group(0) .args(["kickstart", "-k", "system/org.nixos.darwin-store"]) .stdin(std::process::Stdio::null()), ) @@ -84,6 +86,7 @@ impl Action for BootstrapVolume { execute_command( Command::new("launchctl") + .process_group(0) .args(["bootout", "system"]) .arg(path) .stdin(std::process::Stdio::null()), diff --git a/src/action/darwin/create_synthetic_objects.rs b/src/action/darwin/create_synthetic_objects.rs index 82c5629..ed72f91 100644 --- a/src/action/darwin/create_synthetic_objects.rs +++ b/src/action/darwin/create_synthetic_objects.rs @@ -37,6 +37,7 @@ impl Action for CreateSyntheticObjects { // Yup we literally call both and ignore the error! Reasoning: https://github.com/NixOS/nix/blob/95331cb9c99151cbd790ceb6ddaf49fc1c0da4b3/scripts/create-darwin-volume.sh#L261 execute_command( Command::new("/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util") + .process_group(0) .arg("-t") .stdin(std::process::Stdio::null()), ) @@ -44,6 +45,7 @@ impl Action for CreateSyntheticObjects { .ok(); // Deliberate execute_command( Command::new("/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util") + .process_group(0) .arg("-B") .stdin(std::process::Stdio::null()), ) @@ -65,6 +67,7 @@ impl Action for CreateSyntheticObjects { // Yup we literally call both and ignore the error! Reasoning: https://github.com/NixOS/nix/blob/95331cb9c99151cbd790ceb6ddaf49fc1c0da4b3/scripts/create-darwin-volume.sh#L261 execute_command( Command::new("/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util") + .process_group(0) .arg("-t") .stdin(std::process::Stdio::null()), ) @@ -72,6 +75,7 @@ impl Action for CreateSyntheticObjects { .ok(); // Deliberate execute_command( Command::new("/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util") + .process_group(0) .arg("-B") .stdin(std::process::Stdio::null()), ) diff --git a/src/action/darwin/create_volume.rs b/src/action/darwin/create_volume.rs index 51747ee..01d29e0 100644 --- a/src/action/darwin/create_volume.rs +++ b/src/action/darwin/create_volume.rs @@ -63,6 +63,7 @@ impl Action for CreateVolume { execute_command( Command::new("/usr/sbin/diskutil") + .process_group(0) .args([ "apfs", "addVolume", @@ -109,6 +110,7 @@ impl Action for CreateVolume { execute_command( Command::new("/usr/sbin/diskutil") + .process_group(0) .args(["apfs", "deleteVolume", name]) .stdin(std::process::Stdio::null()), ) diff --git a/src/action/darwin/enable_ownership.rs b/src/action/darwin/enable_ownership.rs index ec7cf29..07fab29 100644 --- a/src/action/darwin/enable_ownership.rs +++ b/src/action/darwin/enable_ownership.rs @@ -52,6 +52,7 @@ impl Action for EnableOwnership { let should_enable_ownership = { let buf = execute_command( Command::new("/usr/sbin/diskutil") + .process_group(0) .args(["info", "-plist"]) .arg(&path) .stdin(std::process::Stdio::null()), @@ -66,6 +67,7 @@ impl Action for EnableOwnership { if should_enable_ownership { execute_command( Command::new("/usr/sbin/diskutil") + .process_group(0) .arg("enableOwnership") .arg(path) .stdin(std::process::Stdio::null()), diff --git a/src/action/darwin/encrypt_volume.rs b/src/action/darwin/encrypt_volume.rs index fc43813..618f970 100644 --- a/src/action/darwin/encrypt_volume.rs +++ b/src/action/darwin/encrypt_volume.rs @@ -75,7 +75,7 @@ impl Action for EncryptVolume { // Add the password to the user keychain so they can unlock it later. execute_command( - Command::new("/usr/bin/security").args([ + Command::new("/usr/bin/security").process_group(0).args([ "add-generic-password", "-a", name.as_str(), @@ -104,7 +104,7 @@ impl Action for EncryptVolume { .await?; // Encrypt the mounted volume - execute_command(Command::new("/usr/sbin/diskutil").args([ + execute_command(Command::new("/usr/sbin/diskutil").process_group(0).args([ "apfs", "encryptVolume", name.as_str(), @@ -117,6 +117,7 @@ impl Action for EncryptVolume { execute_command( Command::new("/usr/sbin/diskutil") + .process_group(0) .arg("unmount") .arg("force") .arg(&name), @@ -150,7 +151,7 @@ impl Action for EncryptVolume { // TODO: This seems very rough and unsafe execute_command( - Command::new("/usr/bin/security").args([ + Command::new("/usr/bin/security").process_group(0).args([ "delete-generic-password", "-a", name.as_str(), diff --git a/src/action/darwin/kickstart_launchctl_service.rs b/src/action/darwin/kickstart_launchctl_service.rs index 3041370..18a960c 100644 --- a/src/action/darwin/kickstart_launchctl_service.rs +++ b/src/action/darwin/kickstart_launchctl_service.rs @@ -46,6 +46,7 @@ impl Action for KickstartLaunchctlService { execute_command( Command::new("launchctl") + .process_group(0) .arg("kickstart") .arg("-k") .arg(unit) diff --git a/src/action/darwin/unmount_volume.rs b/src/action/darwin/unmount_volume.rs index 8969289..a3ddc9f 100644 --- a/src/action/darwin/unmount_volume.rs +++ b/src/action/darwin/unmount_volume.rs @@ -55,6 +55,7 @@ impl Action for UnmountVolume { execute_command( Command::new("/usr/sbin/diskutil") + .process_group(0) .args(["unmount", "force"]) .arg(name) .stdin(std::process::Stdio::null()), @@ -82,6 +83,7 @@ impl Action for UnmountVolume { execute_command( Command::new("/usr/sbin/diskutil") + .process_group(0) .args(["unmount", "force"]) .arg(name) .stdin(std::process::Stdio::null()), diff --git a/src/action/linux/start_systemd_unit.rs b/src/action/linux/start_systemd_unit.rs index 5e9afea..b3e9155 100644 --- a/src/action/linux/start_systemd_unit.rs +++ b/src/action/linux/start_systemd_unit.rs @@ -43,6 +43,7 @@ impl Action for StartSystemdUnit { // TODO(@Hoverbear): Handle proxy vars execute_command( Command::new("systemctl") + .process_group(0) .arg("enable") .arg("--now") .arg(format!("{unit}")) @@ -67,9 +68,9 @@ impl Action for StartSystemdUnit { async fn revert(&mut self) -> Result<(), Box> { let Self { unit, .. } = self; - // TODO(@Hoverbear): Handle proxy vars execute_command( Command::new("systemctl") + .process_group(0) .arg("disable") .arg(format!("{unit}")) .stdin(std::process::Stdio::null()), @@ -80,6 +81,7 @@ impl Action for StartSystemdUnit { // We do both to avoid an error doing `disable --now` if the user did stop it already somehow. execute_command( Command::new("systemctl") + .process_group(0) .arg("stop") .arg(format!("{unit}")) .stdin(std::process::Stdio::null()), diff --git a/src/action/linux/systemd_sysext_merge.rs b/src/action/linux/systemd_sysext_merge.rs index 7652652..7be2869 100644 --- a/src/action/linux/systemd_sysext_merge.rs +++ b/src/action/linux/systemd_sysext_merge.rs @@ -44,6 +44,7 @@ impl Action for SystemdSysextMerge { execute_command( Command::new("systemd-sysext") + .process_group(0) .arg("merge") .arg(device) .stdin(std::process::Stdio::null()), @@ -75,6 +76,7 @@ impl Action for SystemdSysextMerge { // TODO(@Hoverbear): Handle proxy vars execute_command( Command::new("systemd-sysext") + .process_group(0) .arg("unmerge") .arg(device) .stdin(std::process::Stdio::null()), diff --git a/src/lib.rs b/src/lib.rs index 5f5db9b..9263503 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,8 +23,6 @@ use tokio::process::Command; #[tracing::instrument(skip_all, fields(command = %format!("{:?}", command.as_std())))] async fn execute_command(command: &mut Command) -> Result { - // TODO(@hoverbear): When tokio releases past 1.21.2, add a process group https://github.com/DeterminateSystems/harmonic/issues/41#issuecomment-1309513073 - let command_str = format!("{:?}", command.as_std()); tracing::trace!("Executing `{command_str}`"); let output = command.output().await?;