Skip to content

Commit

Permalink
Add support for kprintf via syslog() and MacOS os_log().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cgull committed Mar 9, 2024
1 parent eea6921 commit cd29315
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kernel/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
#include <stdarg.h>
#include <string.h>
#include <sys/uio.h>
#include <syslog.h>
#if LOG_HANDLER_NSLOG
#include <CoreFoundation/CoreFoundation.h>
#endif
#if LOG_HANDLER_OS_LOG
#include <os/log.h>
#endif
#include "kernel/calls.h"
#include "util/sync.h"
#include "util/fifo.h"
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions xX_main_Xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <syslog.h>
#include "kernel/init.h"
#include "kernel/fs.h"
#include "fs/devices.h"
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cd29315

Please sign in to comment.