aboutsummaryrefslogtreecommitdiff
path: root/minit.c
blob: 7ea96889fc6898b68651ad6e5476a4dd42b1389a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <linux/reboot.h>
#include <sys/mount.h>
#include <sys/reboot.h>
#include <sys/syscall.h>

[[noreturn]]
int main(int argc, char *argv[])
{
	if (argc < 2) {
		puts("usage: minit <command>");
		exit(1);
	}

	int rc = mount("proc", "/proc", "proc", 0, NULL);
	if (rc)
		puts("warning: unable to mount proc!");

	rc = mount("sysfs", "/sys", "sysfs", 0, NULL);
	if (rc) {
		puts("warning: unable to mount sysfs!");
	} else {
		rc = mount("debugfs", "/sys/kernel/debug", "debugfs", 0, NULL);
		if (rc)
			puts("warning: unable to mount debugfs!");
	}

	rc = system(argv[1]);
	if (rc) {
		puts("the command exited with failure");
	}

	sync();
	rc = reboot(LINUX_REBOOT_CMD_HALT);
	/* If we made it here something went wrong with the reboot command */
	exit(rc);
}