initd: implement simple test init daemon

paging
anna 3 years ago
parent 104578d072
commit c767d551d3
Signed by: fef
GPG Key ID: EC22E476DC2D3D84

@ -71,7 +71,7 @@ configure_file(
add_subdirectory(arch) add_subdirectory(arch)
#add_subdirectory(init) add_subdirectory(init)
add_subdirectory(kernel) add_subdirectory(kernel)
add_subdirectory(lib) add_subdirectory(lib)
@ -86,7 +86,7 @@ add_custom_command(
COMMAND ${CMAKE_LINKER} COMMAND ${CMAKE_LINKER}
ARGS ${ARDIX_LINKER_FLAGS} -o ardix.elf ARGS ${ARDIX_LINKER_FLAGS} -o ardix.elf
$<TARGET_FILE:ardix_arch> $<TARGET_FILE:ardix_arch>
#$<TARGET_FILE:ardix_init> $<TARGET_FILE:ardix_init>
$<TARGET_FILE:ardix_kernel> $<TARGET_FILE:ardix_kernel>
$<TARGET_FILE:ardix_kernel_fs> $<TARGET_FILE:ardix_kernel_fs>
$<TARGET_FILE:ardix_lib> $<TARGET_FILE:ardix_lib>

@ -0,0 +1,52 @@
/* See the end of this file for copyright, license, and warranty information. */
#include <ardix/io.h>
#include <ardix/kent.h>
#include <ardix/kevent.h>
#include <ardix/sched.h>
#include <config.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
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 <owo@fef.moe>.
*
* 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
* <https://git.pixie.town/thufie/CNPL>.
*
* Ardix comes with ABSOLUTELY NO WARRANTY, to the extent
* permitted by applicable law. See the CNPLv6+ for details.
*/

@ -12,6 +12,8 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
extern int init_main(void); /* init/main.c */
/** /**
* Core init routine. * Core init routine.
* *
@ -44,9 +46,10 @@ int main(void)
printf("This is non-violent software, and there is NO WARRANTY.\n"); printf("This is non-violent software, and there is NO WARRANTY.\n");
printf("See <https://git.fef.moe/fef/ardix> for details.\n\n"); printf("See <https://git.fef.moe/fef/ardix> for details.\n\n");
/* TODO: The next big step is to write initd and fork to it here. */ pid_t pid = exec(init_main);
while (1) waitpid(pid, &err, 0);
sleep(1000); printf("initd exited with status %d, system halted\n", err);
while (1);
} }
/* /*

Loading…
Cancel
Save