summaryrefslogtreecommitdiff
path: root/src/user/init.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-01-03 02:19:57 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-01-03 02:19:57 +0800
commit210025560c80b48af4875af199f183ad709e3bf0 (patch)
treeeb11aeb7b641187f207e3b572c5184cf3526b463 /src/user/init.cc
parentbde87490d61135dcaa94d9b1489ff6c39876d169 (diff)
parent10614e04929a6d109a5e90524e446b637aaf0c13 (diff)
downloadlume-210025560c80b48af4875af199f183ad709e3bf0.tar.gz
lume-210025560c80b48af4875af199f183ad709e3bf0.tar.xz
Merge pull request #4 from Richard-Qin-001/dev/shell
Rebuilt the system's underlying structure; it is now stable enough to merge. The system now supports a read-only file system and has a simple shell implemented.
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