From 7c51807812262788b85313ae71c41cd7f7c719fd Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 May 2023 06:40:55 +0300 Subject: [PATCH] Update init code --- apps/system/init/init.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/system/init/init.c b/apps/system/init/init.c index 7f80c0ba..53fc6a7e 100644 --- a/apps/system/init/init.c +++ b/apps/system/init/init.c @@ -1,8 +1,10 @@ #include +#include #include +#include #include -#include +#include #define print(m, ...) init_log(m, ##__VA_ARGS__) void test_args(int argc, char *argv[], char *envp[]) @@ -42,8 +44,38 @@ int main(int argc, char *argv[], char *envp[]) char buf[1024]; int read = fread(buf, 1024, 1, test); - print("Read %ld bytes from file\n", read); - print("File contents: %s\n", buf); + print("/Test.txt (%ld): %s\n", read, buf); fclose(test); + + pid_t pid; + int status; + + pid = fork(); + + if (pid == 0) // Child process + { + print("Creating shell process\n"); + char *args[] = {"/system/bin/sh", "--rcfile /home/default/.shrc", NULL}; + execv(args[0], args); + exit(EXIT_FAILURE); + } + else if (pid > 0) + { + wait(&status); + if (WIFEXITED(status)) + { + print("Child process exited with code: %d\n", WEXITSTATUS(status)); + } + else + { + print("Execution failed.\n"); + } + } + else + { + print("\eFF0000Failed to create the process.\n"); + exit(EXIT_FAILURE); + } + return 0; }