Compare commits
5 Commits
6a8af7727e
...
e5e707eb54
Author | SHA1 | Date | |
---|---|---|---|
e5e707eb54 | |||
b3894f1600 | |||
b0e543177b | |||
ba1c0eedbd | |||
ac1cc172f7 |
@ -1,2 +1,3 @@
|
||||
@print "this is an init script!"
|
||||
base:/bin/pctl ls
|
||||
base:/bin/tb -m interactive
|
||||
|
@ -32,6 +32,7 @@
|
||||
static uint8_t shiftcode[0x100] = {
|
||||
[0x1d] KB_CTL,
|
||||
[0x2a] KB_SHIFT,
|
||||
[0x36] KB_SHIFT,
|
||||
[0x38] KB_ALT,
|
||||
[0x9d] KB_CTL,
|
||||
[0xb8] KB_ALT,
|
||||
|
@ -49,6 +49,13 @@ int32_t SYSCALL5(sys_ipcpipe, pid1, pipenum1, cmd1, buffer1, len1) {
|
||||
}
|
||||
|
||||
spinlock_acquire(&proc->pipes_spinlock);
|
||||
if (proc->pipes[pipenum] != NULL) {
|
||||
spinlock_release(&proc->pipes_spinlock);
|
||||
ipc_pipefree(pipe);
|
||||
dlfree(pipe);
|
||||
ret = E_RESOURCEAVAIL;
|
||||
goto done;
|
||||
}
|
||||
proc->pipes[pipenum] = pipe;
|
||||
spinlock_release(&proc->pipes_spinlock);
|
||||
|
||||
|
@ -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)))
|
||||
|
@ -19,6 +19,9 @@ int32_t parse_args(char **argv, size_t argc, Arg *defs) {
|
||||
case ARG_STRING:
|
||||
*((char **)def->ptr) = argv[i+1];
|
||||
break;
|
||||
case ARG_BOOL:
|
||||
*((bool *)def->ptr) = string_strcmp(argv[i+1], "yes") == 0;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ size_t argslen(void);
|
||||
|
||||
typedef struct {
|
||||
char *shortname;
|
||||
enum { ARG_STRING } expected_value;
|
||||
enum { ARG_STRING, ARG_BOOL } expected_value;
|
||||
void *ptr;
|
||||
bool end;
|
||||
} Arg;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <string/char.h>
|
||||
#include <util/util.h>
|
||||
#include <dlmalloc/malloc.h>
|
||||
#include <errors.h>
|
||||
|
||||
#define SUBPROC_PIPE_OUT 0x1f
|
||||
|
||||
@ -18,7 +19,7 @@ void main(void) {
|
||||
|
||||
ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_MAKE, NULL, 0);
|
||||
|
||||
char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb" };
|
||||
char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb", "-logcmds", "yes" };
|
||||
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, ARRLEN(tbargs));
|
||||
ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)PID, SUBPROC_PIPE_OUT);
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -150,7 +151,7 @@ bool interp_readline(char *data, const char **bgptr, const char **endptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool interp_runstring(const char *string, InterpResult **res) {
|
||||
bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
|
||||
*res = &RES;
|
||||
string_memset(RES.errmsg, 0, sizeof(RES.errmsg));
|
||||
|
||||
@ -160,6 +161,11 @@ bool interp_runstring(const char *string, InterpResult **res) {
|
||||
interp_readline((char *)string, NULL, NULL);
|
||||
while (interp_readline(NULL, &bg, &end)) {
|
||||
size_t linelen = end - bg;
|
||||
|
||||
if (logcmds) {
|
||||
uprintf("+ %.*s\n", (int)linelen, bg);
|
||||
}
|
||||
|
||||
Tokenizer tz = {0};
|
||||
tz_init(&tz, bg, linelen);
|
||||
|
||||
@ -210,8 +216,20 @@ bool interp_runstring(const char *string, InterpResult **res) {
|
||||
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) {
|
||||
@ -223,12 +241,10 @@ bool interp_runstring(const char *string, InterpResult **res) {
|
||||
}
|
||||
|
||||
dlfree(outbuf);
|
||||
|
||||
for (size_t j = 0; j < argslen1; j++) {
|
||||
dlfree(args1[j]);
|
||||
}
|
||||
dlfree(args1);
|
||||
|
||||
dlfree(appname);
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,6 @@ typedef struct {
|
||||
Token *tokens;
|
||||
} Tokenizer;
|
||||
|
||||
bool interp_runstring(const char *string, InterpResult **res);
|
||||
bool interp_runstring(const char *string, InterpResult **res, bool logcmds);
|
||||
|
||||
#endif // TB_INTERP_H_
|
||||
|
@ -20,7 +20,10 @@ uint64_t PID;
|
||||
struct {
|
||||
char *modestr;
|
||||
enum { MODE_INTERACTIVE = 1, MODE_RUNFILE = 2 } mode;
|
||||
|
||||
char *filepath;
|
||||
|
||||
bool logcmds;
|
||||
} CONFIG;
|
||||
|
||||
#define LINEBUF_MAX 1024
|
||||
@ -28,6 +31,7 @@ struct {
|
||||
static Arg ARGS[] = {
|
||||
ARG("-m", ARG_STRING, &CONFIG.modestr),
|
||||
ARG("-f", ARG_STRING, &CONFIG.filepath),
|
||||
ARG("-logcmds", ARG_BOOL, &CONFIG.logcmds),
|
||||
ARG_END(),
|
||||
};
|
||||
|
||||
@ -79,7 +83,7 @@ void do_file(char *filepath) {
|
||||
}
|
||||
|
||||
InterpResult *res;
|
||||
bool ok = interp_runstring((const char *)buf, &res);
|
||||
bool ok = interp_runstring((const char *)buf, &res, CONFIG.logcmds);
|
||||
if (!ok) {
|
||||
uprintf("Interpreter error:\n");
|
||||
uprintf("%s\n", res->errmsg);
|
||||
@ -101,15 +105,16 @@ 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';
|
||||
uprintf("\n");
|
||||
InterpResult *res;
|
||||
if (!interp_runstring(linebuf, &res)) {
|
||||
if (!interp_runstring(linebuf, &res, CONFIG.logcmds)) {
|
||||
LOG(LOG_ERR, "%s\n", res->errmsg);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user