This commit is contained in:
rustdesk 2021-04-30 00:33:37 +08:00
parent afc842785a
commit 401648eefd
2 changed files with 102 additions and 15 deletions

View File

@ -12,9 +12,8 @@ Desktop versions use [sciter](https://sciter.com/) for GUI, please download scit
[Linux](https://github.com/c-smile/sciter-sdk/raw/dc65744b66389cd5a0ff6bdb7c63a8b7b05a708b/bin.lnx/x64/libsciter-gtk.so)
[Osx](https://github.com/c-smile/sciter-sdk/raw/dc65744b66389cd5a0ff6bdb7c63a8b7b05a708b/bin.osx/sciter-osx-64.dylib)
## How To Build
### Steps
## Raw Steps to build
* Prepare your Rust development env and C++ build env
* Install [vcpkg](https://github.com/microsoft/vcpkg), and set `VCPKG_ROOT` env variable correctly
@ -23,13 +22,41 @@ Desktop versions use [sciter](https://sciter.com/) for GUI, please download scit
- Linux/Osx: vcpkg install libvpx libyuv opus
* run `cargo run`
### Build on Debain
## How to build on Linux
### Ubuntu 18 (Debain 10)
```
sudo apt install -y git curl wget nasm libgtk-3-dev clang libxcb-randr0-dev libxdo-dev libxfixes-dev libxcb-shape0-dev libxcb-xfixes0-dev libasound2-dev libpulse-dev cmake
git clone https://github.com/microsoft/vcpkg
sudo apt install -y g++ gcc git curl wget nasm libgtk-3-dev clang libxcb-randr0-dev libxdo-dev libxfixes-dev libxcb-shape0-dev libxcb-xfixes0-dev libasound2-dev libpulse-dev cmake
```
### Fedora 28
```
yum -y install gcc-c++ git curl wget nasm gcc gtk3-devel clang libxcb-devel libxdo-devel libXfixes-devel pulseaudio-libs-devel cmake alsa-lib-devel
```
### Install VCPKG
```
git clone https://github.com/microsoft/vcpkg --branch 2020.11-1
vcpkg/bootstrap-vcpkg.sh
export VCPKG_ROOT=$HOME/vcpkg
vcpkg/vcpkg install libvpx libyuv opus
```
### Fix libvpx (For Fedora)
```
cd vcpkg/buildtrees/libvpx/src
cd *
./configure
sed -i 's/CFLAGS+=-I/CFLAGS+=-fPIC -I/g' Makefile
sed -i 's/CXXFLAGS+=-I/CXXFLAGS+=-fPIC -I/g' Makefile
make
cp libvpx.a $HOME/vcpkg/installed/x64-linux/lib/
cd
```
### Build
```
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
git clone https://github.com/rustdesk/rustdesk

View File

@ -1,6 +1,7 @@
use super::{CursorData, ResultType};
use hbb_common::{allow_err, bail, log};
use libc::{c_char, c_int, c_void};
use std::io::prelude::*;
use std::{
cell::RefCell,
sync::{
@ -162,8 +163,36 @@ pub fn start_os_service() {
if tmp != uid && !tmp.is_empty() {
uid = tmp;
log::info!("uid of seat0: {}", uid);
std::env::set_var("XAUTHORITY", format!("/run/user/{}/gdm/Xauthority", uid));
std::env::set_var("DISPLAY", get_display());
let gdm = format!("/run/user/{}/gdm/Xauthority", uid);
let mut auth = get_env("XAUTHORITY", &uid);
if auth.is_empty() {
auth = if std::path::Path::new(&gdm).exists() {
gdm
} else {
let username = get_active_username();
if username == "root" {
format!("/{}/.Xauthority", username)
} else {
let tmp = format!("/home/{}/.Xauthority", username);
if std::path::Path::new(&tmp).exists() {
tmp
} else {
format!("/var/lib/{}/.Xauthority", username)
}
}
};
}
let mut d = get_env("DISPLAY", &uid);
if d.is_empty() {
d = get_display();
}
if d.is_empty() {
d = ":0".to_owned()
}
log::info!("DISPLAY: {}", d);
log::info!("XAUTHORITY: {}", auth);
std::env::set_var("XAUTHORITY", auth);
std::env::set_var("DISPLAY", d);
if let Some(ps) = server.as_mut() {
allow_err!(ps.kill());
std::thread::sleep(std::time::Duration::from_millis(30));
@ -245,12 +274,12 @@ fn get_cm() -> bool {
fn get_display() -> String {
let user = get_active_username();
log::debug!("w {}", &user);
if let Ok(output) = std::process::Command::new("w").arg(&user).output() {
for line in String::from_utf8_lossy(&output.stdout).lines() {
log::debug!(" {}", line);
let mut iter = line.split_whitespace();
let a = iter.nth(1);
let b = iter.next();
if a == b {
let b = iter.nth(2);
if let Some(b) = b {
if b.starts_with(":") {
return b.to_owned();
@ -258,13 +287,14 @@ fn get_display() -> String {
}
}
}
}
// above not work for gdm user
log::debug!("ls -l /tmp/.X11-unix/");
if let Ok(output) = std::process::Command::new("ls")
.args(vec!["-l", "/tmp/.X11-unix/"])
.output()
{
for line in String::from_utf8_lossy(&output.stdout).lines() {
log::debug!(" {}", line);
let mut iter = line.split_whitespace();
if iter.nth(2) == Some(&user) {
if let Some(x) = iter.last() {
@ -444,3 +474,33 @@ pub fn block_input(_v: bool) {
pub fn is_installed() -> bool {
true
}
fn run_cmds(cmds: String) -> ResultType<Option<String>> {
let mut tmp = std::env::temp_dir();
tmp.push(format!(
"{}_{}",
hbb_common::config::APP_NAME,
crate::get_time()
));
let mut file = std::fs::File::create(&tmp)?;
file.write_all(cmds.as_bytes())?;
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(name: &str, uid: &str) -> String {
let cmd = format!("ps -u {} -o pid= | xargs -I__ cat /proc/__/environ 2>/dev/null | tr '\\0' '\\n' | grep -m1 '^{}=' | sed 's/{}=//g'", uid, name, name);
log::debug!("Run: {}", &cmd);
if let Ok(Some(x)) = run_cmds(cmd) {
x.trim_end().to_string()
} else {
"".to_owned()
}
}