summaryrefslogtreecommitdiff
path: root/usr.bin/osh
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/osh')
-rw-r--r--usr.bin/osh/osh.c94
1 files changed, 64 insertions, 30 deletions
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index 9b4e9ab..ca9a241 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -30,8 +30,10 @@
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/reboot.h>
+#include <sys/spawn.h>
#include <fcntl.h>
#include <stddef.h>
+#include <stdbool.h>
#include <unistd.h>
#include <string.h>
@@ -50,6 +52,9 @@
"reboot - Reboot the machine\n" \
"shutdown - Power off the machine\n" \
"kmsg - Print kernel message buffer\n" \
+ "fetch - System information\n" \
+ "kfg - Start up kfgwm\n" \
+ "bell - Toggle backspace bell\n" \
"exit - Exit the shell\n"
#define PROMPT "[root::osmora]~ "
@@ -57,9 +62,12 @@
static char buf[64];
static uint8_t i;
static int running;
+static int bell_fd;
+static bool bs_bell = true; /* Beep on backspace */
struct command {
const char *name;
+ const char *path;
void (*func)(int fd, int argc, char *argv[]);
};
@@ -88,29 +96,6 @@ 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++) {
@@ -120,6 +105,27 @@ cmd_echo(int fd, int argc, char *argv[])
prcons(fd, "\n");
}
+void
+cmd_bell(int fd, int argc, char *argv[])
+{
+ const char *usage_str = "usage: bell [on/off]\n";
+ const char *arg;
+
+ if (argc < 2) {
+ prcons(fd, usage_str);
+ return;
+ }
+
+ arg = argv[1];
+ if (strcmp(arg, "on") == 0) {
+ bs_bell = true;
+ } else if (strcmp(arg, "off") == 0) {
+ bs_bell = false;
+ } else {
+ prcons(fd, usage_str);
+ }
+}
+
int
parse_args(char *input, char *argv[], int max_args)
{
@@ -159,8 +165,17 @@ getstr(int fd)
{
char c;
uint8_t input;
+ uint32_t beep_payload;
+
i = 0;
+ /*
+ * Prepare the beep payload @ 500 Hz
+ * for 20ms
+ */
+ beep_payload = 500;
+ beep_payload |= (30 << 16);
+
for (;;) {
if (read(fd, &input, 2) <= 0) {
continue;
@@ -180,6 +195,8 @@ getstr(int fd)
if (i > 0) {
i--;
write(fd, "\b \b", 3);
+ } else if (bell_fd > 0 && bs_bell) {
+ write(bell_fd, &beep_payload, sizeof(beep_payload));
}
} else if (is_ascii(c) && i < sizeof(buf) - 1) {
/* write to fd and add to buffer */
@@ -189,13 +206,29 @@ 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},
- {"kmsg", cmd_kmsg},
+ {"help", NULL, cmd_help},
+ {"echo", NULL, cmd_echo},
+ {"exit", NULL, cmd_exit},
+ {"reboot", NULL, cmd_reboot},
+ {"shutdown", NULL, cmd_shutdown},
+ {"bell", NULL, cmd_bell},
+ {"kmsg", "/usr/bin/kmsg", NULL},
+ {"fetch", "/usr/bin/fetch", NULL},
+ {"kfg", "/usr/bin/kfgwm", NULL},
{NULL, NULL}
};
@@ -213,6 +246,7 @@ main(void)
i = 0;
running = 1;
found = 0;
+ bell_fd = open("/dev/beep", O_WRONLY);
prcons(fd, WELCOME);
while (running) {
@@ -230,7 +264,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;
}