From 778b24d74f4763f46ea874a6777e39b794006c44 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Fri, 14 Feb 2025 19:35:57 +0200 Subject: smolshel - works --- .gitignore | 3 ++- a.out | Bin 0 -> 1248 bytes makefile | 4 ++-- progs/shel/shel.c | 26 +++++++++++++++++++++----- sbin/init/init.c | 3 ++- 5 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 a.out diff --git a/.gitignore b/.gitignore index 5451a03..e0cc2a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ kernel - +build +sbuild diff --git a/a.out b/a.out new file mode 100644 index 0000000..5421e76 Binary files /dev/null and b/a.out differ diff --git a/makefile b/makefile index 990196a..51a756e 100644 --- a/makefile +++ b/makefile @@ -16,8 +16,8 @@ all: build_asmlib build_init build_shell build_fdmaker build_devscan if [ -d $$dir ]; then \ name=$$(basename $$dir); \ echo "Processing $$name $$dir/$$name.c"; \ - rm build/$$name; \ - gcc -o ./build/$$name $$dir/$$name.c -z noexecstack -static -march=x86-64; \ + rm sbuild/$$name; \ + gcc -o ./sbuild/$$name $$dir/$$name.c -z noexecstack -static -march=x86-64; \ fi \ done diff --git a/progs/shel/shel.c b/progs/shel/shel.c index f375250..e3221f4 100644 --- a/progs/shel/shel.c +++ b/progs/shel/shel.c @@ -1,34 +1,48 @@ #include #include +#include #include #include #include -void parseInput(char *input, char *command, char *argv) { +void parseInput(char *input, char *command, char **argv) { bool reachedArgv = false; char arg[32] = {0}; int idx = 0; int argvIdx = 1; - for (int i = 0; i < sizeof(input); i++) + for (int i = 0; i < strlen(input); i++) { + char *a = {&(input[i])}; if (reachedArgv) { + if (input[i] == ' ') { + arg[idx] = '\0'; + argv[argvIdx] = strdup(arg); + memset(arg, 0, sizeof(arg)); + argvIdx++; + idx = 0; + continue; + } arg[idx] = input[i]; idx++; continue; } if (input[i] == ' ') { - arg[idx] == '\0'; + arg[idx] = '\0'; strcpy(command, arg); reachedArgv = true; memset(arg, 0, sizeof(arg)); - idx++; + idx = 0; continue; } arg[idx] = input[i]; idx++; } - + argv[0] = command; + if (reachedArgv) { + arg[idx] = '\0'; + argv[argvIdx] = strdup(arg); + } } int main() { @@ -38,5 +52,7 @@ int main() { char *env[32] = {"PATH=/bin"}; char path[128] = "/"; + strcpy(input, "/bin/echo meow"); parseInput(input, command, argv); + execve(command, argv, 0); } \ No newline at end of file diff --git a/sbin/init/init.c b/sbin/init/init.c index ea64188..9f97918 100644 --- a/sbin/init/init.c +++ b/sbin/init/init.c @@ -1 +1,2 @@ -//TODO \ No newline at end of file +//TODO +int main() {return 0;} \ No newline at end of file -- cgit 1.4.1-2-gfad0