From ce9e6392f16e6f8dd55e3cca8cd34f2869650418 Mon Sep 17 00:00:00 2001 From: turret Date: Mon, 18 Dec 2023 14:05:31 -0600 Subject: init: token logic (also add loglevel for failed to reap message) token is required and init will panic without TOKEN in the environment --- init/init.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/init/init.c b/init/init.c index 97461ef..59908d1 100644 --- a/init/init.c +++ b/init/init.c @@ -1,4 +1,6 @@ #include +#include +#include #include #include @@ -8,6 +10,7 @@ extern int subsystem_handle_term(int pid); int mainpid = 0; +char *token; /* 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 @@ -55,8 +58,18 @@ int main(void) { print("init: Hello world! Running " NAME " v" VERSION "!"); + /* set mainpid for the subsystem service so it is fully accessible during l1 */ mainpid = getpid(); + /* fetch token */ + char *token_base = getenv("TOKEN"); + if(!token_base) + panic("init: cannot find TOKEN in env"); + + token = calloc(strlen(token_base) + strlen("Authorization: Bot ") + 1, sizeof(char)); + strcpy(token, "Authorization: Bot "); + strcat(token, token_base); + /* Rest of the program.. */ do_initcalls(); @@ -73,7 +86,7 @@ int main(void) int process = 0; while((process = waitpid(-1, NULL, WNOHANG)) > 0) if(subsystem_handle_term(process) > 0) - print("init: failed to reap process %d", process); + print(LOG_WARNING "init: failed to reap process %d", process); } } } -- cgit v1.2.3