run via execpve

This commit is contained in:
Alexander Mohr 2025-05-02 02:22:21 +02:00
parent 66a708b429
commit bc6d1de673
4 changed files with 29 additions and 3 deletions

19
Cargo.lock generated
View file

@ -135,6 +135,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.2.25" version = "3.2.25"
@ -891,6 +897,18 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nix"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537bc3c4a347b87fd52ac6c03a02ab1302962cfd93373c5d7a112cdc337854cc"
dependencies = [
"bitflags 2.9.0",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "1.2.4" version = "1.2.4"
@ -1480,6 +1498,7 @@ dependencies = [
"libc", "libc",
"log", "log",
"meval", "meval",
"nix",
"rayon", "rayon",
"regex", "regex",
"serde", "serde",

View file

@ -46,3 +46,4 @@ which = "7.0.3"
meval = "0.2.0" meval = "0.2.0"
tree_magic_mini = "3.1.6" tree_magic_mini = "3.1.6"
rayon = "1.10.0" rayon = "1.10.0"
nix = { version = "0.30.0", features = ["process"] }

View file

@ -960,7 +960,7 @@ fn percent_or_absolute(value: &str, base_value: i32) -> Option<i32> {
pub fn sort_menu_items_alphabetically_honor_initial_score<T: Clone>(items: &mut [MenuItem<T>]) { pub fn sort_menu_items_alphabetically_honor_initial_score<T: Clone>(items: &mut [MenuItem<T>]) {
let special_score = items.len() as f64; let special_score = items.len() as f64;
let mut regular_score = 0.0; let mut regular_score = 0.0;
items.sort_by(|l, r| l.label.cmp(&r.label)); items.sort_by(|l, r| r.label.cmp(&l.label));
for item in items.iter_mut() { for item in items.iter_mut() {
if item.initial_sort_score == 0.0 { if item.initial_sort_score == 0.0 {

View file

@ -11,6 +11,7 @@ use std::io::Read;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::Instant; use std::time::Instant;
use std::{env, fs, io}; use std::{env, fs, io};
use std::ffi::CString;
#[derive(Debug, Deserialize, Serialize, Clone)] #[derive(Debug, Deserialize, Serialize, Clone)]
struct DRunCache { struct DRunCache {
@ -532,7 +533,7 @@ impl ItemProvider<String> for DMenuProvider {
(false, self.items.clone()) (false, self.items.clone())
} }
fn get_sub_elements(&mut self, _: &MenuItem<String>) -> (bool, std::option::Option<Vec<gui::MenuItem<std::string::String>>>) { fn get_sub_elements(&mut self, _: &MenuItem<String>) -> (bool, Option<Vec<gui::MenuItem<std::string::String>>>) {
(false, None) (false, None)
} }
} }
@ -822,7 +823,12 @@ fn update_run_cache_and_run<T: Clone>(
} }
if let Some(action) = selection_result.action { if let Some(action) = selection_result.action {
spawn_fork(&action, selection_result.working_dir.as_ref()) let program = CString::new(action).unwrap();
let args = [program.clone()];
// This replaces the current process image
nix::unistd::execvp(&program, &args).map_err(|e| Error::RunFailed(e.to_string()))?;
Ok(())
} else { } else {
Err(Error::MissingAction) Err(Error::MissingAction)
} }