summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-05-29 23:00:50 -0400
committerIan Moffett <ian@osmora.org>2025-05-29 23:00:50 -0400
commit36d829cb9b6bbb29c28aaa1454593c74d0a5bc59 (patch)
tree7161260d614f3013a69e5309ded9dc2ec1b85687
parent81ffbaa6d5f2270a5c32d0f22da14606e0bd5394 (diff)
usr.bin: osh: Add kmsg command for kernel messages
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--usr.bin/osh/osh.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index c45d9c8..9b4e9ab 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -49,6 +49,7 @@
"echo - Print the arguments to the console\n" \
"reboot - Reboot the machine\n" \
"shutdown - Power off the machine\n" \
+ "kmsg - Print kernel message buffer\n" \
"exit - Exit the shell\n"
#define PROMPT "[root::osmora]~ "
@@ -87,6 +88,29 @@ cmd_shutdown(int fd, int argc, char *argv[])
}
void
+cmd_kmsg(int fd, int argc, char *argv[])
+{
+ int mfd;
+ ssize_t retval;
+ char linebuf[256];
+
+ if ((mfd = open("/dev/kmsg", O_RDONLY)) < 0) {
+ return;
+ }
+
+ for (;;) {
+ retval = read(mfd, linebuf, sizeof(linebuf) - 1);
+ if (retval <= 0) {
+ break;
+ }
+ linebuf[retval] = '\0';
+ prcons(fd, linebuf);
+ }
+
+ close(mfd);
+}
+
+void
cmd_echo(int fd, int argc, char *argv[])
{
for (i = 1; i < argc; i++) {
@@ -171,6 +195,7 @@ struct command cmds[] = {
{"exit", cmd_exit},
{"reboot", cmd_reboot},
{"shutdown", cmd_shutdown},
+ {"kmsg", cmd_kmsg},
{NULL, NULL}
};