Skip to content

Commit

Permalink
feat: flush log in panic
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjian85 committed Jul 24, 2024
1 parent 5cf1043 commit c2ffe3a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/module/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ static void write(const char *str, usize size) {
dev_write(make_dev(TTY_DRIVER, 0), (const u8 *) str, size);
}

static void flush(void) {
dev_t tty_dev = make_dev(TTY_DRIVER, 0);
dev_write(tty_dev, (const u8 *) log_buf + log_head,
LOG_BUF_SIZE - log_head);
if (log_tail < log_head) {
dev_write(tty_dev, (const u8 *) log_buf, log_tail);
}
}

static void kvprintf(const char *fmt, va_list args) {
while (*fmt) {
switch (*fmt) {
Expand Down Expand Up @@ -82,17 +91,14 @@ void klogf(log_severity_t severity, const char *fmt, ...) {
kvprintf(fmt, args);
va_end(args);

if (severity == LOG_SEVERITY_PANIC)
if (severity == LOG_SEVERITY_PANIC) {
flush();
pm_hang();
}
}

static i32 init(void) {
dev_t tty_dev = make_dev(TTY_DRIVER, 0);
dev_write(tty_dev, (const u8 *) log_buf + log_head,
LOG_BUF_SIZE - log_head);
if (log_tail < log_head) {
dev_write(tty_dev, (const u8 *) log_buf, log_tail);
}
flush();
inited = true;
return 0;
}
Expand Down

0 comments on commit c2ffe3a

Please sign in to comment.