add fastboot and nosync flags from David Grubb (dgg@mit-athena)
authorJim Bloom <bloom@ucbvax.Berkeley.EDU>
Sat, 2 Nov 1985 08:55:51 +0000 (00:55 -0800)
committerJim Bloom <bloom@ucbvax.Berkeley.EDU>
Sat, 2 Nov 1985 08:55:51 +0000 (00:55 -0800)
SCCS-vsn: sbin/shutdown/shutdown.c 5.2

usr/src/sbin/shutdown/shutdown.c

index 8eecad7..16aef5d 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)shutdown.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)shutdown.c 5.2 (Berkeley) %G%";
 #endif not lint
 
 #include <stdio.h>
 #endif not lint
 
 #include <stdio.h>
@@ -61,14 +61,19 @@ int nlflag = 1;             /* nolog yet to be done */
 int    killflg = 1;
 int    reboot = 0;
 int    halt = 0;
 int    killflg = 1;
 int    reboot = 0;
 int    halt = 0;
+int     fast = 0;
+char    *nosync = NULL;
+char    nosyncflag[] = "-n";
 char   term[sizeof tpath + sizeof utmp.ut_line];
 char   tbuf[BUFSIZ];
 char   nolog1[] = "\n\nNO LOGINS: System going down at %5.5s\n\n";
 char   *nolog2[NLOG+1];
 #ifdef DEBUG
 char   nologin[] = "nologin";
 char   term[sizeof tpath + sizeof utmp.ut_line];
 char   tbuf[BUFSIZ];
 char   nolog1[] = "\n\nNO LOGINS: System going down at %5.5s\n\n";
 char   *nolog2[NLOG+1];
 #ifdef DEBUG
 char   nologin[] = "nologin";
+char    fastboot[] = "fastboot";
 #else
 char   nologin[] = "/etc/nologin";
 #else
 char   nologin[] = "/etc/nologin";
+char   fastboot[] = "/fastboot";
 #endif
 time_t nowtime;
 jmp_buf        alarmbuf;
 #endif
 time_t nowtime;
 jmp_buf        alarmbuf;
@@ -111,6 +116,12 @@ main(argc,argv)
                case 'k':
                        killflg = 0;
                        continue;
                case 'k':
                        killflg = 0;
                        continue;
+               case 'n':
+                       nosync = nosyncflag;
+                       continue;
+               case 'f':
+                       fast = 1;
+                       continue;
                case 'r':
                        reboot = 1;
                        continue;
                case 'r':
                        reboot = 1;
                        continue;
@@ -124,8 +135,12 @@ main(argc,argv)
                argc--, argv++;
        }
        if (argc < 1) {
                argc--, argv++;
        }
        if (argc < 1) {
-               printf("Usage: %s [ -krh ] shutdowntime [ message ]\n",
-                   argv[0]);
+               /* argv[0] is not available after the argument handling. */
+               printf("Usage: shutdown [ -krhfn ] shutdowntime [ message ]\n");
+               finish();
+       }
+       if (fast && (nosync == nosyncflag)) {
+               printf ("shutdown: Incompatible switches 'fast' & 'nosync'\n");
                finish();
        }
        if (geteuid()) {
                finish();
        }
        if (geteuid()) {
@@ -230,18 +245,29 @@ main(argc,argv)
                                printf("but you'll have to do it yourself\n");
                                finish();
                        }
                                printf("but you'll have to do it yourself\n");
                                finish();
                        }
+                       if (fast)
+                               doitfast();
 #ifndef DEBUG
                        kill(-1, SIGTERM);      /* terminate everyone */
                        sleep(5);               /* & wait while they die */
                        if (reboot)
 #ifndef DEBUG
                        kill(-1, SIGTERM);      /* terminate everyone */
                        sleep(5);               /* & wait while they die */
                        if (reboot)
-                               execle(REBOOT, "reboot", 0, 0);
+                               execle(REBOOT, "reboot", nosync, 0, 0);
                        if (halt)
                        if (halt)
-                               execle(HALT, "halt", 0, 0);
+                               execle(HALT, "halt", nosync, 0, 0);
                        kill(1, SIGTERM);       /* sync */
                        kill(1, SIGTERM);       /* sync */
                        sleep(20);
 #else
                        printf("EXTERMINATE EXTERMINATE\n");
                        kill(1, SIGTERM);       /* sync */
                        kill(1, SIGTERM);       /* sync */
                        sleep(20);
 #else
                        printf("EXTERMINATE EXTERMINATE\n");
+                       if (reboot)
+                               printf("REBOOT");
+                       if (halt)
+                               printf(" HALT");
+                       if (fast)
+                               printf(" %s (without fsck's)\n", nosync);
+                       else
+                               printf(" %s\n", nosync);
+
 #endif
                        finish();
                }
 #endif
                        finish();
                }
@@ -341,6 +367,16 @@ warn(term, sdt, now, type)
                fprintf(term, "System going down IMMEDIATELY\r\n");
 }
 
                fprintf(term, "System going down IMMEDIATELY\r\n");
 }
 
+doitfast()
+{
+       FILE *fastd;
+
+       if ((fastd = fopen(fastboot, "w")) != NULL) {
+               putc('\n', fastd);
+               fclose(fastd);
+       }
+}
+
 nolog(sdt)
        time_t sdt;
 {
 nolog(sdt)
        time_t sdt;
 {