tb running cmds in interactive mode
This commit is contained in:
@ -1,2 +1,3 @@
|
||||
@print "this is an init script!"
|
||||
base:/bin/pctl ls
|
||||
base:/bin/tb -m interactive
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)))
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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';
|
||||
|
Reference in New Issue
Block a user