Skip to content

Commit

Permalink
refactor: 合并 daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
Mufanc committed Dec 10, 2023
1 parent c1337d2 commit 8a9dc21
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 255 deletions.
5 changes: 1 addition & 4 deletions PKGBUILD.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ sha256sums=()
build() {
cd "$PKGROOT/daemon"
cargo build --release

cd "$PKGROOT/inject"
cargo build --release
}

package() {
Expand All @@ -35,7 +32,7 @@ package() {
mv "$pkgdir/opt/QQ/qq" "$pkgdir/opt/QQ/main"
cp "$srcdir/launcher.sh" "$pkgdir/opt/QQ/launcher.sh"
cp "$PKGROOT/daemon/target/release/daemon" "$pkgdir/opt/QQ/qq"
cp "$PKGROOT/inject/target/release/libinject.so" "$pkgdir/opt/QQ/libinject.so"
cp "$PKGROOT/daemon/target/release/libinject.so" "$pkgdir/opt/QQ/libinject.so"

# 处理 crash
res="$pkgdir/opt/QQ/resources/app"
Expand Down
2 changes: 0 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set -ex

export SOURCE=$(curl -s https://im.qq.com/rainbow/linuxQQDownload/ | grep -Eo '"deb":"[^"]+"' | grep -Eo 'https://.*_amd64\.deb')
export PKGVER=$(echo "$SOURCE" | awk -F "linuxqq_|-" '{print $2}')
export PKGROOT=$(realpath "$(dirname "$0")")
Expand Down
164 changes: 164 additions & 0 deletions daemon/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ name = "daemon"
version = "0.1.0"
edition = "2021"

[lib]
name = "inject"
crate-type = ["cdylib"]
path = "src/inject.rs"

[[bin]]
name = "daemon"
path = "src/daemon.rs"

[dependencies]
anyhow = "1.0.75"
ctor = "0.2.5"
goblin = "0.7.1"
nix = { version = "0.27.1", features = ["socket", "process"] }
once_cell = "1.19.0"
url = "2.5.0"
1 change: 1 addition & 0 deletions daemon/src/configs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const SERVER_ADDRESS: &str = "qwrapper-daemon";
6 changes: 3 additions & 3 deletions daemon/src/main.rs → daemon/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use nix::sys::signal::Signal;
use nix::sys::socket;
use nix::sys::socket::{AddressFamily, MsgFlags, SockFlag, SockType, UnixAddr};

const BIND_ADDRESS: &str = "qwrapper-daemon";
mod configs;


fn bind_server(fd: &OwnedFd) -> Result<()> {
let addr = &UnixAddr::new_abstract(BIND_ADDRESS.as_bytes())?;
let addr = &UnixAddr::new_abstract(configs::SERVER_ADDRESS.as_bytes())?;

if let Err(err) = socket::bind(fd.as_raw_fd(), addr) {
if err != Errno::EADDRINUSE {
Expand Down Expand Up @@ -86,7 +86,7 @@ fn main() -> Result<()> {
bind_server(&fd)?;

let listener = UnixListener::from(fd);
println!("daemon is listening on @{BIND_ADDRESS}");
println!("daemon is listening on @{}", configs::SERVER_ADDRESS);

prctl::set_pdeathsig(Signal::SIGKILL)?;

Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion inject/src/lib.rs → daemon/src/inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use once_cell::sync::Lazy;
use url::Url;

mod dlopt;
mod configs;

static SERVER_ADDRESS: Lazy<UnixAddr> = Lazy::new(|| {
UnixAddr::new_abstract("qwrapper-daemon".as_bytes()).unwrap()
UnixAddr::new_abstract(configs::SERVER_ADDRESS.as_bytes()).unwrap()
});


Expand Down
1 change: 0 additions & 1 deletion inject/.gitignore

This file was deleted.

Loading

0 comments on commit 8a9dc21

Please sign in to comment.