diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-24 09:16:44 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-24 09:16:44 +0400 |
| commit | e278e871c357c4832f29629e4f65f57ff0d0ded0 (patch) | |
| tree | d1543eecc3c381f72a13ca32234dca5691048c67 /src/utils/spawning.rs | |
| parent | ab9d1aab4ed13027896a80200775e5679fca9539 (diff) | |
| download | niri-e278e871c357c4832f29629e4f65f57ff0d0ded0.tar.gz niri-e278e871c357c4832f29629e4f65f57ff0d0ded0.tar.bz2 niri-e278e871c357c4832f29629e4f65f57ff0d0ded0.zip | |
Expand ~ in spawn
Diffstat (limited to 'src/utils/spawning.rs')
| -rw-r--r-- | src/utils/spawning.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/utils/spawning.rs b/src/utils/spawning.rs index 0e69a4a1..d212ea18 100644 --- a/src/utils/spawning.rs +++ b/src/utils/spawning.rs @@ -1,6 +1,7 @@ use std::ffi::OsStr; use std::os::fd::{AsFd, AsRawFd, FromRawFd, OwnedFd}; use std::os::unix::process::CommandExt; +use std::path::Path; use std::process::{Command, Stdio}; use std::sync::atomic::{AtomicBool, Ordering}; use std::{io, thread}; @@ -10,6 +11,8 @@ use smithay::reexports::rustix; use smithay::reexports::rustix::io::{close, read, retry_on_intr, write}; use smithay::reexports::rustix::pipe::{pipe_with, PipeFlags}; +use crate::utils::expand_home; + pub static REMOVE_ENV_RUST_BACKTRACE: AtomicBool = AtomicBool::new(false); pub static REMOVE_ENV_RUST_LIB_BACKTRACE: AtomicBool = AtomicBool::new(false); @@ -37,7 +40,17 @@ pub fn spawn<T: AsRef<OsStr> + Send + 'static>(command: Vec<T>) { fn spawn_sync(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>) { let _span = tracy_client::span!(); - let command = command.as_ref(); + let mut command = command.as_ref(); + + // Expand `~` at the start. + let expanded = expand_home(Path::new(command)); + match &expanded { + Ok(Some(expanded)) => command = expanded.as_ref(), + Ok(None) => (), + Err(err) => { + warn!("error expanding ~: {err:?}"); + } + } let mut process = Command::new(command); process @@ -221,7 +234,6 @@ fn read_all(fd: impl AsFd, buf: &mut [u8]) -> rustix::io::Result<()> { fn start_systemd_scope(name: &OsStr, intermediate_pid: u32, child_pid: u32) -> anyhow::Result<()> { use std::fmt::Write as _; use std::os::unix::ffi::OsStrExt; - use std::path::Path; use std::sync::OnceLock; use anyhow::Context; |
