mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
tools: basic init
This commit is contained in:
@@ -14,3 +14,5 @@ kernel-src/io/printf.c
|
||||
kernel-src/flanterm
|
||||
sysroot
|
||||
minimalsysroot
|
||||
tools/init/init
|
||||
tools/init/main.o
|
||||
|
||||
@@ -369,7 +369,7 @@ void sched_runinit() {
|
||||
sched_initproc = proc;
|
||||
|
||||
vnode_t *initnode;
|
||||
__assert(vfs_open(vfsroot, "/usr/bin/bash", 0, &initnode) == 0);
|
||||
__assert(vfs_open(vfsroot, "/init", 0, &initnode) == 0);
|
||||
|
||||
auxv64list_t auxv64;
|
||||
char *interp = NULL;
|
||||
@@ -417,7 +417,7 @@ void sched_runinit() {
|
||||
proc->root = vfsroot;
|
||||
VOP_HOLD(vfsroot);
|
||||
|
||||
char *argv[] = {"/usr/bin/bash", "-l", NULL};
|
||||
char *argv[] = {"/init", "-l", NULL};
|
||||
char *envp[] = {NULL};
|
||||
|
||||
void *stack = elf_preparestack(STACK_TOP, &auxv64, argv, envp);
|
||||
|
||||
+34
-2
@@ -1,6 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <pwd.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello, world!\n");
|
||||
return 0;
|
||||
printf("init: Welcome to Astral!\n");
|
||||
|
||||
struct passwd* pw = getpwuid(getuid());
|
||||
//setenv("PWD", pw->pw_dir, 1);
|
||||
setenv("HOME", pw->pw_dir, 1);
|
||||
//chdir(pw->pw_dir);
|
||||
setenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", 1);
|
||||
setenv("TERM", "linux", 1);
|
||||
|
||||
printf("init: running /usr/bin/bash\n");
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == -1) {
|
||||
perror("init: fork failed:");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
execl("/usr/bin/bash", "/usr/bin/bash", "-l", NULL);
|
||||
perror("init: execl /usr/bin/bash failed:");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int status;
|
||||
if (waitpid(-1, &status, 0) == -1) {
|
||||
perror("init: waitpid failed:");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user