summaryrefslogtreecommitdiff
path: root/src/user/init/init.c
blob: e8786038cdb7eeb198d8749be101ecfde300fbfc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <knob/user.h>
#include <knob/file.h>
#include <knob/task.h>

void start(const char *cmd) {
  tell_user_sz("[init] Starting ");
  tell_user_sz(cmd);
  tell_user_sz(": ");
  tell_user_sz(
    run_command(cmd)
      ? "Succeded.\n"
      : "Failed.\n"
  );
  tell_user_sz("[init] Yielding.\n");
  yield_task();
}

#define STARTUP_FILE_PATH "sys/startup.rc"

void main() {
  struct file *f = open_file(STARTUP_FILE_PATH);
  if (!f) {
    tell_user_sz("Could not open " STARTUP_FILE_PATH ".\n");
    return;
  }

  tell_user_sz("[init] Reading from " STARTUP_FILE_PATH ".\n");

  char buf[1024];
  char *bufp = buf;
  while (read_from_file(f, 1, bufp)) {
    if (*bufp == '\n') {
      if (bufp == buf)
        continue;
      *bufp = '\0';
      start(buf);
      bufp = buf;
    }
    else
      ++bufp;
  }
  if (bufp != buf) {
    *bufp = '\0';
    start(buf);
  }

  close_file(f);

  tell_user_sz("[init] Done starting programs.\n");
}