67 lines
1.2 KiB
C
67 lines
1.2 KiB
C
#include <debugconsole.h>
|
|
#include <kb.h>
|
|
#include <limits.h>
|
|
#include <process.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <streams.h>
|
|
#include <string.h>
|
|
#include <terminal.h>
|
|
|
|
#define RECV_MAX (1024 * 16)
|
|
|
|
static int ce_pgid;
|
|
|
|
static void receiver(void* arg) {
|
|
(void)arg;
|
|
|
|
char recv[RECV_MAX];
|
|
int n;
|
|
for (;;) {
|
|
n = stream_read(STREAM_OUT, (void*)recv, RECV_MAX - 1);
|
|
|
|
if (n > 0)
|
|
terminal_print(recv, n);
|
|
else
|
|
sched();
|
|
}
|
|
}
|
|
|
|
static void run_ce_interactive(void) {
|
|
int ce_pid = exec("sys", "/ce", NULL);
|
|
ce_pgid = get_procgroup(ce_pid);
|
|
|
|
process_spawn(&receiver, NULL);
|
|
|
|
for (;;) {
|
|
int ch = kb_read_key();
|
|
|
|
if (ch == 0)
|
|
continue;
|
|
|
|
stream_write(ce_pgid, STREAM_IN, &ch, 1);
|
|
}
|
|
}
|
|
|
|
static void ce_run_init_script(void) {
|
|
int ce_pid = exec_partial("sys", "/ce", "-script sys:/init.cmd");
|
|
ce_pgid = get_procgroup(ce_pid);
|
|
|
|
struct process_data* recv_pdata = process_spawn(&receiver, NULL);
|
|
|
|
exec_partial_fini(ce_pgid);
|
|
|
|
wait_for_pid(ce_pid);
|
|
kill(recv_pdata->pid);
|
|
process_data_free(recv_pdata);
|
|
}
|
|
|
|
void app_main(void) {
|
|
debug_printf("Init process is running. Starting user shell...\n");
|
|
|
|
ce_run_init_script();
|
|
run_ce_interactive();
|
|
for (;;)
|
|
;
|
|
}
|