aboutsummaryrefslogtreecommitdiffstats
path: root/init/init.c
diff options
context:
space:
mode:
authorturret <turret@duck.com>2023-11-24 00:57:35 -0600
committerturret <turret@duck.com>2023-11-24 00:57:35 -0600
commit2f957068e567391e7aef5d7a2c075c14c1e6b37a (patch)
tree2e58f3008886e3372ebb26d1d7ae83a3ac0adae5 /init/init.c
parent40bff7788865b519b79b1ee7eb9851914010ffb4 (diff)
downloaddiscord-bot-skeleton-2f957068e567391e7aef5d7a2c075c14c1e6b37a.tar.gz
discord-bot-skeleton-2f957068e567391e7aef5d7a2c075c14c1e6b37a.tar.bz2
discord-bot-skeleton-2f957068e567391e7aef5d7a2c075c14c1e6b37a.zip
misc: subsys upgrade, log timestamps
(log) - create LOGLEVEL constant numbers - implement CONSOLE_LOGLEVEL - color array now uses loglevel constants - timestamp now shown (thanks util-linux) (init) - register mainpid - hello world print - fix process reaper to refer to subsys when reaping (subsys) - create maximum subsystem count - create subsystem table - add debugging prints to subsystem entry and termination - create function to handle process termination (unmap stack, free subsystem malloc, clear entry in table) - disable subsystem inception - change die references to fail with print - supply clone with signal to send on termination (SIGCHLD)
Diffstat (limited to 'init/init.c')
-rw-r--r--init/init.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/init/init.c b/init/init.c
index 7c2d6a6..97461ef 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1,9 +1,14 @@
#include <signal.h>
#include <sys/wait.h>
+#include <config.h>
#include <init.h>
+#include <log.h>
#include <util.h>
+extern int subsystem_handle_term(int pid);
+int mainpid = 0;
+
/* For some reason, I get SIGSEGV'd when running because a random-ass
byte was inserted where it isnt supposed to be. Added a safety byte
because I cannot be asked to try to figure out how to do this cleanly. */
@@ -48,20 +53,27 @@ static void do_initcalls(void)
int main(void)
{
+ print("init: Hello world! Running " NAME " v" VERSION "!");
+
+ mainpid = getpid();
+
+ /* Rest of the program.. */
do_initcalls();
/* Reaper. Much like init. */
- // BUG: doesnt actually work?? we have defunct processes still
- // TODO: fix bug
+ siginfo_t siginfo;
static sigset_t set;
sigaddset(&set, SIGCHLD);
sigprocmask(SIG_BLOCK, &set, NULL);
while(1) {
- int sig;
- sigwait(&set, &sig);
- if(sig == SIGCHLD)
- while(waitpid(0, NULL, WNOHANG) > 0)
- ;
+ sigwaitinfo(&set, &siginfo);
+ int sig = siginfo.si_signo;
+ if(sig == SIGCHLD) {
+ int process = 0;
+ while((process = waitpid(-1, NULL, WNOHANG)) > 0)
+ if(subsystem_handle_term(process) > 0)
+ print("init: failed to reap process %d", process);
+ }
}
}