diff --git a/native/jni/core/bootstages.cpp b/native/jni/core/bootstages.cpp index e592c0feb..35a3eac49 100644 --- a/native/jni/core/bootstages.cpp +++ b/native/jni/core/bootstages.cpp @@ -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; }); } diff --git a/native/jni/magiskhide/hide_utils.cpp b/native/jni/magiskhide/hide_utils.cpp index 839155111..d469d1b7f 100644 --- a/native/jni/magiskhide/hide_utils.cpp +++ b/native/jni/magiskhide/hide_utils.cpp @@ -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); }); } } diff --git a/native/jni/utils/include/utils.h b/native/jni/utils/include/utils.h index 12292d37f..d88aa7b6d 100644 --- a/native/jni/utils/include/utils.h +++ b/native/jni/utils/include/utils.h @@ -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 &&fn); struct exec_t { bool err = false; diff --git a/native/jni/utils/misc.cpp b/native/jni/utils/misc.cpp index b82a06006..4a8ba0b53 100644 --- a/native/jni/utils/misc.cpp +++ b/native/jni/utils/misc.cpp @@ -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*>(fp); + (*fn)(); + delete fn; + return nullptr; +} + +int new_daemon_thread(std::function &&fn) { + return new_daemon_thread(proxy_routine, new std::function(std::move(fn))); +} + static char *argv0; static size_t name_len; void init_argv0(int argc, char **argv) {