Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <errno.h>
- #include <error.h>
- #include <limits.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/mount.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- extern char **environ;
- int run()
- {
- const char * const root = "/dev/md/Volume0_0p3";
- const char * const rootfs = "xfs";
- char real_root[PATH_MAX];
- int retval = EXIT_SUCCESS;
- pid_t child;
- // mount /sys and /proc
- if (mount("proc", "/proc", "proc", MS_MGC_VAL, NULL) == -1)
- { error(0, errno, "mount -t proc proc /proc failed with error %d", errno); return errno; }
- if (mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL) == -1)
- { error(0, errno, "mount -t sysfs sysfs /sys failed with error %d", errno); return errno; }
- // run mdadm
- child = vfork();
- if (child == 0) { execl("/sbin/mdadm", "/sbin/mdadm", "--assemble", "--scan", "--auto=mdp", NULL); }
- else
- {
- siginfo_t info;
- waitid(P_PID, child, &info, WEXITED);
- retval = info.si_status;
- }
- if (retval != EXIT_SUCCESS) { error(0, 0, "mdadm --assemble --scan --auto=mdp exited with status %d, aborting.\n", retval); return retval; }
- // mount /
- if (realpath(root, real_root) == NULL)
- { error(0, errno, "realpath %s failed with error %d", root, errno); return errno; }
- if (mount(real_root, "/", rootfs, MS_MGC_VAL|MS_RDONLY, NULL) == -1)
- { error(0, errno, "mount -o ro -t %s %s / failed with error %d", rootfs, root, errno); return errno; }
- // run init
- retval = execl("/sbin/init", "/sbin/init", NULL);
- if (retval == -1) { error(0, errno, "/sbin/init failed with error %d", errno); return errno; }
- else if (retval != EXIT_SUCCESS) { error(0, 0, "init exited with status %d, aborting.\n", retval); return retval; }
- return EXIT_SUCCESS;
- }
- int main (int argc, const char * const argv[])
- {
- int retval = run();
- sleep(30);
- return retval;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement