still serv_close bug...
[mit-jos.git] / user / init.c
blob535d2a1a1de81401f142629f306bb14a64c84e9e
1 #include <inc/lib.h>
3 struct {
4 char msg1[5000];
5 char msg2[1000];
6 } data = {
7 "this is initialized data",
8 "so is this"
9 };
11 char bss[6000];
13 int
14 sum(const char *s, int n)
16 int i, tot = 0;
17 for (i = 0; i < n; i++)
18 tot ^= i * s[i];
19 return tot;
22 void
23 umain(int argc, char **argv)
25 int i, r, x, want;
27 cprintf("init: running\n");
29 want = 0xf989e;
30 if ((x = sum((char*)&data, sizeof data)) != want)
31 cprintf("init: data is not initialized: got sum %08x wanted %08x\n",
32 x, want);
33 else
34 cprintf("init: data seems okay\n");
35 if ((x = sum(bss, sizeof bss)) != 0)
36 cprintf("bss is not initialized: wanted sum 0 got %08x\n", x);
37 else
38 cprintf("init: bss seems okay\n");
40 cprintf("init: args:");
41 for (i = 0; i < argc; i++)
42 cprintf(" '%s'", argv[i]);
43 cprintf("\n");
45 cprintf("init: running sh\n");
47 // being run directly from kernel, so no file descriptors open yet
48 close(0);
49 if ((r = opencons()) < 0)
50 panic("opencons: %e", r);
51 if (r != 0)
52 panic("first opencons used fd %d", r);
53 if ((r = dup(0, 1)) < 0)
54 panic("dup: %e", r);
55 while (1) {
56 cprintf("init: starting sh\n");
57 r = spawnl("/sh", "sh", (char*)0);
58 if (r < 0) {
59 cprintf("init: spawn sh: %e\n", r);
60 continue;
62 wait(r);