Add new util function
This commit is contained in:
parent
6785dc4967
commit
23d3e56967
@ -525,7 +525,7 @@ static void dump_logs() {
|
||||
rename(LOGFILE, LOGFILE ".bak");
|
||||
log_dump = true;
|
||||
// Start a daemon thread and wait indefinitely
|
||||
new_daemon_thread([](auto) -> void* {
|
||||
new_daemon_thread([]() -> void {
|
||||
int fd = xopen(LOGFILE, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
|
||||
exec_t exec {
|
||||
.fd = fd,
|
||||
@ -535,10 +535,9 @@ static void dump_logs() {
|
||||
close(fd);
|
||||
if (pid < 0) {
|
||||
log_dump = false;
|
||||
return nullptr;
|
||||
} else {
|
||||
waitpid(pid, nullptr, 0);
|
||||
}
|
||||
waitpid(pid, nullptr, 0);
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -322,10 +322,7 @@ void auto_start_magiskhide() {
|
||||
db_settings dbs;
|
||||
get_db_settings(dbs, HIDE_CONFIG);
|
||||
if (dbs[HIDE_CONFIG]) {
|
||||
new_daemon_thread([](auto) -> void* {
|
||||
launch_magiskhide(-1);
|
||||
return nullptr;
|
||||
});
|
||||
new_daemon_thread([]() -> void { launch_magiskhide(-1); });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,6 +208,7 @@ int parse_int(S __s) { return parse_int(__s.data()); }
|
||||
|
||||
int new_daemon_thread(void *(*start_routine) (void *), void *arg = nullptr,
|
||||
const pthread_attr_t *attr = nullptr);
|
||||
int new_daemon_thread(std::function<void()> &&fn);
|
||||
|
||||
struct exec_t {
|
||||
bool err = false;
|
||||
|
@ -200,6 +200,17 @@ int new_daemon_thread(void *(*start_routine) (void *), void *arg, const pthread_
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void *proxy_routine(void *fp) {
|
||||
auto fn = reinterpret_cast<std::function<void()>*>(fp);
|
||||
(*fn)();
|
||||
delete fn;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int new_daemon_thread(std::function<void()> &&fn) {
|
||||
return new_daemon_thread(proxy_routine, new std::function<void()>(std::move(fn)));
|
||||
}
|
||||
|
||||
static char *argv0;
|
||||
static size_t name_len;
|
||||
void init_argv0(int argc, char **argv) {
|
||||
|
Loading…
Reference in New Issue
Block a user