summaryrefslogtreecommitdiff
path: root/minit.c
blob: 323c688501fc0789cdced44b639dd3be7376681c (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
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
 * minit.c - A minimal init; as stupid as it gets.
 *
 * Copyright (c) 2025 - Yaroslav de la Peña Smirnov <yps@yaroslavps.com>
 *
 * This is free software, which you can redistribute and/or modify under the
 * terms of the GNU General Public License, version 2.0 only. For more
 * information read the COPYING and LICENSE files provided in the original
 * source repository.
 */
#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>");
		puts("more info: git.yaroslavps.com/minit/about/");
		exit(1);
	}

	puts("=== minit v1.0.0 ===");

	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);
}