From bb6e080c1c69695054a8bc99fe976ec4c12e3446 Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Thu, 26 Jun 2025 09:49:22 +0800 Subject: [PATCH] fix: linux workaround cmd path (#12172) Signed-off-by: fufesou --- libs/hbb_common | 2 +- src/platform/gtk_sudo.rs | 6 ++++-- src/platform/linux.rs | 13 ++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libs/hbb_common b/libs/hbb_common index 92ca2ca8b..3454fe8c6 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 92ca2ca8be6c54d3977e35292d378dfbe90908fc +Subproject commit 3454fe8c60d32ee5033d04fc72466eebb5873880 diff --git a/src/platform/gtk_sudo.rs b/src/platform/gtk_sudo.rs index 9aeea1e2b..fca6403f6 100644 --- a/src/platform/gtk_sudo.rs +++ b/src/platform/gtk_sudo.rs @@ -5,7 +5,9 @@ use crate::lang::translate; use gtk::{glib, prelude::*}; use hbb_common::{ anyhow::{bail, Error}, - log, ResultType, + log, + platform::linux::CMD_SH, + ResultType, }; use nix::{ libc::{fcntl, kill}, @@ -468,7 +470,7 @@ fn child(su_user: Option, args: Vec) -> ResultType<()> { if su_user.is_some() { params.push("-S".to_string()); } - params.push("/bin/sh".to_string()); + params.push(CMD_SH.to_string()); params.push("-c".to_string()); let command = args diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 18a8ab172..7d8b781a7 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -10,6 +10,7 @@ use hbb_common::{ libc::{c_char, c_int, c_long, c_void}, log, message_proto::{DisplayInfo, Resolution}, + platform::linux::{CMD_PS, CMD_SH}, regex::{Captures, Regex}, }; use std::{ @@ -320,7 +321,7 @@ fn set_x11_env(desktop: &Desktop) { #[inline] fn stop_rustdesk_servers() { let _ = run_cmds(&format!( - r##"ps -ef | grep -E '{} +--server' | awk '{{printf("kill -9 %d\n", $2)}}' | bash"##, + r##"ps -ef | grep -E '{} +--server' | awk '{{print $2}}' | xargs -r kill -9"##, crate::get_app_name().to_lowercase(), )); } @@ -328,11 +329,11 @@ fn stop_rustdesk_servers() { #[inline] fn stop_subprocess() { let _ = run_cmds(&format!( - r##"ps -ef | grep '/etc/{}/xorg.conf' | grep -v grep | awk '{{printf("kill -9 %d\n", $2)}}' | bash"##, + r##"ps -ef | grep '/etc/{}/xorg.conf' | grep -v grep | awk '{{print $2}}' | xargs -r kill -9"##, crate::get_app_name().to_lowercase(), )); let _ = run_cmds(&format!( - r##"ps -ef | grep -E '{} +--cm-no-ui' | grep -v grep | awk '{{printf("kill -9 %d\n", $2)}}' | bash"##, + r##"ps -ef | grep -E '{} +--cm-no-ui' | grep -v grep | awk '{{print $2}}' | xargs -r kill -9"##, crate::get_app_name().to_lowercase(), )); } @@ -517,7 +518,8 @@ pub fn get_active_userid() -> String { } fn get_cm() -> bool { - if let Ok(output) = Command::new("ps").args(vec!["aux"]).output() { + // We use `CMD_PS` instead of `ps` to suppress some audit messages on some systems. + if let Ok(output) = Command::new(CMD_PS.as_str()).args(vec!["aux"]).output() { for line in String::from_utf8_lossy(&output.stdout).lines() { if line.contains(&format!( "{} --cm", @@ -1355,7 +1357,8 @@ pub fn run_me_with(secs: u32) { .unwrap_or("".into()) .to_string_lossy() .to_string(); - std::process::Command::new("sh") + // We use `CMD_SH` instead of `sh` to suppress some audit messages on some systems. + std::process::Command::new(CMD_SH.as_str()) .arg("-c") .arg(&format!("sleep {secs}; {exe}")) .spawn()