summaryrefslogtreecommitdiff
path: root/usr.bin/osh/osh.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/osh/osh.c')
-rw-r--r--usr.bin/osh/osh.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index c45d9c8..583f29a 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -30,6 +30,7 @@
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/reboot.h>
+#include <sys/spawn.h>
#include <fcntl.h>
#include <stddef.h>
#include <unistd.h>
@@ -49,6 +50,8 @@
"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" \
+ "fetch - System information\n" \
"exit - Exit the shell\n"
#define PROMPT "[root::osmora]~ "
@@ -59,6 +62,7 @@ static int running;
struct command {
const char *name;
+ const char *path;
void (*func)(int fd, int argc, char *argv[]);
};
@@ -165,12 +169,27 @@ getstr(int fd)
}
}
+static void
+command_run(struct command *cmd, int fd, int argc, char *argv[])
+{
+ if (cmd->func != NULL) {
+ cmd->func(fd, argc, argv);
+ return;
+ }
+
+ if (cmd->path != NULL) {
+ spawn(cmd->path, SPAWN_WAIT);
+ }
+}
+
struct command cmds[] = {
- {"help", cmd_help},
- {"echo", cmd_echo},
- {"exit", cmd_exit},
- {"reboot", cmd_reboot},
- {"shutdown", cmd_shutdown},
+ {"help", NULL, cmd_help},
+ {"echo", NULL, cmd_echo},
+ {"exit", NULL, cmd_exit},
+ {"reboot", NULL, cmd_reboot},
+ {"shutdown", NULL, cmd_shutdown},
+ {"kmsg", "/usr/bin/kmsg", NULL},
+ {"fetch", "/usr/bin/fetch", NULL},
{NULL, NULL}
};
@@ -205,7 +224,7 @@ main(void)
for (i = 0; cmds[i].name != NULL; i++) {
if (strcmp(input, cmds[i].name) == 0) {
- cmds[i].func(fd, argc, argv);
+ command_run(&cmds[i], fd, argc, argv);
found = 1;
break;
}