mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-29 13:27:38 +00:00
Cleanup implementations
This commit is contained in:
parent
ae0d605310
commit
aabe2696fe
@ -1,10 +1,3 @@
|
||||
#include <sys/mount.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
|
||||
#include <utils.hpp>
|
||||
|
||||
#include "raw_data.hpp"
|
||||
@ -50,16 +43,10 @@ protected:
|
||||
char **argv;
|
||||
std::vector<std::string> mount_list;
|
||||
|
||||
void exec_init() {
|
||||
cleanup();
|
||||
execv("/init", argv);
|
||||
exit(1);
|
||||
}
|
||||
virtual void cleanup();
|
||||
[[noreturn]] void exec_init();
|
||||
void read_dt_fstab(std::vector<fstab_entry> &fstab);
|
||||
public:
|
||||
BaseInit(char *argv[], cmdline *cmd) :
|
||||
cmd(cmd), argv(argv), mount_list{"/sys", "/proc"} {}
|
||||
BaseInit(char *argv[], cmdline *cmd) : cmd(cmd), argv(argv), mount_list{"/sys", "/proc"} {}
|
||||
virtual ~BaseInit() = default;
|
||||
virtual void start() = 0;
|
||||
};
|
||||
@ -82,17 +69,11 @@ class SARBase : public MagiskInit {
|
||||
protected:
|
||||
std::vector<raw_file> overlays;
|
||||
|
||||
virtual void early_mount() = 0;
|
||||
void backup_files();
|
||||
void patch_rootdir();
|
||||
void mount_system_root();
|
||||
public:
|
||||
SARBase(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {}
|
||||
void start() override {
|
||||
early_mount();
|
||||
patch_rootdir();
|
||||
exec_init();
|
||||
}
|
||||
};
|
||||
|
||||
/***************
|
||||
@ -113,14 +94,19 @@ public:
|
||||
};
|
||||
|
||||
class SecondStageInit : public SARBase {
|
||||
protected:
|
||||
void early_mount() override;
|
||||
private:
|
||||
void prepare();
|
||||
public:
|
||||
SecondStageInit(char *argv[]) : SARBase(argv, nullptr) {
|
||||
LOGD("%s\n", __FUNCTION__);
|
||||
// Do not unmount /sys and /proc
|
||||
mount_list.clear();
|
||||
};
|
||||
void start() override {
|
||||
prepare();
|
||||
patch_rootdir();
|
||||
exec_init();
|
||||
}
|
||||
};
|
||||
|
||||
/*************
|
||||
@ -130,9 +116,9 @@ public:
|
||||
class SARInit : public SARBase {
|
||||
private:
|
||||
bool is_two_stage;
|
||||
|
||||
void early_mount();
|
||||
void first_stage_prep();
|
||||
protected:
|
||||
void early_mount() override;
|
||||
public:
|
||||
SARInit(char *argv[], cmdline *cmd) : SARBase(argv, cmd), is_two_stage(false) {
|
||||
LOGD("%s\n", __FUNCTION__);
|
||||
@ -153,16 +139,15 @@ public:
|
||||
|
||||
class RootFSInit : public MagiskInit {
|
||||
private:
|
||||
void setup_rootfs();
|
||||
void early_mount();
|
||||
void patch_rootfs();
|
||||
public:
|
||||
RootFSInit(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {
|
||||
LOGD("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void start() override {
|
||||
early_mount();
|
||||
setup_rootfs();
|
||||
patch_rootfs();
|
||||
exec_init();
|
||||
}
|
||||
};
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include <sys/mount.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
#include <vector>
|
||||
|
||||
#include <utils.hpp>
|
||||
#include <selinux.hpp>
|
||||
@ -357,7 +355,7 @@ void SARInit::early_mount() {
|
||||
}
|
||||
}
|
||||
|
||||
void SecondStageInit::early_mount() {
|
||||
void SecondStageInit::prepare() {
|
||||
backup_files();
|
||||
|
||||
umount2("/init", MNT_DETACH);
|
||||
@ -367,14 +365,14 @@ void SecondStageInit::early_mount() {
|
||||
switch_root("/system_root");
|
||||
}
|
||||
|
||||
void BaseInit::cleanup() {
|
||||
void BaseInit::exec_init() {
|
||||
// Unmount in reverse order
|
||||
for (auto &p : reversed(mount_list)) {
|
||||
if (xumount(p.data()) == 0)
|
||||
LOGD("Unmount [%s]\n", p.data());
|
||||
}
|
||||
mount_list.clear();
|
||||
mount_list.shrink_to_fit();
|
||||
execv("/init", argv);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void patch_socket_name(const char *path) {
|
||||
|
@ -1,7 +1,4 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <vector>
|
||||
#include <sys/mount.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <magisk.hpp>
|
||||
@ -293,7 +290,7 @@ void SARBase::patch_rootdir() {
|
||||
#define TMP_MNTDIR "/dev/mnt"
|
||||
#define TMP_RULESDIR "/.backup/.sepolicy.rules"
|
||||
|
||||
void RootFSInit::setup_rootfs() {
|
||||
void RootFSInit::patch_rootfs() {
|
||||
// Handle custom sepolicy rules
|
||||
xmkdir(TMP_MNTDIR, 0755);
|
||||
mount_rules_dir("/dev/block", TMP_MNTDIR);
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <magisk.hpp>
|
||||
#include <utils.hpp>
|
||||
#include <socket.hpp>
|
||||
|
Loading…
x
Reference in New Issue
Block a user