add PCTL_DELETE for removing pipes

This commit is contained in:
2025-09-18 22:43:24 +02:00
parent 024a5b2e21
commit 4c17f26915
4 changed files with 30 additions and 18 deletions

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,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);