summaryrefslogtreecommitdiff
path: root/src/user/init.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/init.cc')
-rw-r--r--src/user/init.cc72
1 files changed, 48 insertions, 24 deletions
diff --git a/src/user/init.cc b/src/user/init.cc
index 3c42adf..827a21e 100644
--- a/src/user/init.cc
+++ b/src/user/init.cc
@@ -1,34 +1,58 @@
+#include "ulib/stdio.h"
+#include "ulib/stdlib.h"
+#include "ulib/string.h"
#include "user/user.h"
-int main();
-
-extern "C" void _start()
-{
- exit(main());
-}
-
int main()
{
- int pid = fork();
+ char *argv[] = {(char *)"sh", 0};
- if (pid < 0)
- {
- write(1, "Fork failed\n", 12);
- exit(1);
- }
+ printf("[Init] Starting Lume OS Shell...\n");
- if (pid == 0)
- {
- write(1, "Hello from Child!\n", 18);
- exit(0);
- }
- else
+ while (1)
{
- write(1, "Parent waiting...\n", 18);
- wait(0);
- write(1, "Parent: Child exited.\n", 22);
- }
+ // printf("fork start\n");
+ int pid = fork();
+ // printf("fork suceess, pid=%i\n", pid);
+
+ if (pid < 0)
+ {
+ printf("[Init] fork failed!\n");
+ exit(1);
+ }
+
+ if (pid == 0)
+ {
+
+ char sh_path[] = "/sh";
+ exec(sh_path, argv);
- while (1);
+ printf("[Init] exec sh failed\n");
+ return 0;
+ exit(1);
+ }
+ else
+ {
+ // break;
+ int status;
+ int wpid;
+ while (1)
+ {
+ wpid = wait((uint64)&status);
+
+ if (wpid == pid)
+ {
+ printf("Shell Exit");
+ break;
+ }
+ if (wpid < 0)
+ {
+ printf("[Init] wait error or no child\n");
+
+ break;
+ }
+ }
+ }
+ }
return 0;
} \ No newline at end of file