summaryrefslogtreecommitdiff
path: root/usrbin/main.c
blob: 6acf5fe5563439c7221774f13269b19338121293 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
#include <errno.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>

void sighandler(int sig) {
  printf("Signal received!\n");
}

void pid1(void) {
  ssize_t in;
  char buf[2] = { 0, };

  printf("We did it ma!\n");
  signal(1, &sighandler);

  while(1) {
    in = read(buf, 1);
    if(in < 1) {
      if(in == -EINTR) {
        printf("Read call interrupted!\n");
        /* kill(getpid(), SIGKILL); */
      } else {
        printf("Error reading from serial port!\n");
        kill(getpid(), SIGKILL);
      }
    }
    if(in == 0) {
      printf("EOF detected!\n");
      panic();
    }
    if(in > 0)
      puts(buf);
  }
}

void pid2(void) {
  int x = 0;

  printf("We did it ma!\n");

  while(1) {
    sleep(1);
    if(time() == 2)
      kill(1, 1);
    printf("0x%04x:0x%08x: 0x%08x, 0x%08x\n", getpid(), (uint32_t) getpdir(), time(), x++);

    if(x > 3)
      kill(getpid(), SIGKILL);
  }
}

void main(void) {
  if(getpid() == 1) {
    ctty(1);
    pid1();
  }

  pid2();
}