mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-31 22:48:21 +00:00
init: run /etc/rc on boot
This commit is contained in:
+6
-1
@@ -1 +1,6 @@
|
|||||||
mkdir /tmp
|
#!/usr/bin/bash
|
||||||
|
mkdir -p /dev
|
||||||
|
mount /dev devfs
|
||||||
|
|
||||||
|
mkdir -p /tmp
|
||||||
|
mount /tmp tmpfs
|
||||||
|
|||||||
+31
-5
@@ -7,6 +7,7 @@
|
|||||||
int main() {
|
int main() {
|
||||||
printf("init: Welcome to Astral!\n");
|
printf("init: Welcome to Astral!\n");
|
||||||
|
|
||||||
|
// set up initial environmental variables
|
||||||
struct passwd* pw = getpwuid(getuid());
|
struct passwd* pw = getpwuid(getuid());
|
||||||
if (pw == NULL) {
|
if (pw == NULL) {
|
||||||
perror("init: failed to open /etc/passwd");
|
perror("init: failed to open /etc/passwd");
|
||||||
@@ -23,24 +24,49 @@ int main() {
|
|||||||
setenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", 1);
|
setenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", 1);
|
||||||
setenv("TERM", "linux", 1);
|
setenv("TERM", "linux", 1);
|
||||||
|
|
||||||
printf("init: running /usr/bin/bash\n");
|
// run rc to initialize environment (mount filesystems, etc)
|
||||||
|
printf("init: running /etc/rc\n");
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
perror("init: fork failed:");
|
perror("init: fork failed");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
execl("/usr/bin/bash", "/usr/bin/bash", "/etc/rc", NULL);
|
||||||
|
perror("init: exec /usr/bin/bash failed");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
|
if (waitpid(pid, &status, 0) == -1) {
|
||||||
|
perror("init: waitpid failed");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WEXITSTATUS(status)) {
|
||||||
|
printf("/etc/rc returned failure status %d\n", WEXITSTATUS(status));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// start user shell
|
||||||
|
printf("init: running /usr/bin/bash\n");
|
||||||
|
pid = fork();
|
||||||
|
if (pid == -1) {
|
||||||
|
perror("init: fork failed");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
execl("/usr/bin/bash", "/usr/bin/bash", "-l", NULL);
|
execl("/usr/bin/bash", "/usr/bin/bash", "-l", NULL);
|
||||||
perror("init: execl /usr/bin/bash failed:");
|
perror("init: execl /usr/bin/bash failed");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int status;
|
int status;
|
||||||
if (waitpid(-1, &status, 0) == -1) {
|
if (waitpid(-1, &status, 0) == -1) {
|
||||||
perror("init: waitpid failed:");
|
perror("init: waitpid failed");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user