diff options
author | turret <turret@duck.com> | 2023-12-18 14:05:31 -0600 |
---|---|---|
committer | turret <turret@duck.com> | 2023-12-18 14:05:31 -0600 |
commit | ce9e6392f16e6f8dd55e3cca8cd34f2869650418 (patch) | |
tree | 6a2fdda484a4bfd81af7d09befa2099fbf22d671 /init | |
parent | cea6abd8faa5570ab06d40eae08f8c3aa519671c (diff) | |
download | discord-bot-skeleton-ce9e6392f16e6f8dd55e3cca8cd34f2869650418.tar.gz discord-bot-skeleton-ce9e6392f16e6f8dd55e3cca8cd34f2869650418.tar.bz2 discord-bot-skeleton-ce9e6392f16e6f8dd55e3cca8cd34f2869650418.zip |
init: token logic
(also add loglevel for failed to reap message)
token is required and init will panic without TOKEN in the environment
Diffstat (limited to 'init')
-rw-r--r-- | init/init.c | 15 |
1 files changed, 14 insertions, 1 deletions
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 <signal.h> +#include <stdlib.h> +#include <string.h> #include <sys/wait.h> #include <config.h> @@ -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); } } } |