-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Remove useless command calls #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||
| use crate::ResultType; | ||||||||||||||||||||||||||
| use std::{collections::HashMap, process::Command}; | ||||||||||||||||||||||||||
| use std::{collections::HashMap, io::BufRead, process::Command}; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| use sctk::{ | ||||||||||||||||||||||||||
| output::OutputData, | ||||||||||||||||||||||||||
|
|
@@ -37,8 +37,6 @@ lazy_static::lazy_static! { | |||||||||||||||||||||||||
| // ... | ||||||||||||||||||||||||||
| lazy_static::lazy_static! { | ||||||||||||||||||||||||||
| pub static ref CMD_LOGINCTL: String = find_cmd_path("loginctl"); | ||||||||||||||||||||||||||
| pub static ref CMD_PS: String = find_cmd_path("ps"); | ||||||||||||||||||||||||||
| pub static ref CMD_SH: String = find_cmd_path("sh"); | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I was working on this repository alone, and didn’t notice it was API for rustdesk, my bad! I’ll put all of the pub symbols back to their former state then, and also do the same kind of fixes in rustdesk, thanks! |
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| pub const DISPLAY_SERVER_WAYLAND: &str = "wayland"; | ||||||||||||||||||||||||||
|
|
@@ -54,17 +52,24 @@ pub struct Distro { | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| impl Distro { | ||||||||||||||||||||||||||
| fn new() -> Self { | ||||||||||||||||||||||||||
| let name = run_cmds("awk -F'=' '/^NAME=/ {print $2}' /etc/os-release") | ||||||||||||||||||||||||||
| .unwrap_or_default() | ||||||||||||||||||||||||||
| .trim() | ||||||||||||||||||||||||||
| .trim_matches('"') | ||||||||||||||||||||||||||
| .to_string(); | ||||||||||||||||||||||||||
| let version_id = run_cmds("awk -F'=' '/^VERSION_ID=/ {print $2}' /etc/os-release") | ||||||||||||||||||||||||||
| .unwrap_or_default() | ||||||||||||||||||||||||||
| .trim() | ||||||||||||||||||||||||||
| .trim_matches('"') | ||||||||||||||||||||||||||
| .to_string(); | ||||||||||||||||||||||||||
| Self { name, version_id } | ||||||||||||||||||||||||||
| let mut name = None; | ||||||||||||||||||||||||||
| let mut version_id = None; | ||||||||||||||||||||||||||
| if let Ok(os_release) = std::fs::File::open("/etc/os-release") { | ||||||||||||||||||||||||||
| let os_release = std::io::BufReader::new(os_release); | ||||||||||||||||||||||||||
| for line in os_release.lines() { | ||||||||||||||||||||||||||
| if let Some((key, value)) = line.unwrap_or_default().split_once('=') { | ||||||||||||||||||||||||||
| if key == "NAME" { | ||||||||||||||||||||||||||
| name = Some(value.trim_matches('"').to_owned()); | ||||||||||||||||||||||||||
| } else if key == "VERSION_ID" { | ||||||||||||||||||||||||||
| version_id = Some(value.trim_matches('"').to_owned()); | ||||||||||||||||||||||||||
|
Comment on lines
+60
to
+64
|
||||||||||||||||||||||||||
| if let Some((key, value)) = line.unwrap_or_default().split_once('=') { | |
| if key == "NAME" { | |
| name = Some(value.trim_matches('"').to_owned()); | |
| } else if key == "VERSION_ID" { | |
| version_id = Some(value.trim_matches('"').to_owned()); | |
| if let Ok(line_content) = line { | |
| if let Some((key, value)) = line_content.split_once('=') { | |
| if key == "NAME" { | |
| name = Some(value.trim_matches('"').to_owned()); | |
| } else if key == "VERSION_ID" { | |
| version_id = Some(value.trim_matches('"').to_owned()); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly removing CMD_SH.as_str() may generate an excessive number of audit logs.
hbb_common/src/platform/linux.rs
Line 26 in 8b0e258
| // `ausearch -x /usr/share/rustdesk/rustdesk` will return |
ausearch -x /usr/share/rustdesk/rustdesk
This is because the audit log will record ENOENT errors when the system attempts to resolve the absolute path of the command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a better change could be
pub fn is_kde_session() -> bool {
let Ok(entries) = fs::read_dir("/proc") else {
return false;
};
for entry in entries.flatten() {
let name = entry.file_name();
let name_str = name.to_string_lossy();
// Skip non-pid directories
if !name_str.chars().all(|c| c.is_ascii_digit()) {
continue;
}
// Read /proc/[pid]/comm (process name, max 16 chars, no args)
let comm_path = entry.path().join("comm");
if let Ok(comm) = fs::read_to_string(&comm_path) {
let comm = comm.trim();
// Match kded5, kded6, etc.
if comm.starts_with("kded") && comm[4..].chars().all(|c| c.is_ascii_digit()) {
return true;
}
}
}
false
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed that’s much better, I’ll update that PR with your code. Using shell commands for pretty much anything is a red flag anyway, silencing the audit logs was always a bad workaround.
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The std::fs::read_to_string() call includes any trailing newline characters from the file. The previous cat /proc/self/sessionid command through the shell would have included the newline, but the comparison with INVALID_SESSION on line 155 might now fail if the file content has trailing whitespace. Consider trimming the result: std::fs::read_to_string("/proc/self/sessionid").unwrap_or_default().trim().to_string()
| session = std::fs::read_to_string("/proc/self/sessionid").unwrap_or_default(); | |
| session = std::fs::read_to_string("/proc/self/sessionid").unwrap_or_default().trim().to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file can’t ever contain any newline, it can only be a decimal integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thinks it's better to always trim() here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, this is ABI, the kernel will never ever add a newline or any other character here, so trim() will always be a noop.
That said, in a future PR I have already started working on, this whole mess of fetching the session is simplified by always using logind using zbus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run_cmds() is commonly used in https://github.com/rustdesk/rustdesk
Maybe we need to keep it in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
std::env::home_dir()function has been deprecated since Rust 1.29 (2018) due to incorrect behavior on Windows and platform inconsistencies. The deprecation notice recommends using thedirsordirs_nextcrate instead. This codebase already usesdirs_next::home_dir()in other places (lines 628, 667), so you should use the same function here for consistency and to avoid using deprecated APIs.