Report S2EVENT_CONNECT when a new SSID is selected.
[AROS.git] / arch / all-unix / bootstrap / kickstart.c
blobe3354d0737e336d5d21523bf84581cc6ac85868d
1 #include <sys/wait.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
7 /* These macros are defined in both UNIX and AROS headers. Get rid of warnings. */
8 #undef __pure
9 #undef __const
10 #undef __pure2
11 #undef __deprecated
13 #include <aros/kernel.h>
14 #include <runtime.h>
16 #include "kickstart.h"
17 #include "platform.h"
19 #define D(x)
22 * This is the UNIX-hosted kicker. Theory of operation:
23 * We want to run the loaded code multiple times, every time as a new process (in order
24 * to drop all open file descriptors etc).
25 * We have already loaded our kickstart and allocated RAM. Now we use fork() to mark
26 * the point where we are started.
27 * AROS is executed inside child process. The parent just sits and waits for the return
28 * code.
29 * When AROS shuts down, it sets exit status in order to indicate a reason. There are
30 * three status codes:
31 * 1. Shutdown
32 * 2. Cold reboot.
33 * 3. Warm reboot.
34 * We pick up this code and see what we need to do. Warm reboot means just creating a
35 * new AROS process using the same kickstart and RAM image. When the RAM is made shared,
36 * this will effectively keep KickTags etc.
37 * Cold reboot is the same as before, re-running everything from scratch.
38 * Shutdown is just plain exit.
40 int kick(int (*addr)(), struct TagItem *msg)
42 int i;
46 pid_t child = fork();
48 switch (child)
50 case -1:
51 DisplayError("Failed to run kickstart!");
52 return -1;
54 case 0:
55 fprintf(stderr, "[Bootstrap] entering kernel at %p...\n", addr);
56 i = addr(msg, AROS_BOOT_MAGIC);
57 exit(i);
60 /* Wait until AROS process exits */
61 waitpid(child, &i, 0);
63 if (!WIFEXITED(i))
65 D(fprintf(stderr, "AROS process died with error\n"));
66 return -1;
69 D(fprintf(stderr, "AROS exited with status 0x%08X\n", WEXITSTATUS(i)));
71 /* ColdReboot() returns 0x8F */
72 } while (WEXITSTATUS(i) == 0x8F);
74 if (WEXITSTATUS(i) == 0x81)
77 * Perform cold boot if requested.
78 * Before rebooting, we clean up. Otherwise execvp()'ed process will
79 * inherit what we allocated here, then again... This will cause memory leak.
81 Host_FreeMem();
82 Host_ColdBoot();
85 return WEXITSTATUS(i);