remove absolute paths when executing binaries
we set the paths manually, so this is ok Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
0b99e5aebc
commit
cbef49bf4f
|
@ -94,7 +94,7 @@ fn get_journal(
|
||||||
|
|
||||||
let mut lines: Vec<String> = vec![];
|
let mut lines: Vec<String> = vec![];
|
||||||
|
|
||||||
let mut child = Command::new("/usr/bin/mini-journalreader")
|
let mut child = Command::new("mini-journalreader")
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
|
|
@ -38,7 +38,7 @@ fn get_full_service_state(service: &str) -> Result<Value, Error> {
|
||||||
|
|
||||||
let real_service_name = real_service_name(service);
|
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])
|
.args(&["show", real_service_name])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
@ -196,7 +196,7 @@ fn run_service_command(service: &str, cmd: &str) -> Result<Value, Error> {
|
||||||
|
|
||||||
let real_service_name = real_service_name(service);
|
let real_service_name = real_service_name(service);
|
||||||
|
|
||||||
let status = Command::new("/bin/systemctl")
|
let status = Command::new("systemctl")
|
||||||
.args(&[cmd, real_service_name])
|
.args(&[cmd, real_service_name])
|
||||||
.status()?;
|
.status()?;
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ fn reboot_or_shutdown(command: NodePowerCommand) -> Result<(), Error> {
|
||||||
NodePowerCommand::Shutdown => "poweroff",
|
NodePowerCommand::Shutdown => "poweroff",
|
||||||
};
|
};
|
||||||
|
|
||||||
let output = Command::new("/bin/systemctl")
|
let output = Command::new("systemctl")
|
||||||
.arg(systemctl_command)
|
.arg(systemctl_command)
|
||||||
.output()
|
.output()
|
||||||
.map_err(|err| format_err!("failed to execute systemctl - {}", err))?;
|
.map_err(|err| format_err!("failed to execute systemctl - {}", err))?;
|
||||||
|
|
|
@ -27,7 +27,7 @@ fn dump_journal(
|
||||||
let start = start.unwrap_or(0);
|
let start = start.unwrap_or(0);
|
||||||
let mut count: u64 = 0;
|
let mut count: u64 = 0;
|
||||||
|
|
||||||
let mut child = Command::new("/bin/journalctl")
|
let mut child = Command::new("journalctl")
|
||||||
.args(&args)
|
.args(&args)
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
|
|
@ -141,7 +141,7 @@ pub fn get_network_interfaces() -> Result<HashMap<String, bool>, Error> {
|
||||||
|
|
||||||
pub fn compute_file_diff(filename: &str, shadow: &str) -> Result<String, Error> {
|
pub fn compute_file_diff(filename: &str, shadow: &str) -> Result<String, Error> {
|
||||||
|
|
||||||
let output = Command::new("/usr/bin/diff")
|
let output = Command::new("diff")
|
||||||
.arg("-b")
|
.arg("-b")
|
||||||
.arg("-u")
|
.arg("-u")
|
||||||
.arg(filename)
|
.arg(filename)
|
||||||
|
@ -165,10 +165,10 @@ pub fn assert_ifupdown2_installed() -> Result<(), Error> {
|
||||||
|
|
||||||
pub fn network_reload() -> Result<(), Error> {
|
pub fn network_reload() -> Result<(), Error> {
|
||||||
|
|
||||||
let output = Command::new("/sbin/ifreload")
|
let output = Command::new("ifreload")
|
||||||
.arg("-a")
|
.arg("-a")
|
||||||
.output()
|
.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)
|
crate::tools::command_output(output, None)
|
||||||
.map_err(|err| format_err!("ifreload failed: {}", err))?;
|
.map_err(|err| format_err!("ifreload failed: {}", err))?;
|
||||||
|
|
|
@ -32,12 +32,6 @@ pub use lvm::*;
|
||||||
mod smart;
|
mod smart;
|
||||||
pub use 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!{
|
lazy_static::lazy_static!{
|
||||||
static ref ISCSI_PATH_REGEX: regex::Regex =
|
static ref ISCSI_PATH_REGEX: regex::Regex =
|
||||||
regex::Regex::new(r"host[^/]*/session[^/]*").unwrap();
|
regex::Regex::new(r"host[^/]*/session[^/]*").unwrap();
|
||||||
|
@ -564,7 +558,7 @@ pub struct BlockDevStat {
|
||||||
/// Use lsblk to read partition type uuids.
|
/// Use lsblk to read partition type uuids.
|
||||||
pub fn get_partition_type_info() -> Result<HashMap<String, Vec<String>>, Error> {
|
pub fn get_partition_type_info() -> Result<HashMap<String, Vec<String>>, 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"]);
|
command.args(&["--json", "-o", "path,parttype"]);
|
||||||
|
|
||||||
let output = crate::tools::run_command(command, None)?;
|
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()),
|
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("--rereadpt");
|
||||||
command.arg(disk_path);
|
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 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.arg(disk_path);
|
||||||
command.args(&["-U", uuid]);
|
command.args(&["-U", uuid]);
|
||||||
|
|
||||||
|
@ -897,7 +891,7 @@ pub fn create_single_linux_partition(disk: &Disk) -> Result<Disk, Error> {
|
||||||
None => bail!("disk {:?} has no node in /dev", disk.syspath()),
|
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.args(&["-n1", "-t1:8300"]);
|
||||||
command.arg(disk_path);
|
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 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.args(&["-t", &fs_type]);
|
||||||
command.arg(disk_path);
|
command.arg(disk_path);
|
||||||
|
|
||||||
|
@ -988,7 +982,7 @@ pub fn get_fs_uuid(disk: &Disk) -> Result<String, Error> {
|
||||||
None => bail!("disk {:?} has no node in /dev", disk.syspath()),
|
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.args(&["-o", "export"]);
|
||||||
command.arg(disk_path);
|
command.arg(disk_path);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub fn get_lvm_devices(
|
||||||
partition_type_map: &HashMap<String, Vec<String>>,
|
partition_type_map: &HashMap<String, Vec<String>>,
|
||||||
) -> Result<HashSet<u64>, Error> {
|
) -> Result<HashSet<u64>, Error> {
|
||||||
|
|
||||||
const PVS_BIN_PATH: &str = "/sbin/pvs";
|
const PVS_BIN_PATH: &str = "pvs";
|
||||||
|
|
||||||
let mut command = std::process::Command::new(PVS_BIN_PATH);
|
let mut command = std::process::Command::new(PVS_BIN_PATH);
|
||||||
command.args(&["--reportformat", "json", "--noheadings", "--readonly", "-o", "pv_name"]);
|
command.args(&["--reportformat", "json", "--noheadings", "--readonly", "-o", "pv_name"]);
|
||||||
|
|
|
@ -76,7 +76,7 @@ pub fn get_smart_data(
|
||||||
health_only: bool,
|
health_only: bool,
|
||||||
) -> Result<SmartData, Error> {
|
) -> Result<SmartData, Error> {
|
||||||
|
|
||||||
const SMARTCTL_BIN_PATH: &str = "/usr/sbin/smartctl";
|
const SMARTCTL_BIN_PATH: &str = "smartctl";
|
||||||
|
|
||||||
let mut command = std::process::Command::new(SMARTCTL_BIN_PATH);
|
let mut command = std::process::Command::new(SMARTCTL_BIN_PATH);
|
||||||
command.arg("-H");
|
command.arg("-H");
|
||||||
|
|
|
@ -7,8 +7,6 @@ pub mod time;
|
||||||
|
|
||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
|
|
||||||
pub const SYSTEMCTL_BIN_PATH: &str = "/usr/bin/systemctl";
|
|
||||||
|
|
||||||
/// Escape strings for usage in systemd unit names
|
/// Escape strings for usage in systemd unit names
|
||||||
pub fn escape_unit(mut unit: &str, is_path: bool) -> String {
|
pub fn escape_unit(mut unit: &str, is_path: bool) -> String {
|
||||||
|
|
||||||
|
@ -77,7 +75,7 @@ pub fn unescape_unit(text: &str) -> Result<String, Error> {
|
||||||
|
|
||||||
pub fn reload_daemon() -> Result<(), Error> {
|
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");
|
command.arg("daemon-reload");
|
||||||
|
|
||||||
crate::tools::run_command(command, None)?;
|
crate::tools::run_command(command, None)?;
|
||||||
|
@ -87,7 +85,7 @@ pub fn reload_daemon() -> Result<(), Error> {
|
||||||
|
|
||||||
pub fn enable_unit(unit: &str) -> 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("enable");
|
||||||
command.arg(unit);
|
command.arg(unit);
|
||||||
|
|
||||||
|
@ -98,7 +96,7 @@ pub fn enable_unit(unit: &str) -> Result<(), Error> {
|
||||||
|
|
||||||
pub fn start_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("start");
|
||||||
command.arg(unit);
|
command.arg(unit);
|
||||||
|
|
||||||
|
@ -109,7 +107,7 @@ pub fn start_unit(unit: &str) -> Result<(), Error> {
|
||||||
|
|
||||||
pub fn stop_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("stop");
|
||||||
command.arg(unit);
|
command.arg(unit);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue