refact register_breakdown_handler
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
c44843c96a
commit
b733ad9379
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -1566,7 +1566,6 @@ version = "0.0.14"
|
||||
dependencies = [
|
||||
"core-graphics 0.22.3",
|
||||
"hbb_common",
|
||||
"libc",
|
||||
"log",
|
||||
"objc",
|
||||
"pkg-config",
|
||||
@ -2598,6 +2597,7 @@ name = "hbb_common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"backtrace",
|
||||
"bytes",
|
||||
"chrono",
|
||||
"confy",
|
||||
@ -2608,6 +2608,7 @@ dependencies = [
|
||||
"futures",
|
||||
"futures-util",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"mac_address",
|
||||
"machine-uid",
|
||||
@ -4813,7 +4814,6 @@ dependencies = [
|
||||
"arboard",
|
||||
"async-process",
|
||||
"async-trait",
|
||||
"backtrace",
|
||||
"base64",
|
||||
"bytes",
|
||||
"cc",
|
||||
@ -4847,7 +4847,6 @@ dependencies = [
|
||||
"include_dir",
|
||||
"jni 0.19.0",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"libpulse-binding",
|
||||
"libpulse-simple-binding",
|
||||
"mac_address",
|
||||
@ -5046,7 +5045,6 @@ dependencies = [
|
||||
"hwcodec",
|
||||
"jni 0.19.0",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"ndk 0.7.0",
|
||||
"num_cpus",
|
||||
|
@ -43,7 +43,6 @@ cfg-if = "1.0"
|
||||
lazy_static = "1.4"
|
||||
sha2 = "0.10"
|
||||
repng = "0.2"
|
||||
libc = "0.2"
|
||||
parity-tokio-ipc = { git = "https://github.com/open-trade/parity-tokio-ipc" }
|
||||
flexi_logger = { version = "0.22", features = ["async", "use_chrono_for_offset"] }
|
||||
runas = "0.2"
|
||||
@ -121,7 +120,6 @@ mouce = { git="https://github.com/fufesou/mouce.git" }
|
||||
evdev = { git="https://github.com/fufesou/evdev" }
|
||||
dbus = "0.9"
|
||||
dbus-crossroads = "0.5"
|
||||
backtrace = "0.3"
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
android_logger = "0.11"
|
||||
|
@ -37,8 +37,5 @@ core-graphics = "0.22"
|
||||
objc = "0.2"
|
||||
unicode-segmentation = "1.6"
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
pkg-config = "0.3"
|
||||
|
@ -1,8 +1,6 @@
|
||||
use libc;
|
||||
|
||||
use crate::{Key, KeyboardControllable, MouseButton, MouseControllable};
|
||||
|
||||
use self::libc::{c_char, c_int, c_void, useconds_t};
|
||||
use hbb_common::libc::{c_char, c_int, c_void, useconds_t};
|
||||
use std::{borrow::Cow, ffi::CString, ptr};
|
||||
|
||||
const CURRENT_WINDOW: c_int = 0;
|
||||
|
@ -31,6 +31,8 @@ sodiumoxide = "0.2"
|
||||
regex = "1.4"
|
||||
tokio-socks = { git = "https://github.com/open-trade/tokio-socks" }
|
||||
chrono = "0.4"
|
||||
backtrace = "0.3"
|
||||
libc = "0.2"
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
mac_address = "1.1"
|
||||
|
@ -39,6 +39,7 @@ pub use tokio_socks::IntoTargetAddr;
|
||||
pub use tokio_socks::TargetAddr;
|
||||
pub mod password_security;
|
||||
pub use chrono;
|
||||
pub use libc;
|
||||
pub use directories_next;
|
||||
pub mod keyboard;
|
||||
|
||||
|
@ -1,2 +1,85 @@
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod linux;
|
||||
|
||||
use crate::{log, config::Config, ResultType};
|
||||
use std::{collections::HashMap, process::{Command, exit}};
|
||||
|
||||
extern "C" fn breakdown_signal_handler(sig: i32) {
|
||||
let mut stack = vec![];
|
||||
backtrace::trace(|frame| {
|
||||
backtrace::resolve_frame(frame, |symbol| {
|
||||
if let Some(name) = symbol.name() {
|
||||
stack.push(name.to_string());
|
||||
}
|
||||
});
|
||||
true // keep going to the next frame
|
||||
});
|
||||
let mut info = String::default();
|
||||
if stack.iter().any(|s| {
|
||||
s.contains(&"nouveau_pushbuf_kick")
|
||||
|| s.to_lowercase().contains("nvidia")
|
||||
|| s.contains("gdk_window_end_draw_frame")
|
||||
}) {
|
||||
Config::set_option("allow-always-software-render".to_string(), "Y".to_string());
|
||||
info = "Always use software rendering will be set.".to_string();
|
||||
log::info!("{}", info);
|
||||
}
|
||||
log::error!(
|
||||
"Got signal {} and exit. stack:\n{}",
|
||||
sig,
|
||||
stack.join("\n").to_string()
|
||||
);
|
||||
if !info.is_empty() {
|
||||
system_message(
|
||||
"RustDesk",
|
||||
&format!("Got signal {} and exit.{}", sig, info),
|
||||
true,
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/// forever: may not work
|
||||
pub fn system_message(title: &str, msg: &str, forever: bool) -> ResultType<()> {
|
||||
let cmds: HashMap<&str, Vec<&str>> = HashMap::from([
|
||||
("notify-send", [title, msg].to_vec()),
|
||||
(
|
||||
"zenity",
|
||||
[
|
||||
"--info",
|
||||
"--timeout",
|
||||
if forever { "0" } else { "3" },
|
||||
"--title",
|
||||
title,
|
||||
"--text",
|
||||
msg,
|
||||
]
|
||||
.to_vec(),
|
||||
),
|
||||
("kdialog", ["--title", title, "--msgbox", msg].to_vec()),
|
||||
(
|
||||
"xmessage",
|
||||
[
|
||||
"-center",
|
||||
"-timeout",
|
||||
if forever { "0" } else { "3" },
|
||||
title,
|
||||
msg,
|
||||
]
|
||||
.to_vec(),
|
||||
),
|
||||
]);
|
||||
for (k, v) in cmds {
|
||||
if Command::new(k).args(v).spawn().is_ok() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
crate::bail!("failed to post system message");
|
||||
}
|
||||
|
||||
pub fn register_breakdown_handler() {
|
||||
unsafe {
|
||||
libc::signal(libc::SIGSEGV, breakdown_signal_handler as _);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ mediacodec = ["ndk"]
|
||||
[dependencies]
|
||||
block = "0.1"
|
||||
cfg-if = "1.0"
|
||||
libc = "0.2"
|
||||
num_cpus = "1.13"
|
||||
lazy_static = "1.4"
|
||||
hbb_common = { path = "../hbb_common" }
|
||||
|
@ -2,7 +2,7 @@
|
||||
extern crate block;
|
||||
#[macro_use]
|
||||
extern crate cfg_if;
|
||||
pub extern crate libc;
|
||||
pub use hbb_common::libc;
|
||||
#[cfg(dxgi)]
|
||||
extern crate winapi;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::ptr;
|
||||
|
||||
use block::{Block, ConcreteBlock};
|
||||
use libc::c_void;
|
||||
use hbb_common::libc::c_void;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::config::Config;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::ptr;
|
||||
|
||||
use libc::c_void;
|
||||
use hbb_common::libc::c_void;
|
||||
|
||||
use super::ffi::*;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use block::RcBlock;
|
||||
use libc::c_void;
|
||||
use hbb_common::libc::c_void;
|
||||
|
||||
pub type CGDisplayStreamRef = *mut c_void;
|
||||
pub type CFDictionaryRef = *mut c_void;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::{io, ptr, slice};
|
||||
|
||||
use libc;
|
||||
use hbb_common::libc;
|
||||
|
||||
use super::ffi::*;
|
||||
use super::Display;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
use libc::c_void;
|
||||
use hbb_common::libc::c_void;
|
||||
|
||||
#[link(name = "xcb")]
|
||||
#[link(name = "xcb-shm")]
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
|
||||
use libc;
|
||||
use hbb_common::libc;
|
||||
|
||||
use super::ffi::*;
|
||||
use super::{Display, Rect, Server};
|
||||
|
@ -101,7 +101,7 @@ pub fn get_key_state(key: enigo::Key) -> bool {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "android")] {
|
||||
|
||||
use libc::{c_float, c_int, c_void};
|
||||
use hbb_common::libc::{c_float, c_int, c_void};
|
||||
type Oboe = *mut c_void;
|
||||
extern "C" {
|
||||
fn create_oboe_player(channels: c_int, sample_rate: c_int) -> Oboe;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use hbb_common::log;
|
||||
use hbb_common::{log, platform::register_breakdown_handler};
|
||||
|
||||
/// shared by flutter and sciter main function
|
||||
///
|
||||
@ -38,10 +38,10 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
register_breakdown_handler();
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "flutter")]
|
||||
{
|
||||
crate::platform::linux::register_breakdown_handler();
|
||||
let (k, v) = ("LIBGL_ALWAYS_SOFTWARE", "true");
|
||||
if !hbb_common::config::Config::get_option("allow-always-software-render").is_empty() {
|
||||
std::env::set_var(k, v);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::{CursorData, ResultType};
|
||||
pub use hbb_common::platform::linux::*;
|
||||
use hbb_common::{allow_err, bail, log};
|
||||
use libc::{c_char, c_int, c_void};
|
||||
use hbb_common::libc::{c_char, c_int, c_void};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::HashMap,
|
||||
@ -642,86 +642,3 @@ pub fn get_double_click_time() -> u32 {
|
||||
double_click_time
|
||||
}
|
||||
}
|
||||
|
||||
/// forever: may not work
|
||||
pub fn system_message(title: &str, msg: &str, forever: bool) -> ResultType<()> {
|
||||
let cmds: HashMap<&str, Vec<&str>> = HashMap::from([
|
||||
("notify-send", [title, msg].to_vec()),
|
||||
(
|
||||
"zenity",
|
||||
[
|
||||
"--info",
|
||||
"--timeout",
|
||||
if forever { "0" } else { "3" },
|
||||
"--title",
|
||||
title,
|
||||
"--text",
|
||||
msg,
|
||||
]
|
||||
.to_vec(),
|
||||
),
|
||||
("kdialog", ["--title", title, "--msgbox", msg].to_vec()),
|
||||
(
|
||||
"xmessage",
|
||||
[
|
||||
"-center",
|
||||
"-timeout",
|
||||
if forever { "0" } else { "3" },
|
||||
title,
|
||||
msg,
|
||||
]
|
||||
.to_vec(),
|
||||
),
|
||||
]);
|
||||
for (k, v) in cmds {
|
||||
if std::process::Command::new(k).args(v).spawn().is_ok() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
bail!("failed to post system message");
|
||||
}
|
||||
|
||||
extern "C" fn breakdown_signal_handler(sig: i32) {
|
||||
let mut stack = vec![];
|
||||
backtrace::trace(|frame| {
|
||||
backtrace::resolve_frame(frame, |symbol| {
|
||||
if let Some(name) = symbol.name() {
|
||||
stack.push(name.to_string());
|
||||
}
|
||||
});
|
||||
true // keep going to the next frame
|
||||
});
|
||||
let mut info = String::default();
|
||||
if stack.iter().any(|s| {
|
||||
s.contains(&"nouveau_pushbuf_kick")
|
||||
|| s.to_lowercase().contains("nvidia")
|
||||
|| s.contains("gdk_window_end_draw_frame")
|
||||
}) {
|
||||
hbb_common::config::Config::set_option(
|
||||
"allow-always-software-render".to_string(),
|
||||
"Y".to_string(),
|
||||
);
|
||||
info = "Always use software rendering will be set.".to_string();
|
||||
log::info!("{}", info);
|
||||
}
|
||||
log::error!(
|
||||
"Got signal {} and exit. stack:\n{}",
|
||||
sig,
|
||||
stack.join("\n").to_string()
|
||||
);
|
||||
if !info.is_empty() {
|
||||
system_message(
|
||||
"RustDesk",
|
||||
&format!("Got signal {} and exit.{}", sig, info),
|
||||
true,
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
pub fn register_breakdown_handler() {
|
||||
unsafe {
|
||||
libc::signal(libc::SIGSEGV, breakdown_signal_handler as _);
|
||||
}
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ pub mod client {
|
||||
let mut option = SHMEM.lock().unwrap();
|
||||
let shmem = option.as_mut().unwrap();
|
||||
unsafe {
|
||||
libc::memset(shmem.as_ptr() as _, 0, shmem.len() as _);
|
||||
hbb_common::libc::memset(shmem.as_ptr() as _, 0, shmem.len() as _);
|
||||
}
|
||||
drop(option);
|
||||
match para {
|
||||
|
Loading…
Reference in New Issue
Block a user