From 642b5fb0007b64c77d186fcb018d571152ee1d47 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 14 Aug 2023 18:51:07 +0200 Subject: reorganization: first steps --- src/cmd/init/driver/initctl.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/cmd/init/driver/initctl.c (limited to 'src/cmd/init/driver/initctl.c') diff --git a/src/cmd/init/driver/initctl.c b/src/cmd/init/driver/initctl.c new file mode 100644 index 0000000..fed71b7 --- /dev/null +++ b/src/cmd/init/driver/initctl.c @@ -0,0 +1,44 @@ +#include "driver.h" +#include +#include +#include +#include +#include +#include + +void initctl_drv(hid_t killswitch) { + struct ufs_request res; + char buf[64]; + const size_t buflen = sizeof buf; + while (!c0_fs_wait(buf, buflen, &res)) { + switch (res.op) { + case VFSOP_OPEN: + c0_fs_respond(NULL, res.len == 0 ? 0 : -1, 0); + break; + case VFSOP_WRITE: + /* null terminate */ + if (res.len > buflen - 1) + res.len = buflen - 1; + buf[res.len] = '\0'; + /* cut at first whitespace */ + for (size_t i = 0; buf[i]; i++) { + if (isspace(buf[i])) { + buf[i] = '\0'; + break; + } + } + if (!strcmp(buf, "halt")) { + _sys_write(killswitch, "halt", 4, 0, 0); + } + if (!strcmp(buf, "intr")) { + _sys_write(killswitch, "intr", 4, 0, 0); + } + c0_fs_respond(NULL, res.len, 0); + break; + default: + c0_fs_respond(NULL, -ENOSYS, 0); + break; + } + } + exit(1); +} -- cgit v1.2.3