Compare commits

...

3 Commits

6 changed files with 40 additions and 19 deletions

View File

@ -1,3 +1,2 @@
@print "this is an init script!"
base:/bin/pctl ls
base:/bin/tb -m interactive

View File

@ -215,6 +215,7 @@ void intr_handleintr(IntrStackFrame *frame) {
break;
case INTR_IRQBASE+1:
int32_t c = ps2kb_intr();
intr_eoi(frame->trapnum - INTR_IRQBASE);
if (c >= 0) {
uint8_t *bytes = (uint8_t *)&c;
spinlock_acquire(&PS2KB_BUF.spinlock);
@ -223,7 +224,6 @@ void intr_handleintr(IntrStackFrame *frame) {
}
spinlock_release(&PS2KB_BUF.spinlock);
}
intr_eoi(frame->trapnum - INTR_IRQBASE);
break;
}
} else if (frame->trapnum == 0x80) {

View File

@ -61,6 +61,21 @@ int32_t SYSCALL5(sys_ipcpipe, pid1, pipenum1, cmd1, buffer1, len1) {
ret = E_OK;
} break;
case IPCPIPE_DELETE: {
if (pipenum >= PROC_PIPEHANDLES_MAX) {
ret = E_NOMEMORY;
goto done;
}
spinlock_acquire(&proc->pipes_spinlock);
if (proc->pipes[pipenum] != NULL) {
ipc_pipefree(proc->pipes[pipenum]);
dlfree(proc->pipes[pipenum]);
proc->pipes[pipenum] = NULL;
}
spinlock_release(&proc->pipes_spinlock);
ret = E_OK;
} break;
case IPCPIPE_WRITE: {
if (pipenum >= PROC_PIPEHANDLES_MAX) {
ret = E_INVALIDARGUMENT;

View File

@ -9,6 +9,7 @@
#include "path/path.h"
#include "kprintf.h"
#include "dlmalloc/malloc.h"
#include "ipc/pipe/pipe.h"
#define PCTL_MP_MAX 0xff
#define PCTL_PATH_MAX VFS_PATH_MAX
@ -66,6 +67,14 @@ int32_t SYSCALL5(sys_processctl, pid1, cmd1, arg1, arg2, arg3) {
PROC_ARG(newproc, (*args)[i]);
}
for (size_t i = 0; i < PROC_PIPEHANDLES_MAX; i++) {
if (newproc->pipes[i] != NULL) {
ipc_pipefree(newproc->pipes[i]);
dlfree(newproc->pipes[i]);
}
newproc->pipes[i] = proc->pipes[i];
}
proc_register(newproc);
ret = newproc->pid;
} break;

View File

@ -15,6 +15,7 @@ enum {
IPCPIPE_WRITE = 2,
IPCPIPE_ADD_BCAST = 3,
IPCPIPE_REPLACE = 4,
IPCPIPE_DELETE = 5,
};
#endif // SHARE_SYSDEFS_IPCPIPE_H_

View File

@ -212,6 +212,7 @@ bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
#define OUTBUF_MAX 1024
char *outbuf = dlmalloc(OUTBUF_MAX);
string_memset(outbuf, 0, OUTBUF_MAX);
ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_MAKE, NULL, 0);
@ -219,27 +220,23 @@ bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
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;
goto cleanup;
}
ipcpipe(app, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)PID, SUBPROC_PIPE_OUT);
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) {
string_memset(outbuf, 0, OUTBUF_MAX);
int32_t nrd = ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_READ, (uint8_t *)outbuf, sizeof(outbuf));
do {
int32_t nrd = ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_READ, (uint8_t *)outbuf, OUTBUF_MAX);
if (nrd > 0) {
uprintf("%s", outbuf);
string_memset(outbuf, 0, OUTBUF_MAX);
}
}
} while(processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4);
cleanup:
ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_DELETE, NULL, 0);
dlfree(outbuf);
for (size_t j = 0; j < argslen1; j++) {
dlfree(args1[j]);