Merge pull request #627 from fufesou/better_linux_run_cmds

better_linux_run_cmds: run cmds without creating tmp files
This commit is contained in:
RustDesk 2022-05-27 11:12:13 +08:00 committed by GitHub
commit 6c739289ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 26 deletions

View File

@ -42,7 +42,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Invalid IP", "Neplatná IP adresa"), ("Invalid IP", "Neplatná IP adresa"),
("id_change_tip", "Použít je mozné pouze znaky a-z, A-Z, 0-9 a _ (podtržítko). Dále je třeba aby začínalo na písmeno a-z, A-Z. Délka mezi 6 a 16 znaky."), ("id_change_tip", "Použít je mozné pouze znaky a-z, A-Z, 0-9 a _ (podtržítko). Dále je třeba aby začínalo na písmeno a-z, A-Z. Délka mezi 6 a 16 znaky."),
("Invalid format", "Neplatný formát"), ("Invalid format", "Neplatný formát"),
("This function is turned off by the server", "Tato funkce je vypnuta serverem"), ("server_not_support", "Server zatím nepodporuje"),
("Not available", "Není k dispozici"), ("Not available", "Není k dispozici"),
("Too frequent", "Příliš časté"), ("Too frequent", "Příliš časté"),
("Cancel", "Storno"), ("Cancel", "Storno"),

View File

@ -42,6 +42,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Invalid IP", "IP nevalida"), ("Invalid IP", "IP nevalida"),
("id_change_tip", "Nur la signoj a-z, A-Z, 0-9, _ (substreko) povas esti uzataj. La unua litero povas esti inter a-z, A-Z. La longeco devas esti inter 6 kaj 16."), ("id_change_tip", "Nur la signoj a-z, A-Z, 0-9, _ (substreko) povas esti uzataj. La unua litero povas esti inter a-z, A-Z. La longeco devas esti inter 6 kaj 16."),
("Invalid format", "Formato nevalida"), ("Invalid format", "Formato nevalida"),
("server_not_support", "Ankoraŭ ne subtenata de la servilo"),
("Not available", "Nedisponebla"), ("Not available", "Nedisponebla"),
("Too frequent", "Tro ofte ŝanĝita, bonvolu reprovi poste"), ("Too frequent", "Tro ofte ŝanĝita, bonvolu reprovi poste"),
("Cancel", "Nuligi"), ("Cancel", "Nuligi"),

View File

@ -42,7 +42,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Invalid IP", ""), ("Invalid IP", ""),
("id_change_tip", ""), ("id_change_tip", ""),
("Invalid format", ""), ("Invalid format", ""),
("This function is turned off by the server", ""), ("server_not_support", ""),
("Not available", ""), ("Not available", ""),
("Too frequent", ""), ("Too frequent", ""),
("Cancel", ""), ("Cancel", ""),

View File

@ -42,7 +42,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Invalid IP", "Geçersiz IP adresi"), ("Invalid IP", "Geçersiz IP adresi"),
("id_change_tip", "Yalnızca a-z, A-Z, 0-9 ve _ (alt çizgi) karakterlerini kullanabilirsiniz. İlk karakter a-z veya A-Z olmalıdır. Uzunluk 6 ile 16 karakter arasında olmalıdır."), ("id_change_tip", "Yalnızca a-z, A-Z, 0-9 ve _ (alt çizgi) karakterlerini kullanabilirsiniz. İlk karakter a-z veya A-Z olmalıdır. Uzunluk 6 ile 16 karakter arasında olmalıdır."),
("Invalid format", "Hatalı Format"), ("Invalid format", "Hatalı Format"),
("This function is turned off by the server", "Bu özellik sunucu tarafından kapatıldı"), ("server_not_support", "Henüz sunucu tarafından desteklenmiyor"),
("Not available", "Erişilebilir değil"), ("Not available", "Erişilebilir değil"),
("Too frequent", "Çok sık"), ("Too frequent", "Çok sık"),
("Cancel", "İptal"), ("Cancel", "İptal"),

View File

