Adopt pipe handle inheritance
This commit is contained in:
@ -10,34 +10,18 @@
|
||||
#include <dlmalloc/malloc.h>
|
||||
#include <errors.h>
|
||||
|
||||
#define SUBPROC_PIPE_OUT 0x1f
|
||||
|
||||
uint64_t PID;
|
||||
|
||||
void main(void) {
|
||||
PID = (uint64_t)processctl(-1, PCTL_GETPID, 0, 0, 0);
|
||||
|
||||
ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_MAKE, NULL, 0);
|
||||
|
||||
void tb_runinitscript(void) {
|
||||
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);
|
||||
|
||||
|
||||
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_MAKE, NULL, 0);
|
||||
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_ADD_BCAST, NULL, 1);
|
||||
|
||||
#define OUTBUF_MAX 1024
|
||||
char *outbuf = dlmalloc(OUTBUF_MAX);
|
||||
|
||||
processctl(tb, PCTL_RUN, 0, 0, 0);
|
||||
|
||||
for(;;) {
|
||||
string_memset(outbuf, 0, OUTBUF_MAX);
|
||||
int32_t nrd = ipcpipe(PID, SUBPROC_PIPE_OUT, IPCPIPE_READ, (uint8_t *)outbuf, sizeof(outbuf));
|
||||
if (nrd > 0) {
|
||||
uprintf("%s", outbuf);
|
||||
}
|
||||
|
||||
while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 4) {
|
||||
int32_t kbchr;
|
||||
int32_t read = ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_READ, (uint8_t *)&kbchr, sizeof(kbchr));
|
||||
if (read > 0) {
|
||||
@ -49,6 +33,14 @@ void main(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
PID = (uint64_t)processctl(-1, PCTL_GETPID, 0, 0, 0);
|
||||
|
||||
tb_runinitscript();
|
||||
|
||||
uprintf("Shell exited! Please reboot the system.\n");
|
||||
|
||||
for(;;);
|
||||
}
|
||||
|
Reference in New Issue
Block a user