From cd29315fe44ac58fbc616fa6589bc532fdfa92e2 Mon Sep 17 00:00:00 2001 From: John Hood Date: Thu, 7 Mar 2024 18:58:54 -0500 Subject: [PATCH] Add support for kprintf via syslog() and MacOS os_log(). This seems moderately successful, I was able to get logging out of the CLI build with syslog(). I may marely have been having trouble with logging on my Mac. --- kernel/log.c | 12 ++++++++++++ xX_main_Xx.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/kernel/log.c b/kernel/log.c index a6cb9fe6..2b58d47d 100644 --- a/kernel/log.c +++ b/kernel/log.c @@ -3,9 +3,13 @@ #include #include #include +#include #if LOG_HANDLER_NSLOG #include #endif +#if LOG_HANDLER_OS_LOG +#include +#endif #include "kernel/calls.h" #include "util/sync.h" #include "util/fifo.h" @@ -142,6 +146,14 @@ static void log_line(const char *line) { extern void NSLog(CFStringRef msg, ...); NSLog(CFSTR("%s"), line); } +#elif LOG_HANDLER_SYSLOG +static void log_line(const char *line) { + syslog(LOG_DEBUG, "%s", line); +} +#elif LOG_HANDLER_OS_LOG +static void log_line(const char *line) { + os_log_fault(OS_LOG_DEFAULT, "%s", line); +} #endif static void default_die_handler(const char *msg) { diff --git a/xX_main_Xx.h b/xX_main_Xx.h index 560b7adf..d3153cc4 100644 --- a/xX_main_Xx.h +++ b/xX_main_Xx.h @@ -2,6 +2,7 @@ #include #include #include +#include #include "kernel/init.h" #include "kernel/fs.h" #include "fs/devices.h" @@ -67,6 +68,8 @@ static inline int xX_main_Xx(int argc, char *const argv[], const char *envp) { } } + openlog(argv[0], 0, LOG_USER); + char root_realpath[MAX_PATH + 1] = "/"; if (root != NULL && realpath(root, root_realpath) == NULL) { perror(root);