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