aboutsummaryrefslogtreecommitdiffstats
path: root/init/init.c
blob: 536308206d8e094fb72690d32a44e1722cd200ed (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
54
55
56
57
58
59
60
#include <signal.h>
#include <sys/wait.h>

#include <init.h>
#include <util.h>

/* For some reason, I get SIGSEGV'd when running because a random-ass
   byte was inserted where it isnt supposed to be. Added a safety byte
   because I cannot be asked to try to figure out how to do this cleanly. */
static unsigned long __1bsafebuf
    __attribute__((used)) __attribute__((section(".1bsafebuf.init"))) = 0;

extern initcall_entry_t __initcall1_start[];
extern initcall_entry_t __initcall2_start[];
extern initcall_entry_t __initcall3_start[];
extern initcall_entry_t __initcall4_start[];
extern initcall_entry_t __initcall5_start[];
extern initcall_entry_t __initcall_end[];

static initcall_entry_t *initcall_levels[] = {
    __initcall1_start,
    __initcall2_start,
    __initcall3_start,
    __initcall4_start,
    __initcall5_start,
    __initcall_end,
};

static void do_initcall_level(int level)
{
    initcall_entry_t *fn;

    for (fn = initcall_levels[level - 1]; fn < initcall_levels[level]; fn++)
        initcall_from_entry(fn)();
}

static void do_initcalls(void)
{
    unsigned long level;
    for (level = 1; level < ARRAY_SIZE(initcall_levels); level++) {
        do_initcall_level(level);
    }
}

int main(void)
{
    do_initcalls();

    static sigset_t set;
    sigaddset(&set, SIGCHLD);
    sigprocmask(SIG_BLOCK, &set, NULL);

    while(1) {
        int sig;
        sigwait(&set, &sig);
        if(sig == SIGCHLD)
            while(waitpid(0, NULL, WNOHANG) > 0)
                ;
    }
}