int uevent_dump_main(int argc, char *argv[]) { int opt; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int long_index = 0; while ((opt = getopt_long(argc, argv, "h", long_options, &long_index)) != -1) { switch (opt) { case 'h': uevent_dump_usage(false); return EXIT_SUCCESS; default: uevent_dump_usage(true); return EXIT_FAILURE; } } // There should be no other arguments if (argc - optind != 0) { uevent_dump_usage(true); return EXIT_FAILURE; } LOGV("mbtool version %s (%s)", get_mbtool_version(), get_git_version()); // Start probing for devices device_init(true); // Kill uevent thread and close uevent socket device_close(); return EXIT_SUCCESS; }
int init_main(int argc, char *argv[]) { for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { init_usage(true); return EXIT_SUCCESS; } } umask(0); mkdir("/dev", 0755); mkdir("/proc", 0755); mkdir("/sys", 0755); mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755"); mkdir("/dev/pts", 0755); mkdir("/dev/socket", 0755); mount("devpts", "/dev/pts", "devpts", 0, nullptr); mount("proc", "/proc", "proc", 0, nullptr); mount("sysfs", "/sys", "sysfs", 0, nullptr); open_devnull_stdio(); util::log_set_logger(std::make_shared<util::KmsgLogger>()); if (klogctl(KLOG_CONSOLE_LEVEL, nullptr, 8) < 0) { LOGE("Failed to set loglevel: %s", strerror(errno)); } LOGV("Booting up with version %s (%s)", get_mbtool_version(), get_git_version()); // Start probing for devices device_init(); std::string fstab = find_fstab(); if (fstab.empty()) { LOGE("Failed to find a suitable fstab file"); emergency_reboot(); return EXIT_FAILURE; } mkdir("/system", 0755); mkdir("/cache", 0770); mkdir("/data", 0771); util::chown("/cache", "system", "cache", 0); util::chown("/data", "system", "system", 0); fix_arter97(); // Mount fstab and write new redacted version if (!mount_fstab(fstab, true)) { LOGE("Failed to mount fstab"); emergency_reboot(); return EXIT_FAILURE; } LOGE("Successfully mounted fstab"); fix_file_contexts(); add_mbtool_services(); strip_manual_mounts(); struct stat sb; if (stat("/sepolicy", &sb) == 0) { if (!patch_sepolicy("/sepolicy", "/sepolicy")) { LOGW("Failed to patch /sepolicy"); emergency_reboot(); return EXIT_FAILURE; } } // Kill uevent thread and close uevent socket device_close(); // Unmount partitions umount("/dev/pts"); umount("/dev"); umount("/proc"); umount("/sys"); // Do not remove these as Android 6.0 init's stage 1 no longer creates these // (platform/system/core commit a1f6a4b13921f61799be14a2544bdbf95958eae7) //rmdir("/dev"); //rmdir("/proc"); //rmdir("/sys"); // Start real init unlink("/init"); rename("/init.orig", "/init"); LOGD("Launching real init ..."); execlp("/init", "/init", nullptr); LOGE("Failed to exec real init: %s", strerror(errno)); emergency_reboot(); return EXIT_FAILURE; }