diff --git a/base/scripts/init.tb b/base/scripts/init.tb index 7b873c3..0ff3e62 100644 --- a/base/scripts/init.tb +++ b/base/scripts/init.tb @@ -1,3 +1,2 @@ @print "this is an init script!" base:/bin/pctl ls -base:/bin/tb -m interactive diff --git a/kernel/syscall/ipcpipe.c b/kernel/syscall/ipcpipe.c index 7617528..53ff338 100644 --- a/kernel/syscall/ipcpipe.c +++ b/kernel/syscall/ipcpipe.c @@ -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; diff --git a/share/sysdefs/ipcpipe.h b/share/sysdefs/ipcpipe.h index f7f2760..b98c09f 100644 --- a/share/sysdefs/ipcpipe.h +++ b/share/sysdefs/ipcpipe.h @@ -15,6 +15,7 @@ enum { IPCPIPE_WRITE = 2, IPCPIPE_ADD_BCAST = 3, IPCPIPE_REPLACE = 4, + IPCPIPE_DELETE = 5, }; #endif // SHARE_SYSDEFS_IPCPIPE_H_ diff --git a/user/tb/interp.c b/user/tb/interp.c index 1bac0de..01aa65a 100644 --- a/user/tb/interp.c +++ b/user/tb/interp.c @@ -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,33 +220,29 @@ 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); - dlfree(outbuf); - for (size_t j = 0; j < argslen1; j++) { - dlfree(args1[j]); - } - dlfree(args1); - dlfree(appname); + cleanup: + ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_DELETE, NULL, 0); + dlfree(outbuf); + for (size_t j = 0; j < argslen1; j++) { + dlfree(args1[j]); + } + dlfree(args1); + dlfree(appname); } tz_free(&tz);