update for new file system
[unix-history] / usr / src / sbin / init / init.c
index 378cb78..89ccfff 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)init.c      4.6 (Berkeley) %G%";
+static char *sccsid = "@(#)init.c      4.10 (Berkeley) %G%";
 #include <signal.h>
 #include <sys/types.h>
 #include <utmp.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <utmp.h>
@@ -51,13 +51,38 @@ int idle();
 char   *strcpy(), *strcat();
 long   lseek();
 
 char   *strcpy(), *strcat();
 long   lseek();
 
+#ifndef sun
 main()
 {
        register int r11;               /* passed thru from boot */
 main()
 {
        register int r11;               /* passed thru from boot */
+#else sun
+main(argc, argv)
+       char **argv;
+{
+#endif sun
        int howto, oldhowto;
 
        time0 = time(0);
        int howto, oldhowto;
 
        time0 = time(0);
+#ifndef sun
        howto = r11;
        howto = r11;
+#else sun
+       if (argc > 1 && argv[1][0] == '-') {
+               char *cp;
+
+               howto = 0;
+               cp = &argv[1][1];
+               while (*cp) switch (*cp++) {
+               case 'a':
+                       howto |= RB_ASKNAME;
+                       break;
+               case 's':
+                       howto |= RB_SINGLE;
+                       break;
+               }
+       } else {
+               howto = RB_SINGLE;
+       }
+#endif sun
        setjmp(sjbuf);
        signal(SIGTERM, reset);
        signal(SIGTSTP, idle);
        setjmp(sjbuf);
        signal(SIGTERM, reset);
        signal(SIGTSTP, idle);
@@ -337,12 +362,15 @@ merge()
        }
 }
 
        }
 }
 
+#include <sys/ioctl.h>
+
 dfork(p)
 struct tab *p;
 {
        register pid;
        time_t t;
        int dowait = 0;
 dfork(p)
 struct tab *p;
 {
        register pid;
        time_t t;
        int dowait = 0;
+       extern char *sys_errlist[];
 
        time(&t);
        p->gettycnt++;
 
        time(&t);
        p->gettycnt++;
@@ -358,29 +386,44 @@ struct tab *p;
        }
        pid = fork();
        if(pid == 0) {
        }
        pid = fork();
        if(pid == 0) {
+               int oerrno, f;
+               extern int errno;
+
+               signal(SIGTERM, SIG_DFL);
+               signal(SIGHUP, SIG_IGN);
+               strcpy(tty, dev);
+               strncat(tty, p->line, LINSIZ);
                if (dowait) {
                if (dowait) {
-                       int f = open("/dev/console", 1);
+                       f = open("/dev/console", 1);
                        write(f, "init: ", 6);
                        write(f, tty, strlen(tty));
                        write(f, ": getty failing, sleeping\n\r", 27);
                        close(f);
                        sleep(30);
                        write(f, "init: ", 6);
                        write(f, tty, strlen(tty));
                        write(f, ": getty failing, sleeping\n\r", 27);
                        close(f);
                        sleep(30);
+                       if ((f = open("/dev/tty", 2)) >= 0) {
+                               ioctl(f, TIOCNOTTY, 0);
+                               close(f);
+                       }
                }
                }
-               signal(SIGTERM, SIG_DFL);
-               signal(SIGHUP, SIG_IGN);
-               strcpy(tty, dev);
-               strncat(tty, p->line, LINSIZ);
                chown(tty, 0, 0);
                chmod(tty, 0622);
                if (open(tty, 2) < 0) {
                        int repcnt = 0;
                        do {
                chown(tty, 0, 0);
                chmod(tty, 0622);
                if (open(tty, 2) < 0) {
                        int repcnt = 0;
                        do {
+                               oerrno = errno;
                                if (repcnt % 10 == 0) {
                                if (repcnt % 10 == 0) {
-                                       int f = open("/dev/console", 1);
+                                       f = open("/dev/console", 1);
                                        write(f, "init: ", 6);
                                        write(f, tty, strlen(tty));
                                        write(f, "init: ", 6);
                                        write(f, tty, strlen(tty));
-                                       write(f, ": cannot open\n\r", 15);
+                                       write(f, ": ", 2);
+                                       write(f, sys_errlist[oerrno],
+                                               strlen(sys_errlist[oerrno]));
+                                       write(f, "\n", 1);
                                        close(f);
                                        close(f);
+                                       if ((f = open("/dev/tty", 2)) >= 0) {
+                                               ioctl(f, TIOCNOTTY, 0);
+                                               close(f);
+                                       }
                                }
                                repcnt++;
                                sleep(60);
                                }
                                repcnt++;
                                sleep(60);