summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-05-27 09:17:28 -0400
committerIan Moffett <ian@osmora.org>2024-05-27 09:17:28 -0400
commit5958c43275236bf5508c2e1582b245c60e1b83fd (patch)
tree052070e2afa8741768fcebef8df03c142f39eaa4
parent80c9ac57e65eec746ffeba968efc8163e0f0e9ae (diff)
kernel: syslog: Serialize kprintf()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/kern/kern_syslog.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/sys/kern/kern_syslog.c b/sys/kern/kern_syslog.c
index f52c05f..86877e0 100644
--- a/sys/kern/kern_syslog.c
+++ b/sys/kern/kern_syslog.c
@@ -32,6 +32,7 @@
#include <sys/tty.h>
#include <sys/cdefs.h>
#include <sys/timer.h>
+#include <sys/spinlock.h>
#include <dev/vcons/vcons.h>
#include <fs/procfs.h>
#include <string.h>
@@ -49,6 +50,7 @@ __STATIC_ASSERT(KMSG_BUF_SHIFT <= 16, "Log buffer shift too large!\n");
static char kmsg_buf[KMSG_BUF_SIZE];
static size_t kmsg_buf_idx = 0;
static struct proc_entry *kmsg_proc;
+static struct spinlock lock = {0};
struct vcons_screen g_syslog_screen = {0};
bool g_syslog_use_tty = true;
@@ -92,6 +94,9 @@ syslog_write(const char *s, size_t len)
tty_flush(&g_root_tty);
}
+/*
+ * XXX: Not serialized
+ */
void
vkprintf(const char *fmt, va_list *ap)
{
@@ -111,6 +116,8 @@ kprintf(const char *fmt, ...)
const char *fmt_p = fmt;
struct timer tmr = {0};
+ spinlock_acquire(&lock);
+
/*
* If the first char is OMIT_TIMESTAMP, then we won't
* print out the timestamp.
@@ -139,6 +146,8 @@ kprintf(const char *fmt, ...)
va_start(ap, fmt);
vkprintf(fmt_p, &ap);
va_end(ap);
+
+ spinlock_release(&lock);
}
void