70 lines
1.3 KiB
C
70 lines
1.3 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 (ce_pgid, 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");
|
|
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");
|
|
ce_pgid = get_procgroup (ce_pid);
|
|
|
|
const char* script_path = "sys:/init.cmd";
|
|
env_set (ce_pgid, "s", (void*)script_path, strlen (script_path) + 1);
|
|
|
|
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 (;;)
|
|
;
|
|
}
|