BSD 4_1_snap release
[unix-history] / usr / src / cmd / dumpdir.c
index d091951..29f67ae 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)dumpdir.c   4.2 (Berkeley) 11/15/80";
+static char *sccsid = "@(#)dumpdir.c   4.4 (Berkeley) 2/28/81";
 #define MAXINO 2000
 #define BITS   8
 #define MAXXTR 60
 #define MAXINO 2000
 #define BITS   8
 #define MAXXTR 60
@@ -12,6 +12,7 @@ static char *sccsid = "@(#)dumpdir.c  4.2 (Berkeley) 11/15/80";
 #include <sys/filsys.h>
 #include <sys/dir.h>
 #include <dumprestor.h>
 #include <sys/filsys.h>
 #include <sys/dir.h>
 #include <dumprestor.h>
+#include <signal.h>
 
 #define        MWORD(m,i) (m[(unsigned)(i-1)/MLEN])
 #define        MBIT(i) (1<<((unsigned)(i-1)%MLEN))
 
 #define        MWORD(m,i) (m[(unsigned)(i-1)/MLEN])
 #define        MBIT(i) (1<<((unsigned)(i-1)%MLEN))
@@ -53,38 +54,56 @@ main(argc, argv)
 char *argv[];
 {
        extern char *ctime();
 char *argv[];
 {
        extern char *ctime();
+       int interrupt();
 
        mktemp(dirfile);
 
        mktemp(dirfile);
+       signal(SIGINT, interrupt);
        argv++;
        if (argc>=3 && *argv[0] == 'f')
                magtape = *++argv;
        df = fopen(dirfile, "w");
        if (df == NULL) {
                printf("dumpdir: %s - cannot create directory temporary\n", dirfile);
        argv++;
        if (argc>=3 && *argv[0] == 'f')
                magtape = *++argv;
        df = fopen(dirfile, "w");
        if (df == NULL) {
                printf("dumpdir: %s - cannot create directory temporary\n", dirfile);
-               exit(1);
+               quit();
        }
 
        if ((mt = open(magtape, 0)) < 0) {
                printf("%s: cannot open tape\n", magtape);
        }
 
        if ((mt = open(magtape, 0)) < 0) {
                printf("%s: cannot open tape\n", magtape);
-               exit(1);
+               quit();
        }
        if (readhdr(&spcl) == 0) {
                printf("Tape is not a dump tape\n");
        }
        if (readhdr(&spcl) == 0) {
                printf("Tape is not a dump tape\n");
-               exit(1);
+               quit();
        }
        printf("Dump   date: %s", ctime(&spcl.c_date));
        printf("Dumped from: %s", ctime(&spcl.c_ddate));
        if (checkvol(&spcl, 1) == 0) {
                printf("Tape is not volume 1 of the dump\n");
        }
        printf("Dump   date: %s", ctime(&spcl.c_date));
        printf("Dumped from: %s", ctime(&spcl.c_ddate));
        if (checkvol(&spcl, 1) == 0) {
                printf("Tape is not volume 1 of the dump\n");
-               exit(1);
+               quit();
        }
        pass1();  /* This sets the various maps on the way by */
        freopen(dirfile, "r", df);
        strcpy(prebuf, "/");
        printem(prebuf, (ino_t) 2);
        }
        pass1();  /* This sets the various maps on the way by */
        freopen(dirfile, "r", df);
        strcpy(prebuf, "/");
        printem(prebuf, (ino_t) 2);
+       quit();
+}
+
+/*
+ * Interrupt -- Quit properly
+ */
+
+interrupt()
+{
+       unlink(dirfile);
+       exit(1);
+}
+
+quit()
+{
+       unlink(dirfile);
        exit(0);
 }
        exit(0);
 }
-       i = 0;
+
 /*
  * Read the tape, bulding up a directory structure for extraction
  * by name
 /*
  * Read the tape, bulding up a directory structure for extraction
  * by name
@@ -223,9 +242,8 @@ char *b;
                for (i = 0; i < NTREC; i++)
                        ((struct spcl *)&tbf[i*BSIZE])->c_magic = 0;
                bct = 0;
                for (i = 0; i < NTREC; i++)
                        ((struct spcl *)&tbf[i*BSIZE])->c_magic = 0;
                bct = 0;
-               if ((i = read(mt, tbf, NTREC*BSIZE)) < 0) {
-                       exit(1);
-               }
+               if ((i = read(mt, tbf, NTREC*BSIZE)) < 0)
+                       quit();
                if (i == 0) {
                        bct = NTREC + 1;
                        volno++;
                if (i == 0) {
                        bct = NTREC + 1;
                        volno++;