diff options
author | Ian Moffett <ian@osmora.org> | 2025-05-28 23:31:46 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-05-28 23:36:34 -0400 |
commit | 51ca9c82c3e8fb323d238e1f58a085f4cb306110 (patch) | |
tree | c48309afbff0dccb21f4dde2a43203d5148fd60b /sys/kern/kern_syslog.c | |
parent | cb807eb795e1380513db4c7dbce0452645746abf (diff) |
kernel: syslog: Handle userspace kmsg logging
- Add USER_KMSG option to configure if kernel messages
should be logged in user contexts
- Add syslog_silence() to silence kernel messages in user
contexts if USER_KMSG is "yes"
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern/kern_syslog.c')
-rw-r--r-- | sys/kern/kern_syslog.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sys/kern/kern_syslog.c b/sys/kern/kern_syslog.c index 656362e..db50a3c 100644 --- a/sys/kern/kern_syslog.c +++ b/sys/kern/kern_syslog.c @@ -40,8 +40,15 @@ #define SERIAL_DEBUG 0 #endif +#if defined(__USER_KMSG) +#define USER_KMSG __USER_KMSG +#else +#define USER_KMSG 0 +#endif + /* Global logger lock */ static struct spinlock lock = {0}; +static bool no_cons_log = false; static void syslog_write(const char *s, size_t len) @@ -58,6 +65,15 @@ syslog_write(const char *s, size_t len) } } + /* + * If the USER_KMSG option is disabled in kconf, + * do not log to the console if everything else + * has already started. + */ + if (!USER_KMSG && no_cons_log) { + return; + } + cons_putstr(&g_root_scr, s, len); } @@ -116,3 +132,16 @@ kprintf(const char *fmt, ...) va_end(ap); spinlock_release(&lock); } + +/* + * Silence kernel messages in if the system + * is already operating in a user context. + * + * XXX: This is ignored if the kconf USER_KMSG + * option is set to "no" + */ +void +syslog_silence(bool option) +{ + no_cons_log = option; +} |