Fix MagiskHide unmount daemon

Close #1101
This commit is contained in:
topjohnwu
2019-02-19 01:50:41 -05:00
parent 3ebc886f8a
commit 660e0dc09a
2 changed files with 42 additions and 19 deletions

View File

@@ -146,11 +146,7 @@ void write_zero(int fd, size_t size);
#define str_contains(s, ss) ((ss) != nullptr && (s).find(ss) != std::string::npos)
#define str_starts(s, ss) ((ss) != nullptr && (s).compare(0, strlen(ss), ss) == 0)
// file.cpp
void file_readline(const char *filename, const std::function<bool (std::string_view&)> &fn, bool trim = false);
// misc.cpp
// RAII
class MutexGuard {
public:
@@ -170,6 +166,22 @@ private:
pthread_mutex_t *mutex;
};
class RunFinally {
public:
explicit RunFinally(std::function<void()> &&fn): fn(std::move(fn)) {}
~RunFinally() { fn(); }
private:
const std::function<void ()> fn;
};
// file.cpp
void file_readline(const char *filename, const std::function<bool (std::string_view&)> &fn, bool trim = false);
// misc.cpp
int new_daemon_thread(void *(*start_routine) (void *), void *arg = nullptr,
const pthread_attr_t *attr = nullptr);