101 lines
2.3 KiB
C
101 lines
2.3 KiB
C
#include "config.h"
|
|
void boot(void)
|
|
{
|
|
log("Mounting pseudo filesystem...");
|
|
{
|
|
mount("proc", "/proc", "proc", MS_NOSUID | MS_NOEXEC | MS_NODEV,
|
|
NULL);
|
|
mount("sys", "/sys", "sysfs", MS_NOSUID | MS_NOEXEC | MS_NODEV,
|
|
NULL);
|
|
mount("cache", "/var/cache", "tmpfs",
|
|
MS_NOSUID | MS_NOEXEC | MS_NODEV, "mode=0777");
|
|
mount("tmp", "/tmp", "tmpfs", MS_NOSUID | MS_NOEXEC | MS_NODEV,
|
|
"mode=0777");
|
|
mount("run", "/run", "tmpfs", MS_NOSUID | MS_NODEV,
|
|
"mode=0777");
|
|
mount("dev", "/dev", "devtmpfs", MS_NOSUID, "mode=0755");
|
|
|
|
mkdir("/dev/pts", 0755);
|
|
mkdir("/dev/shm", 0755);
|
|
mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC,
|
|
"mode=0620,gid=5");
|
|
mount("shm", "/dev/shm", "tmpfs", MS_NOSUID | MS_NODEV,
|
|
"mode=1777");
|
|
|
|
symlink("/proc/self/fd", "/dev/fd");
|
|
symlink("fd/0", "/dev/stdin");
|
|
symlink("fd/1", "/dev/stdout");
|
|
symlink("fd/2", "/dev/stderr");
|
|
|
|
mkdir("/run/lock", 0755);
|
|
}
|
|
|
|
log("Set up loopback...");
|
|
{
|
|
int fd, i;
|
|
struct sockaddr_in *addr;
|
|
struct ifreq iface;
|
|
const char *ifname = "lo";
|
|
|
|
fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
|
|
|
|
iface.ifr_addr.sa_family = AF_INET;
|
|
for (i = 0; iface.ifr_name[i] = ifname[i]; ++i)
|
|
;
|
|
|
|
addr = (struct sockaddr_in *)&iface.ifr_addr;
|
|
|
|
addr->sin_family = AF_INET;
|
|
addr->sin_addr.s_addr = 0x0100007f;
|
|
ioctl(fd, SIOCSIFADDR, &iface);
|
|
|
|
addr->sin_family = AF_INET;
|
|
addr->sin_addr.s_addr = 0x0000ff;
|
|
ioctl(fd, SIOCSIFNETMASK, &iface);
|
|
|
|
iface.ifr_flags |= (IFF_UP | IFF_RUNNING | IFF_LOOPBACK);
|
|
ioctl(fd, SIOCSIFFLAGS, &iface);
|
|
|
|
close(fd);
|
|
}
|
|
|
|
log("Setting hostname...");
|
|
{
|
|
char buf[64];
|
|
long result;
|
|
int input, output;
|
|
|
|
#warning callback if HOSTNAME doesnot exists
|
|
input = open(HOSTFILE, O_RDONLY);
|
|
output = open("/proc/sys/kernel/hostname", O_WRONLY);
|
|
|
|
while (result = read(input, buf, sizeof(buf)))
|
|
write(output, buf, result);
|
|
|
|
close(input);
|
|
close(output);
|
|
}
|
|
log("Seeding urandom...");
|
|
{
|
|
char buf[64];
|
|
long result;
|
|
int input, output;
|
|
|
|
output = open("/dev/urandom", O_WRONLY);
|
|
|
|
#warning callback if input doesnot exists
|
|
if (input = open(SEEDFILE, O_RDONLY))
|
|
;
|
|
{
|
|
while (result = read(input, buf, sizeof(buf)))
|
|
write(output, buf, result);
|
|
}
|
|
|
|
close(input);
|
|
close(output);
|
|
}
|
|
|
|
log("Running programs...");
|
|
runprgs((void *)boot_cmd, sizeof(boot_cmd) / sizeof(boot_cmd[0]));
|
|
}
|