forked from pcercuei/mininit
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsplashkill.c
More file actions
87 lines (67 loc) · 1.53 KB
/
splashkill.c
File metadata and controls
87 lines (67 loc) · 1.53 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <linux/input.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "debug.h"
#define MAGIC_KEY KEY_ENTER
static char * const process_name = "splk";
static char * const init_fn = "/mininit";
static char * const event_fn = "/dev/event0";
static char * const console_fn = "/sys/devices/virtual/vtconsole/vtcon1/bind";
static char * const sys_mountpoint = "/sys";
static int fd;
static void quit_hdl(int err)
{
close(fd);
exit(err);
}
static int waitForEnter()
{
struct input_event event;
fd = open(event_fn, O_RDONLY);
if (fd < 0) {
ERROR("Unable to open %s\n", event_fn);
return -1;
}
do {
while(read(fd, &event, sizeof(event)) < sizeof(event));
} while (event.code != MAGIC_KEY);
close(fd);
return 0;
}
int main(int argc, char **argv)
{
int res, argv0size = strlen(argv[0]);
char one = '1';
signal(SIGINT, &quit_hdl);
signal(SIGSEGV, &quit_hdl);
signal(SIGTERM, &quit_hdl);
if (fork())
execl(init_fn, "/init", NULL);
strlcpy(argv[0], process_name, argv0size);
res = waitForEnter();
if (res)
return res;
if (mount(NULL, sys_mountpoint, "sysfs", 0, NULL)) {
ERROR("Unable to mount sysfs.\n");
return -1;
}
fd = open(console_fn, O_WRONLY);
if (fd < 0) {
ERROR("Unable to open %s\n", console_fn);
return -1;
}
write(fd, &one, sizeof(one));
close(fd);
if (umount(sys_mountpoint)) {
ERROR("Unable to un-mount sysfs.\n");
return -1;
}
return 0;
}