From cbef49bf4f9d68bdb98df1772cd865afff34f13d Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 15 Jun 2020 11:16:11 +0200 Subject: [PATCH] remove absolute paths when executing binaries we set the paths manually, so this is ok Signed-off-by: Dominik Csapak --- src/api2/node/journal.rs | 2 +- src/api2/node/services.rs | 4 ++-- src/api2/node/status.rs | 2 +- src/api2/node/syslog.rs | 2 +- src/config/network/helper.rs | 6 +++--- src/tools/disks.rs | 18 ++++++------------ src/tools/disks/lvm.rs | 2 +- src/tools/disks/smart.rs | 2 +- src/tools/systemd.rs | 10 ++++------ 9 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/api2/node/journal.rs b/src/api2/node/journal.rs index 915d90ee..3d28a472 100644 --- a/src/api2/node/journal.rs +++ b/src/api2/node/journal.rs @@ -94,7 +94,7 @@ fn get_journal( let mut lines: Vec = vec![]; - let mut child = Command::new("/usr/bin/mini-journalreader") + let mut child = Command::new("mini-journalreader") .args(&args) .stdout(Stdio::piped()) .spawn()?; diff --git a/src/api2/node/services.rs b/src/api2/node/services.rs index b0cca76e..945ddb05 100644 --- a/src/api2/node/services.rs +++ b/src/api2/node/services.rs @@ -38,7 +38,7 @@ fn get_full_service_state(service: &str) -> Result { let real_service_name = real_service_name(service); - let mut child = Command::new("/bin/systemctl") + let mut child = Command::new("systemctl") .args(&["show", real_service_name]) .stdout(Stdio::piped()) .spawn()?; @@ -196,7 +196,7 @@ fn run_service_command(service: &str, cmd: &str) -> Result { let real_service_name = real_service_name(service); - let status = Command::new("/bin/systemctl") + let status = Command::new("systemctl") .args(&[cmd, real_service_name]) .status()?; diff --git a/src/api2/node/status.rs b/src/api2/node/status.rs index 0fe9ef4a..970c1367 100644 --- a/src/api2/node/status.rs +++ b/src/api2/node/status.rs @@ -102,7 +102,7 @@ fn reboot_or_shutdown(command: NodePowerCommand) -> Result<(), Error> { NodePowerCommand::Shutdown => "poweroff", }; - let output = Command::new("/bin/systemctl") + let output = Command::new("systemctl") .arg(systemctl_command) .output() .map_err(|err| format_err!("failed to execute systemctl - {}", err))?; diff --git a/src/api2/node/syslog.rs b/src/api2/node/syslog.rs index 8bd7b4c4..28a79469 100644 --- a/src/api2/node/syslog.rs +++ b/src/api2/node/syslog.rs @@ -27,7 +27,7 @@ fn dump_journal( let start = start.unwrap_or(0); let mut count: u64 = 0; - let mut child = Command::new("/bin/journalctl") + let mut child = Command::new("journalctl") .args(&args) .stdout(Stdio::piped()) .spawn()?; diff --git a/src/config/network/helper.rs b/src/config/network/helper.rs index 97645c01..c89427f9 100644 --- a/src/config/network/helper.rs +++ b/src/config/network/helper.rs @@ -141,7 +141,7 @@ pub fn get_network_interfaces() -> Result, Error> { pub fn compute_file_diff(filename: &str, shadow: &str) -> Result { - let output = Command::new("/usr/bin/diff") + let output = Command::new("diff") .arg("-b") .arg("-u") .arg(filename) @@ -165,10 +165,10 @@ pub fn assert_ifupdown2_installed() -> Result<(), Error> { pub fn network_reload() -> Result<(), Error> { - let output = Command::new("/sbin/ifreload") + let output = Command::new("ifreload") .arg("-a") .output() - .map_err(|err| format_err!("failed to execute '/sbin/ifreload' - {}", err))?; + .map_err(|err| format_err!("failed to execute 'ifreload' - {}", err))?; crate::tools::command_output(output, None) .map_err(|err| format_err!("ifreload failed: {}", err))?; diff --git a/src/tools/disks.rs b/src/tools/disks.rs index 54487cc2..a4c3e295 100644 --- a/src/tools/disks.rs +++ b/src/tools/disks.rs @@ -32,12 +32,6 @@ pub use lvm::*; mod smart; pub use smart::*; -pub const SGDISK_BIN_PATH: &str = "/usr/sbin/sgdisk"; -pub const LSBLK_BIN_PATH: &str = "/usr/bin/lsblk"; -pub const BLOCKDEV_BIN_PATH: &str = "/sbin/blockdev"; -pub const MKFS_BIN_PATH: &str = "/sbin/mkfs"; -pub const BLKID_BIN_PATH: &str = "/sbin/blkid"; - lazy_static::lazy_static!{ static ref ISCSI_PATH_REGEX: regex::Regex = regex::Regex::new(r"host[^/]*/session[^/]*").unwrap(); @@ -564,7 +558,7 @@ pub struct BlockDevStat { /// Use lsblk to read partition type uuids. pub fn get_partition_type_info() -> Result>, Error> { - let mut command = std::process::Command::new(LSBLK_BIN_PATH); + let mut command = std::process::Command::new("lsblk"); command.args(&["--json", "-o", "path,parttype"]); let output = crate::tools::run_command(command, None)?; @@ -861,7 +855,7 @@ pub fn reread_partition_table(disk: &Disk) -> Result<(), Error> { None => bail!("disk {:?} has no node in /dev", disk.syspath()), }; - let mut command = std::process::Command::new(BLOCKDEV_BIN_PATH); + let mut command = std::process::Command::new("blockdev"); command.arg("--rereadpt"); command.arg(disk_path); @@ -880,7 +874,7 @@ pub fn inititialize_gpt_disk(disk: &Disk, uuid: Option<&str>) -> Result<(), Erro let uuid = uuid.unwrap_or("R"); // R .. random disk GUID - let mut command = std::process::Command::new(SGDISK_BIN_PATH); + let mut command = std::process::Command::new("sgdisk"); command.arg(disk_path); command.args(&["-U", uuid]); @@ -897,7 +891,7 @@ pub fn create_single_linux_partition(disk: &Disk) -> Result { None => bail!("disk {:?} has no node in /dev", disk.syspath()), }; - let mut command = std::process::Command::new(SGDISK_BIN_PATH); + let mut command = std::process::Command::new("sgdisk"); command.args(&["-n1", "-t1:8300"]); command.arg(disk_path); @@ -950,7 +944,7 @@ pub fn create_file_system(disk: &Disk, fs_type: FileSystemType) -> Result<(), Er let fs_type = fs_type.to_string(); - let mut command = std::process::Command::new(MKFS_BIN_PATH); + let mut command = std::process::Command::new("mkfs"); command.args(&["-t", &fs_type]); command.arg(disk_path); @@ -988,7 +982,7 @@ pub fn get_fs_uuid(disk: &Disk) -> Result { None => bail!("disk {:?} has no node in /dev", disk.syspath()), }; - let mut command = std::process::Command::new(BLKID_BIN_PATH); + let mut command = std::process::Command::new("blkid"); command.args(&["-o", "export"]); command.arg(disk_path); diff --git a/src/tools/disks/lvm.rs b/src/tools/disks/lvm.rs index 2579a09b..eb228785 100644 --- a/src/tools/disks/lvm.rs +++ b/src/tools/disks/lvm.rs @@ -20,7 +20,7 @@ pub fn get_lvm_devices( partition_type_map: &HashMap>, ) -> Result, Error> { - const PVS_BIN_PATH: &str = "/sbin/pvs"; + const PVS_BIN_PATH: &str = "pvs"; let mut command = std::process::Command::new(PVS_BIN_PATH); command.args(&["--reportformat", "json", "--noheadings", "--readonly", "-o", "pv_name"]); diff --git a/src/tools/disks/smart.rs b/src/tools/disks/smart.rs index 9dbdf552..f85a92c4 100644 --- a/src/tools/disks/smart.rs +++ b/src/tools/disks/smart.rs @@ -76,7 +76,7 @@ pub fn get_smart_data( health_only: bool, ) -> Result { - const SMARTCTL_BIN_PATH: &str = "/usr/sbin/smartctl"; + const SMARTCTL_BIN_PATH: &str = "smartctl"; let mut command = std::process::Command::new(SMARTCTL_BIN_PATH); command.arg("-H"); diff --git a/src/tools/systemd.rs b/src/tools/systemd.rs index 15bb165d..6dde06a3 100644 --- a/src/tools/systemd.rs +++ b/src/tools/systemd.rs @@ -7,8 +7,6 @@ pub mod time; use anyhow::{bail, Error}; -pub const SYSTEMCTL_BIN_PATH: &str = "/usr/bin/systemctl"; - /// Escape strings for usage in systemd unit names pub fn escape_unit(mut unit: &str, is_path: bool) -> String { @@ -77,7 +75,7 @@ pub fn unescape_unit(text: &str) -> Result { pub fn reload_daemon() -> Result<(), Error> { - let mut command = std::process::Command::new(SYSTEMCTL_BIN_PATH); + let mut command = std::process::Command::new("systemctl"); command.arg("daemon-reload"); crate::tools::run_command(command, None)?; @@ -87,7 +85,7 @@ pub fn reload_daemon() -> Result<(), Error> { pub fn enable_unit(unit: &str) -> Result<(), Error> { - let mut command = std::process::Command::new(SYSTEMCTL_BIN_PATH); + let mut command = std::process::Command::new("systemctl"); command.arg("enable"); command.arg(unit); @@ -98,7 +96,7 @@ pub fn enable_unit(unit: &str) -> Result<(), Error> { pub fn start_unit(unit: &str) -> Result<(), Error> { - let mut command = std::process::Command::new(SYSTEMCTL_BIN_PATH); + let mut command = std::process::Command::new("systemctl"); command.arg("start"); command.arg(unit); @@ -109,7 +107,7 @@ pub fn start_unit(unit: &str) -> Result<(), Error> { pub fn stop_unit(unit: &str) -> Result<(), Error> { - let mut command = std::process::Command::new(SYSTEMCTL_BIN_PATH); + let mut command = std::process::Command::new("systemctl"); command.arg("stop"); command.arg(unit);