add PCTL_DELETE for removing pipes
This commit is contained in:
@ -1,3 +1,2 @@
|
|||||||
@print "this is an init script!"
|
@print "this is an init script!"
|
||||||
base:/bin/pctl ls
|
base:/bin/pctl ls
|
||||||
base:/bin/tb -m interactive
|
|
||||||
|
@ -61,6 +61,21 @@ int32_t SYSCALL5(sys_ipcpipe, pid1, pipenum1, cmd1, buffer1, len1) {
|
|||||||
|
|
||||||
ret = E_OK;
|
ret = E_OK;
|
||||||
} break;
|
} 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: {
|
case IPCPIPE_WRITE: {
|
||||||
if (pipenum >= PROC_PIPEHANDLES_MAX) {
|
if (pipenum >= PROC_PIPEHANDLES_MAX) {
|
||||||
ret = E_INVALIDARGUMENT;
|
ret = E_INVALIDARGUMENT;
|
||||||
|
@ -15,6 +15,7 @@ enum {
|
|||||||
IPCPIPE_WRITE = 2,
|
IPCPIPE_WRITE = 2,
|
||||||
IPCPIPE_ADD_BCAST = 3,
|
IPCPIPE_ADD_BCAST = 3,
|
||||||
IPCPIPE_REPLACE = 4,
|
IPCPIPE_REPLACE = 4,
|
||||||
|
IPCPIPE_DELETE = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHARE_SYSDEFS_IPCPIPE_H_
|
#endif // SHARE_SYSDEFS_IPCPIPE_H_
|
||||||
|
@ -212,6 +212,7 @@ bool interp_runstring(const char *string, InterpResult **res, bool logcmds) {
|
|||||||
|
|
||||||
#define OUTBUF_MAX 1024
|
#define OUTBUF_MAX 1024
|
||||||
char *outbuf = dlmalloc(OUTBUF_MAX);
|
char *outbuf = dlmalloc(OUTBUF_MAX);
|
||||||
|
string_memset(outbuf, 0, OUTBUF_MAX);
|
||||||
|
|
||||||
ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_MAKE, NULL, 0);
|
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) {
|
if (app < 0) {
|
||||||
usprintf(RES.errmsg, "Could not run %s: %s\n", appname, ERRSTRING(app));
|
usprintf(RES.errmsg, "Could not run %s: %s\n", appname, ERRSTRING(app));
|
||||||
ok = false;
|
ok = false;
|
||||||
dlfree(outbuf);
|
goto cleanup;
|
||||||
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_OUT, IPCPIPE_REPLACE, (uint8_t *)PID, SUBPROC_PIPE_OUT);
|
||||||
ipcpipe(app, IPCPIPE_IN, IPCPIPE_REPLACE, (uint8_t *)PID, IPCPIPE_IN);
|
ipcpipe(app, IPCPIPE_IN, IPCPIPE_REPLACE, (uint8_t *)PID, IPCPIPE_IN);
|
||||||
processctl(app, PCTL_RUN, 0, 0, 0);
|
processctl(app, PCTL_RUN, 0, 0, 0);
|
||||||
|
|
||||||
while (processctl(app, PCTL_POLLSTATE, 0, 0, 0) != 4) {
|
do {
|
||||||
string_memset(outbuf, 0, OUTBUF_MAX);
|
int32_t nrd = ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_READ, (uint8_t *)outbuf, OUTBUF_MAX);
|
||||||
int32_t nrd = ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_READ, (uint8_t *)outbuf, sizeof(outbuf));
|
|
||||||
if (nrd > 0) {
|
if (nrd > 0) {
|
||||||
uprintf("%s", outbuf);
|
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);
|
dlfree(outbuf);
|
||||||
for (size_t j = 0; j < argslen1; j++) {
|
for (size_t j = 0; j < argslen1; j++) {
|
||||||
dlfree(args1[j]);
|
dlfree(args1[j]);
|
||||||
|
Reference in New Issue
Block a user