dont hang when kill 1 and procs hung
authorBill Joy <bill@ucbvax.Berkeley.EDU>
Tue, 14 Oct 1980 11:18:16 +0000 (03:18 -0800)
committerBill Joy <bill@ucbvax.Berkeley.EDU>
Tue, 14 Oct 1980 11:18:16 +0000 (03:18 -0800)
SCCS-vsn: old/init/init.c 4.3
SCCS-vsn: sbin/init/init.c 4.3

usr/src/old/init/init.c
usr/src/sbin/init/init.c

index 9b36c65..589979e 100644 (file)
@@ -1,3 +1,4 @@
+static char *sccsid = "@(#)init.c      4.3 (Berkeley) %G%";
 #include <signal.h>
 #include <sys/types.h>
 #include <utmp.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <utmp.h>
@@ -39,7 +40,7 @@ struct        tab
 int    fi;
 int    mergflag;
 char   tty[20];
 int    fi;
 int    mergflag;
 char   tty[20];
-jmp_buf        sjbuf;
+jmp_buf        sjbuf, shutpass;
 
 int    reset();
 char   *strcpy(), *strcat();
 
 int    reset();
 char   *strcpy(), *strcat();
@@ -60,7 +61,8 @@ main()
        for(EVER) {
                oldhowto = howto;
                howto = RB_SINGLE;
        for(EVER) {
                oldhowto = howto;
                howto = RB_SINGLE;
-               shutdown();
+               if (setjmp(shutpass) == 0)
+                       shutdown();
                if (oldhowto & RB_SINGLE)
                        single();
                if (runcom(oldhowto) == 0) 
                if (oldhowto & RB_SINGLE)
                        single();
                if (runcom(oldhowto) == 0) 
@@ -70,6 +72,8 @@ main()
        }
 }
 
        }
 }
 
+int    shutreset();
+
 shutdown()
 {
        register i;
 shutdown()
 {
        register i;
@@ -81,13 +85,37 @@ shutdown()
                term(p);
                p->line[0] = 0;
        }
                term(p);
                p->line[0] = 0;
        }
-       signal(SIGALRM, reset);
-       alarm(60);
+       signal(SIGALRM, shutreset);
+       alarm(30);
        for(i=0; i<5; i++)
                kill(-1, SIGKILL);
        while(wait((int *)0) != -1)
                ;
        alarm(0);
        for(i=0; i<5; i++)
                kill(-1, SIGKILL);
        while(wait((int *)0) != -1)
                ;
        alarm(0);
+       shutend();
+}
+
+char shutfailm[] = "WARNING: Something is hung (wont die); ps axl advised\n";
+
+shutreset()
+{
+       int status;
+
+       if (fork() == 0) {
+               int ct = open(ctty, 1);
+               write(ct, shutfailm, sizeof (shutfailm));
+               sleep(5);
+               exit(1);
+       }
+       sleep(5);
+       shutend();
+       longjmp(shutpass, 1);
+}
+
+shutend()
+{
+       register i;
+
        signal(SIGALRM, SIG_DFL);
        for(i=0; i<10; i++)
                close(i);
        signal(SIGALRM, SIG_DFL);
        for(i=0; i<10; i++)
                close(i);
@@ -343,5 +371,3 @@ reset()
 {
        longjmp(sjbuf, 1);
 }
 {
        longjmp(sjbuf, 1);
 }
-
-
index 9b36c65..589979e 100644 (file)
@@ -1,3 +1,4 @@
+static char *sccsid = "@(#)init.c      4.3 (Berkeley) %G%";
 #include <signal.h>
 #include <sys/types.h>
 #include <utmp.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <utmp.h>
@@ -39,7 +40,7 @@ struct        tab
 int    fi;
 int    mergflag;
 char   tty[20];
 int    fi;
 int    mergflag;
 char   tty[20];
-jmp_buf        sjbuf;
+jmp_buf        sjbuf, shutpass;
 
 int    reset();
 char   *strcpy(), *strcat();
 
 int    reset();
 char   *strcpy(), *strcat();
@@ -60,7 +61,8 @@ main()
        for(EVER) {
                oldhowto = howto;
                howto = RB_SINGLE;
        for(EVER) {
                oldhowto = howto;
                howto = RB_SINGLE;
-               shutdown();
+               if (setjmp(shutpass) == 0)
+                       shutdown();
                if (oldhowto & RB_SINGLE)
                        single();
                if (runcom(oldhowto) == 0) 
                if (oldhowto & RB_SINGLE)
                        single();
                if (runcom(oldhowto) == 0) 
@@ -70,6 +72,8 @@ main()
        }
 }
 
        }
 }
 
+int    shutreset();
+
 shutdown()
 {
        register i;
 shutdown()
 {
        register i;
@@ -81,13 +85,37 @@ shutdown()
                term(p);
                p->line[0] = 0;
        }
                term(p);
                p->line[0] = 0;
        }
-       signal(SIGALRM, reset);
-       alarm(60);
+       signal(SIGALRM, shutreset);
+       alarm(30);
        for(i=0; i<5; i++)
                kill(-1, SIGKILL);
        while(wait((int *)0) != -1)
                ;
        alarm(0);
        for(i=0; i<5; i++)
                kill(-1, SIGKILL);
        while(wait((int *)0) != -1)
                ;
        alarm(0);
+       shutend();
+}
+
+char shutfailm[] = "WARNING: Something is hung (wont die); ps axl advised\n";
+
+shutreset()
+{
+       int status;
+
+       if (fork() == 0) {
+               int ct = open(ctty, 1);
+               write(ct, shutfailm, sizeof (shutfailm));
+               sleep(5);
+               exit(1);
+       }
+       sleep(5);
+       shutend();
+       longjmp(shutpass, 1);
+}
+
+shutend()
+{
+       register i;
+
        signal(SIGALRM, SIG_DFL);
        for(i=0; i<10; i++)
                close(i);
        signal(SIGALRM, SIG_DFL);
        for(i=0; i<10; i++)
                close(i);
@@ -343,5 +371,3 @@ reset()
 {
        longjmp(sjbuf, 1);
 }
 {
        longjmp(sjbuf, 1);
 }
-
-