/***************************** /* init.c file /*****************************/ int pid, child, s0, s1, status; int stdin, stdout; #include "ucode.c" int main(char* s) { /*open console for WRITE in order to diaplay messages*/ stdin = open("/dev/tty0", 0); stdout = open("/dev/tty0", 1); /* Now we can use printf, which calls putc(), which writes to stdout*/ printf("WPHINIT : fork a login task on console\n"); child = ufork(); if (child) { printf("WPHINIT : fork login tasks on serial terminals\n"); s0 = ufork(); if(s0) { s1 = ufork(); if(s1) { parent(); }/*end if s1, do parent*/ else { s1login(); }/*else do s1login*/ }/*end if in s0*/ else { s0login(); }/*end else do s0login*/ }/*end if in first child*/ else /* login task */ { login(); }/*else do login for main process*/ return 0; }/*end int main(char* s)*/ int login() { exec("login /dev/tty0"); }/*end int login*/ int s0login() { close(stdin); close(stdout); /*should I be assigning these to stdin/stdout again? what about stderr?*/ open("/dev/ttyS0",0); open("/dev/ttyS0",1); exec("login /dev/ttyS0"); }/*end int s0login*/ int s1login() { close(stdin); close(stdout); /*should I be assigning these to stdin/stdout again? what about stderr?*/ open("/dev/ttyS1",0); open("/dev/ttyS1",1); exec("login /dev/ttyS1"); }/*end int s1login*/ int parent() { printf("WPHINIT : waiting...\n\r"); while(1) { pid = wait(); if (pid==child) { printf("\n-----------------------------------------------\n"); printf("WPHINIT: Oh my God! "); printf("My beloved login child has died\n"); printf("Oh Well, I'll just fork another one!\n"); printf("-----------------------------------------------\n"); child = ufork(); if (child) { continue; }/*in parent, continue*/ else { login(); }/*end do login in new child*/ }/*end if pid==child*/ if (pid==s0) { printf("\n-----------------------------------------------\n"); printf("WPHINIT: Oh Dear! "); printf("My serial port 0 login child has died\n"); printf("Oh well, I'll just fork another one!\n"); printf("-----------------------------------------------\n"); s0 = ufork(); if (s0) { continue; }/*in parent, continue*/ else { s0login(); }/*end do s0login in new child*/ }/*end if pid==s0*/ if (pid==s1) { printf("\n-----------------------------------------------\n"); printf("WPHINIT: Oh No! "); printf("My serial port 1 login child has died\n"); printf("Oh well, I'll just fork another one!\n"); printf("-----------------------------------------------\n"); s1 = ufork(); if (s1) { continue; }/*end continue if new child was created*/ else { s1login(); }/*end do s1login in new child*/ }/*end if pid==s1*/ printf("WPHINIT : I just buried an orphan child %d\n", pid); }/*end while(1)*/ }/*end int parent()*/