From e5e707eb544d07064d54a4a89c829f94db44c927 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Thu, 18 Sep 2025 00:57:24 +0200 Subject: [PATCH] tb running cmds in interactive mode --- base/scripts/init.tb | 1 + kernel/syscall/processctl.c | 2 +- share/errors.h | 4 ++++ user/init/main.c | 4 +--- user/tb/interp.c | 17 ++++++++++++++--- user/tb/main.c | 3 ++- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/base/scripts/init.tb b/base/scripts/init.tb index 0ff3e62..7b873c3 100644 --- a/base/scripts/init.tb +++ b/base/scripts/init.tb @@ -1,2 +1,3 @@ @print "this is an init script!" base:/bin/pctl ls +base:/bin/tb -m interactive diff --git a/kernel/syscall/processctl.c b/kernel/syscall/processctl.c index 310c60b..326c9f9 100644 --- a/kernel/syscall/processctl.c +++ b/kernel/syscall/processctl.c @@ -56,7 +56,7 @@ int32_t SYSCALL5(sys_processctl, pid1, cmd1, arg1, arg2, arg3) { Proc *newproc = proc_spawnuser(mp, path); if (newproc == NULL) { - ret = E_NOMEMORY; + ret = E_SPAWNERROR; goto done; } diff --git a/share/errors.h b/share/errors.h index a6be501..ef77af5 100644 --- a/share/errors.h +++ b/share/errors.h @@ -14,6 +14,8 @@ enum { E_DOSCHEDULING = -9, E_INVALIDARGUMENT = -10, E_INVALIDOPER = -11, + E_RESOURCEAVAIL = -12, + E_SPAWNERROR = -13, }; static const char *_ERROR_STRINGS[] = { @@ -29,6 +31,8 @@ static const char *_ERROR_STRINGS[] = { "Perform scheduling (internal flag)", "Invalid argument", "Invalid operation", + "Resource already available", + "Process spawn error", }; #define ERRSTRING_INDEX(ioh) ((size_t)((ioh) < 0 ? (ioh) * (-1) : (ioh))) diff --git a/user/init/main.c b/user/init/main.c index 51a07f1..c80a643 100644 --- a/user/init/main.c +++ b/user/init/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #define SUBPROC_PIPE_OUT 0x1f @@ -45,9 +46,6 @@ void main(void) { if (c != 0) { ipcpipe(tb, IPCPIPE_IN, IPCPIPE_WRITE, &c, 1); } - if (string_chr_isprint(c)) { - uprintf("%c", c); - } } } } diff --git a/user/tb/interp.c b/user/tb/interp.c index 4772935..1bac0de 100644 --- a/user/tb/interp.c +++ b/user/tb/interp.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "interp.h" #include "runtime.h" @@ -215,8 +216,20 @@ bool interp_runstring(const char *string, InterpResult **res, bool logcmds) { ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_MAKE, NULL, 0); int32_t app = processctl(-1, PCTL_SPAWN, (uint64_t)(char *)appname, (uint64_t)args1, argslen1); + if (app < 0) { + usprintf(RES.errmsg, "Could not run %s: %s\n", appname, ERRSTRING(app)); + ok = false; + dlfree(outbuf); + for (size_t j = 0; j < argslen1; j++) { + dlfree(args1[j]); + } + dlfree(args1); + dlfree(appname); + goto done; + } + ipcpipe(app, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)PID, SUBPROC_PIPE_OUT); - ipcpipe(app, IPCPIPE_IN, IPCPIPE_READ, (uint8_t *)PID, IPCPIPE_IN); + ipcpipe(app, IPCPIPE_IN, IPCPIPE_REPLACE, (uint8_t *)PID, IPCPIPE_IN); processctl(app, PCTL_RUN, 0, 0, 0); while (processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4) { @@ -228,12 +241,10 @@ bool interp_runstring(const char *string, InterpResult **res, bool logcmds) { } dlfree(outbuf); - for (size_t j = 0; j < argslen1; j++) { dlfree(args1[j]); } dlfree(args1); - dlfree(appname); } diff --git a/user/tb/main.c b/user/tb/main.c index b8771fe..402b9dc 100644 --- a/user/tb/main.c +++ b/user/tb/main.c @@ -105,9 +105,10 @@ void do_mode_interactive(void) { string_memset(linebuf, 0, LINEBUF_MAX); char c = 0; while (c != '\n') { - int32_t rd = ipcpipe(IPCPIPE_SELFPID, IPCPIPE_IN, IPCPIPE_READ, (uint8_t *)&c, 1); + int32_t rd = ipcpipe(PID, IPCPIPE_IN, IPCPIPE_READ, (uint8_t *)&c, 1); if (rd > 0 && cursor < LINEBUF_MAX) { linebuf[cursor++] = c; + uprintf("%c", c); } } linebuf[cursor - 1] = '\0';