foundry
Foundry OS: the operating system built on the Rustbelt kernel
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | //! init -- Foundry OS's first program (pid 1) under boot contract v2.
//!
//! When the kernel finds our ext2 root partition, it mounts it at `/` and
//! starts `/sbin/init` (this program) as process 1, with argv `["init"]`
//! (`["init", "selftest"]` in a headless build) and the environment
//! PATH=/sbin:/bin:/usr/bin:/mnt/disk0/bin, HOME=/, TERM=linux (plus
//! RUSTBELT_HEADLESS=1 when headless). See docs/boot-contract.md.
//!
//! Its jobs:
//!
//! 1. **Start the login shells.** rbsh (`/bin/rbsh`, the shell with drive
//! letters and DOS commands) on the console, and another one on the
//! second console `/dev/hvc0` if QEMU has one.
//! 2. **Respawn them.** Type `exit` in a shell and init starts a new one.
//! (The kernel never restarts pid 1 itself, so init must never exit in
//! normal use: when pid 1 exits, the kernel ends the QEMU run.)
//! 3. **Reap orphans.** When a process exits before its children, the
//! kernel hands those children to pid 1 -- but only if pid 1 is called
//! `init`, which is why this program is named init. A finished child
//! stays a "zombie" until its parent collects its exit status with
//! wait(); init's main loop waits for *any* child, so adopted orphans are
//! collected too.
//! 4. **Headless mode** (`init selftest`, or RUSTBELT_HEADLESS=1), used by
//! `make test`: run `rbsh /scripts/selftest.sh` on the console, wait for
//! it and for every orphan it left behind, report how many memory frames
//! are in use before and after (they must be equal: no leaks), and exit
//! with the self-test's exit code. The kernel turns pid 1's exit(n) into
//! QEMU exit code 33 + 2n, so exit(0) = 33 = "pass".
//!
//! init ignores the keyboard and termination signals (Ctrl+C on the console
//! must not kill pid 1); its children get the default handlers back.
extern crate alloc;
use *;
const SHELL: &str = "/bin/rbsh";
const SELFTEST: &str = "/scripts/selftest.sh";
const HVC0: &str = "/dev/hvc0";
/// Signals init ignores (and its children get back as SIG_DFL).
const IGNORED: = ;
const CLOCK_MONOTONIC: u64 = 1;
/// Start `argv` (argv[0] is the path) in a child process. With `tty`, the
/// child gets a session of its own with that terminal as stdin, stdout,
/// stderr and controlling terminal (what getty does); without, it shares
/// init's console. Returns the child's pid, or -errno.
/// Print the mount table on one line, e.g. "/ ext2, /tmp ramfs, ...".
/// Headless mode: run the self-test and return its exit code.
/// One terminal with a login shell on it.
/// Normal mode: keep a shell on every terminal, forever.
!
|