aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/init/mshell.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-05-23 10:11:56 -0400
committerIan Moffett <ian@osmora.org>2024-05-23 10:11:56 -0400
commitd7a3a7652d36201f37e515a08a7f31a72d2bde29 (patch)
treed7840e6d8e1f41cabb8d5fce3bcaa4ada5fcd3ef /usr.sbin/init/mshell.c
parent6fb9f18fd64cad9b22a4933bdb1d8c9639b2128c (diff)
init: Add 'kversion' and 'memstat' commands
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.sbin/init/mshell.c')
-rw-r--r--usr.sbin/init/mshell.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/usr.sbin/init/mshell.c b/usr.sbin/init/mshell.c
index dde07a9..a361b27 100644
--- a/usr.sbin/init/mshell.c
+++ b/usr.sbin/init/mshell.c
@@ -39,6 +39,7 @@
#include "mshell.h"
#define INPUT_SIZE 32
+#define MAX_FILE_SIZE 1024
#define TTY_DEV "/dev/tty1"
#define PROMPT "mshell> "
@@ -56,11 +57,38 @@ help(void)
"\treboot - reboot the system\n"
"\ttty - show the current TTY\n"
"\tpagesize - get the current page size\n"
+ "\tkversion - get the kernel version\n"
+ "\tmemstat - get info about memory\n"
"\texit - exit the shell\n"
);
}
static void
+print_file(const char *path)
+{
+ char buf[MAX_FILE_SIZE];
+ int fd = open(path, O_RDONLY);
+ int len;
+
+ if (fd < 0) {
+ printf("Failed to open %s\n", path);
+ return;
+ }
+
+ len = read(fd, buf, sizeof(buf));
+ if (len > MAX_FILE_SIZE) {
+ len = MAX_FILE_SIZE - 1;
+ }
+
+ if (len > 0) {
+ buf[len] = '\0';
+ printf("%s\n", buf);
+ }
+
+ close(fd);
+}
+
+static void
parse_input(struct mshell_state *state)
{
char cmd[INPUT_SIZE];
@@ -91,6 +119,10 @@ parse_input(struct mshell_state *state)
help();
} else if (strcmp(cmd, "exit") == 0) {
state->running = 0;
+ } else if (strcmp(cmd, "kversion") == 0) {
+ print_file("/proc/version");
+ } else if (strcmp(cmd, "memstat") == 0) {
+ print_file("/proc/memstat");
} else {
printf("Unknown command '%s'\n", cmd);
printf("Use 'help' for help\n");