General QoL changes

This commit is contained in:
topjohnwu
2019-12-13 00:37:06 -05:00
parent 8c500709e4
commit af060b3132
22 changed files with 205 additions and 213 deletions

View File

@@ -197,10 +197,10 @@ int main(int argc, char *argv[]) {
return test_main(argc, argv);
#endif
if (argc > 1 && strcmp(argv[1], "-x") == 0) {
if (strcmp(argv[2], "magisk") == 0)
if (argc > 1 && argv[1] == "-x"sv) {
if (argv[2] == "magisk"sv)
return dump_magisk(argv[3], 0755);
else if (strcmp(argv[2], "manager") == 0)
else if (argv[2] == "manager"sv)
return dump_manager(argv[3], 0644);
}
@@ -208,27 +208,28 @@ int main(int argc, char *argv[]) {
return 1;
setup_klog();
if (argc > 1 && argv[1] == "selinux_setup"sv) {
auto init = make_unique<SecondStageInit>(argv);
init->start();
}
cmdline cmd{};
load_kernel_info(&cmd);
unique_ptr<BaseInit> init;
if (cmd.force_normal_boot) {
init = make_unique<ABFirstStageInit>(argv, &cmd);
} else if (cmd.skip_initramfs) {
init = make_unique<SARInit>(argv, &cmd);
cmdline cmd{};
if (argc > 1 && argv[1] == "selinux_setup"sv) {
init = make_unique<SecondStageInit>(argv);
} else {
decompress_ramdisk();
if (access("/sbin/recovery", F_OK) == 0 || access("/system/bin/recovery", F_OK) == 0)
init = make_unique<RecoveryInit>(argv, &cmd);
else if (access("/apex", F_OK) == 0)
init = make_unique<AFirstStageInit>(argv, &cmd);
else
init = make_unique<RootFSInit>(argv, &cmd);
// This will also mount /sys and /proc
load_kernel_info(&cmd);
if (cmd.force_normal_boot) {
init = make_unique<ABFirstStageInit>(argv, &cmd);
} else if (cmd.skip_initramfs) {
init = make_unique<SARInit>(argv, &cmd);
} else {
decompress_ramdisk();
if (access("/sbin/recovery", F_OK) == 0 || access("/system/bin/recovery", F_OK) == 0)
init = make_unique<RecoveryInit>(argv, &cmd);
else if (access("/apex", F_OK) == 0)
init = make_unique<AFirstStageInit>(argv, &cmd);
else
init = make_unique<RootFSInit>(argv, &cmd);
}
}
// Run the main routine

View File

@@ -44,17 +44,15 @@ static void parse_device(devinfo *dev, const char *uevent) {
static void collect_devices() {
char path[128];
devinfo dev{};
DIR *dir = xopendir("/sys/dev/block");
if (dir == nullptr)
return;
for (dirent *entry; (entry = readdir(dir));) {
if (entry->d_name == "."sv || entry->d_name == ".."sv)
continue;
sprintf(path, "/sys/dev/block/%s/uevent", entry->d_name);
parse_device(&dev, path);
dev_list.push_back(dev);
if (auto dir = xopen_dir("/sys/dev/block"); dir) {
for (dirent *entry; (entry = readdir(dir.get()));) {
if (entry->d_name == "."sv || entry->d_name == ".."sv)
continue;
sprintf(path, "/sys/dev/block/%s/uevent", entry->d_name);
parse_device(&dev, path);
dev_list.push_back(dev);
}
}
closedir(dir);
}
static int64_t setup_block(bool write_block = true) {

View File

@@ -426,17 +426,16 @@ static void patch_fstab(const string &fstab) {
#define FSR "/first_stage_ramdisk"
void ABFirstStageInit::prepare() {
DIR *dir = xopendir(FSR);
auto dir = xopen_dir(FSR);
if (!dir)
return;
string fstab(FSR "/");
for (dirent *de; (de = readdir(dir));) {
for (dirent *de; (de = xreaddir(dir.get()));) {
if (strstr(de->d_name, "fstab")) {
fstab += de->d_name;
break;
}
}
closedir(dir);
if (fstab.length() == sizeof(FSR))
return;
@@ -453,14 +452,13 @@ void ABFirstStageInit::prepare() {
}
void AFirstStageInit::prepare() {
DIR *dir = xopendir("/");
for (dirent *de; (de = readdir(dir));) {
auto dir = xopen_dir("/");
for (dirent *de; (de = xreaddir(dir.get()));) {
if (strstr(de->d_name, "fstab")) {
patch_fstab(de->d_name);
break;
}
}
closedir(dir);
// Move stuffs for next stage
xmkdir("/system", 0755);