tb running cmds in interactive mode

This commit is contained in:
2025-09-18 00:57:24 +02:00
parent b3894f1600
commit e5e707eb54
6 changed files with 23 additions and 8 deletions

View File

@ -8,6 +8,7 @@
#include <string/char.h>
#include <util/util.h>
#include <dlmalloc/malloc.h>
#include <errors.h>
#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);
}
}
}
}

View File

@ -9,6 +9,7 @@
#include <sysdefs/processctl.h>
#include <sysdefs/ipcpipe.h>
#include <uprintf.h>
#include <errors.h>
#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);
}

View File

@ -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';