@ -1,7 +1,6 @@
use super::{CursorData, ResultType}; use super::{CursorData, ResultType};
use hbb_common::{allow_err, bail, log}; use hbb_common::{allow_err, bail, log};
use libc::{c_char, c_int, c_void}; use libc::{c_char, c_int, c_void};
use std::io::prelude::*;
use std::{ use std::{
cell::RefCell, cell::RefCell,
sync::{ sync::{
@ -371,8 +370,7 @@ fn get_display_server_of_session(session: &str) -> String {
.replace("TTY=", "") .replace("TTY=", "")
.trim_end() .trim_end()
.into(); .into();
if let Ok(Some(xorg_results)) = if let Ok(xorg_results) = run_cmds(format!("ps -e | grep \"{}.\\\\+Xorg\"", tty))
run_cmds(format!("ps -e | grep \"{}.\\\\+Xorg\"", tty))
// And check if Xorg is running on that tty // And check if Xorg is running on that tty
{ {
if xorg_results.trim_end().to_string() != "" { if xorg_results.trim_end().to_string() != "" {
@ -441,9 +439,7 @@ pub fn current_is_wayland() -> bool {
pub fn modify_default_login() -> String { pub fn modify_default_login() -> String {
let dsession = std::env::var("DESKTOP_SESSION").unwrap(); let dsession = std::env::var("DESKTOP_SESSION").unwrap();
let user_name = std::env::var("USERNAME").unwrap(); let user_name = std::env::var("USERNAME").unwrap();
if let Ok(Some(x)) = if let Ok(x) = run_cmds("ls /usr/share/* | grep ${DESKTOP_SESSION}-xorg.desktop".to_owned()) {
run_cmds("ls /usr/share/* | grep ${DESKTOP_SESSION}-xorg.desktop".to_owned())
{
if x.trim_end().to_string() != "" { if x.trim_end().to_string() != "" {
match std::process::Command::new("pkexec") match std::process::Command::new("pkexec")
.args(vec![ .args(vec![
@ -471,7 +467,7 @@ pub fn modify_default_login() -> String {
return "Fix failed! Please re-login with X server manually".to_owned(); return "Fix failed! Please re-login with X server manually".to_owned();
} }
} }
} else if let Ok(Some(z)) = } else if let Ok(z) =
run_cmds("ls /usr/share/* | grep ${DESKTOP_SESSION:0:-8}.desktop".to_owned()) run_cmds("ls /usr/share/* | grep ${DESKTOP_SESSION:0:-8}.desktop".to_owned())
{ {
if z.trim_end().to_string() != "" { if z.trim_end().to_string() != "" {
@ -605,20 +601,11 @@ pub fn is_installed() -> bool {
true true
} }
fn run_cmds(cmds: String) -> ResultType<Option<String>> { pub fn run_cmds(cmds: String) -> ResultType<String> {
let mut tmp = std::env::temp_dir(); let output = std::process::Command::new("sh")
tmp.push(format!("{}_{}", crate::get_app_name(), crate::get_time())); .args(vec!["-c", &cmds])
let mut file = std::fs::File::create(&tmp)?; .output()?;
file.write_all(cmds.as_bytes())?; Ok(String::from_utf8_lossy(&output.stdout).to_string())
file.sync_all()?;
if let Ok(output) = std::process::Command::new("bash")
.arg(tmp.to_str().unwrap_or(""))
.output()
{
Ok(Some(String::from_utf8_lossy(&output.stdout).to_string()))
} else {
Ok(None)
}
} }
fn get_env_tries(name: &str, uid: &str, n: usize) -> String { fn get_env_tries(name: &str, uid: &str, n: usize) -> String {
@ -635,7 +622,7 @@ fn get_env_tries(name: &str, uid: &str, n: usize) -> String {
fn get_env(name: &str, uid: &str) -> String { fn get_env(name: &str, uid: &str) -> String {
let cmd = format!("ps -u {} -o pid= | xargs -I__ cat /proc/__/environ 2>/dev/null | tr '\\0' '\\n' | grep '^{}=' | tail -1 | sed 's/{}=//g'", uid, name, name); let cmd = format!("ps -u {} -o pid= | xargs -I__ cat /proc/__/environ 2>/dev/null | tr '\\0' '\\n' | grep '^{}=' | tail -1 | sed 's/{}=//g'", uid, name, name);
log::debug!("Run: {}", &cmd); log::debug!("Run: {}", &cmd);
if let Ok(Some(x)) = run_cmds(cmd) { if let Ok(x) = run_cmds(cmd) {
x.trim_end().to_string() x.trim_end().to_string()
} else { } else {
"".to_owned() "".to_owned()