Migrate connect_daemon to Rust

This commit is contained in:
topjohnwu
2025-09-15 14:25:18 -07:00
committed by John Wu
parent 4aed644e08
commit cf483ad4d2
8 changed files with 100 additions and 90 deletions
+3 -3
View File
@@ -158,10 +158,10 @@ void init_argv0(int argc, char **argv) {
name_len = (argv[argc - 1] - argv[0]) + strlen(argv[argc - 1]) + 1;
}
void set_nice_name(const char *name) {
void set_nice_name(Utf8CStr name) {
memset(argv0, 0, name_len);
strscpy(argv0, name, name_len);
prctl(PR_SET_NAME, name);
strscpy(argv0, name.c_str(), name_len);
prctl(PR_SET_NAME, name.c_str());
}
template<typename T, int base>
+2 -1
View File
@@ -10,7 +10,7 @@ pub use cstr::{
};
use cxx_extern::*;
pub use dir::*;
pub use ffi::{Utf8CStrRef, fork_dont_care};
pub use ffi::{Utf8CStrRef, fork_dont_care, set_nice_name};
pub use files::*;
pub use logging::*;
pub use misc::*;
@@ -46,6 +46,7 @@ mod ffi {
fn mut_u8_patch(buf: &mut [u8], from: &[u8], to: &[u8]) -> Vec<usize>;
fn fork_dont_care() -> i32;
fn set_nice_name(name: Utf8CStrRef);
type FnBoolStrStr;
fn call(self: &FnBoolStrStr, key: &str, value: &str) -> bool;
+4 -2
View File
@@ -18,6 +18,8 @@ clazz(const clazz&) = delete; \
clazz(clazz &&o) { swap(o); } \
clazz& operator=(clazz &&o) { swap(o); return *this; }
struct Utf8CStr;
class mutex_guard {
DISALLOW_COPY_AND_MOVE(mutex_guard)
public:
@@ -146,7 +148,7 @@ static inline std::string rtrim(std::string &&s) {
int fork_dont_care();
int fork_no_orphan();
void init_argv0(int argc, char **argv);
void set_nice_name(const char *name);
void set_nice_name(Utf8CStr name);
int switch_mnt_ns(int pid);
std::string &replace_all(std::string &str, std::string_view from, std::string_view to);
std::vector<std::string> split(std::string_view s, std::string_view delims);
@@ -245,4 +247,4 @@ struct FnBoolStr : public CxxFnBoolStr {
bool call(Utf8CStr s) const {
return operator()(s);
}
};
};