diff --git a/CMakeLists.txt b/CMakeLists.txt index a4cf9f4..db4c821 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,7 @@ configure_file( add_subdirectory(arch) -#add_subdirectory(init) +add_subdirectory(init) add_subdirectory(kernel) add_subdirectory(lib) @@ -86,7 +86,7 @@ add_custom_command( COMMAND ${CMAKE_LINKER} ARGS ${ARDIX_LINKER_FLAGS} -o ardix.elf $ - #$ + $ $ $ $ diff --git a/init/main.c b/init/main.c new file mode 100644 index 0000000..6a9ef38 --- /dev/null +++ b/init/main.c @@ -0,0 +1,52 @@ +/* See the end of this file for copyright, license, and warranty information. */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +int child_test(void) +{ + printf("[child ] i'm so sleempy,, calling sleep(),,\n"); + sleep(1000); + printf("[child ] sleep() returned, i'm gonna kill myself now uwu\n"); + return 69; +} + +/** + * @brief init daemon entry point. + */ +int init_main(void) +{ + printf("[parent] calling exec()\n"); + pid_t pid = exec(child_test); + printf("[parent] exec() returned, child pid = %d\n", pid); + + int status; + printf("[parent] calling waitpid()\n"); + waitpid(-1, &status, 0); + printf("[parent] waitpid() returned, child exit code = %d\n", status); + printf("[parent] my child has died, goodbye cruel world qwq\n"); + + return 0; +} + +/* + * This file is part of Ardix. + * Copyright (c) 2020, 2021 Felix Kopp . + * + * Ardix is non-violent software: you may only use, redistribute, + * and/or modify it under the terms of the CNPLv6+ as found in + * the LICENSE file in the source code root directory or at + * . + * + * Ardix comes with ABSOLUTELY NO WARRANTY, to the extent + * permitted by applicable law. See the CNPLv6+ for details. + */ diff --git a/kernel/main.c b/kernel/main.c index c3758a1..6878c6f 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -12,6 +12,8 @@ #include #include +extern int init_main(void); /* init/main.c */ + /** * Core init routine. * @@ -44,9 +46,10 @@ int main(void) printf("This is non-violent software, and there is NO WARRANTY.\n"); printf("See for details.\n\n"); - /* TODO: The next big step is to write initd and fork to it here. */ - while (1) - sleep(1000); + pid_t pid = exec(init_main); + waitpid(pid, &err, 0); + printf("initd exited with status %d, system halted\n", err); + while (1); } /*