]> git.wh0rd.org - dump.git/blobdiff - dump/optr.c
noos -> popies.net
[dump.git] / dump / optr.c
index 9383cf6b69614f1378bc9daadb5e67859004adf0..73347fabdc2dc743c8d9373fc16da88fc2ca2ca4 100644 (file)
@@ -2,8 +2,8 @@
  *     Ported to Linux's Second Extended File System as part of the
  *     dump and restore backup suit
  *     Remy Card <card@Linux.EU.Org>, 1994-1997
- *     Stelian Pop <pop@noos.fr>, 1999-2000
- *     Stelian Pop <pop@noos.fr> - Alcôve <www.alcove.fr>, 2000
+ *     Stelian Pop <stelian@popies.net>, 1999-2000
+ *     Stelian Pop <stelian@popies.net> - Alcôve <www.alcove.com>, 2000-2002
  */
 
 /*-
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: optr.c,v 1.19 2001/02/21 16:13:05 stelian Exp $";
+       "$Id: optr.c,v 1.29 2002/01/16 09:32:14 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
 #include <sys/param.h>
 #include <sys/wait.h>
 #include <sys/time.h>
+#include <time.h>
 
 #include <errno.h>
 #include <fstab.h>
@@ -61,7 +62,11 @@ static const char rcsid[] =
 #include <sys/stat.h>
 
 #ifdef __linux__
+#ifdef HAVE_EXT2FS_EXT2_FS_H
+#include <ext2fs/ext2_fs.h>
+#else
 #include <linux/ext2_fs.h>
+#endif
 #include <ext2fs/ext2fs.h>
 #include <bsdcompat.h>
 #include <signal.h>
@@ -100,11 +105,13 @@ query(const char *question)
        FILE    *mytty;
        time_t  firstprompt, when_answered;
 
-#ifdef __linux__
-       (void)time4(&(firstprompt));
-#else
-       (void)time((time_t *)&(firstprompt));
-#endif
+       if (qflag) {
+               msg("%s - forced abort\n", question);
+               dumpabort(0);
+               /* NOTREACHED */
+       }
+
+       firstprompt = time(NULL);
 
        if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
                quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
@@ -137,16 +144,12 @@ query(const char *question)
        if (signal(SIGALRM, sig) == SIG_IGN)
                signal(SIGALRM, SIG_IGN);
        (void) fclose(mytty);
-#ifdef __linux__
-       (void)time4(&(when_answered));
-#else
-       (void)time((time_t *)&(when_answered));
-#endif
+       when_answered = time(NULL);
        /*
         * Adjust the base for time estimates to ignore time we spent waiting
         * for operator input.
         */
-       if ((tstart_writing != 0) && (when_answered != (time_t)-1) && (firstprompt != (time_t)-1))
+       if (tstart_writing != 0)
                tstart_writing += (when_answered - firstprompt);
        return(back);
 }
@@ -246,7 +249,7 @@ broadcast(const char *message)
                return;
        }
 
-       clock = time((time_t *)0);
+       clock = time(NULL);
        localclock = localtime(&clock);
 
        if ((f_utmp = fopen(_PATH_UTMP, "r")) == NULL) {
@@ -323,13 +326,8 @@ time_t     tschedule = 0;
 void
 timeest(void)
 {
-       time_t tnow;
+       time_t tnow = time(NULL);
 
-#ifdef __linux__
-       (void) time4(&tnow);
-#else
-       (void) time((time_t *) &tnow);
-#endif
        if (tnow >= tschedule) {
                char *buf = mktimeest(tnow);
                tschedule = tnow + 300;
@@ -471,7 +469,6 @@ getfstab(void)
                    strcmp(fs->fs_type, FSTAB_RQ))
                        continue;
                fs = allocfsent(fs);
-               fs->fs_passno = 0;
                if ((pf = (struct pfstab *)malloc(sizeof (*pf))) == NULL)
                        quit("%s\n", strerror(errno));
                pf->pf_fstab = fs;
@@ -504,7 +501,7 @@ fstabsearch(const char *key)
 {
        register struct pfstab *pf;
        register struct fstab *fs;
-       char *rn;
+       const char *rn;
 
        for (pf = table; pf != NULL; pf = pf->pf_next) {
                fs = pf->pf_fstab;
@@ -542,7 +539,7 @@ fstabsearchdir(const char *key, char *directory)
        for (pf = table; pf != NULL; pf = pf->pf_next) {
                fs = pf->pf_fstab;
                if (strlen(fs->fs_file) > size &&
-                   strlen(key) > strlen(fs->fs_file) + 1 &&
+                   strlen(key) > strlen(fs->fs_file) &&
                    strncmp(fs->fs_file, key, strlen(fs->fs_file)) == 0 &&
                    (key[strlen(fs->fs_file)] == '/' ||
                     fs->fs_file[strlen(fs->fs_file) - 1] == '/')) {
@@ -567,15 +564,9 @@ static void
 print_wmsg(char arg, int dumpme, const char *dev, int level,
           const char *mtpt, time_t ddate)
 {
-       char *date = NULL;
-       
-       if (ddate) {
-               char *d;
-               date = (char *)ctime(&ddate);
-               d = strchr(date, '\n');
-               if (d) *d = '\0';
-       }
-
+#ifdef FDEBUG
+       printf("checking dev %s: lvl %d, mtpt %s\n", dev, level, mtpt);
+#endif
        if (!dumpme && arg == 'w')
                return;
 
@@ -584,10 +575,18 @@ print_wmsg(char arg, int dumpme, const char *dev, int level,
                      dev,
                      mtpt ? mtpt : "");
 
-       if (ddate)
-               printf("Level %c, Date %s\n",
-                     level, date);
-       else
+       /*
+        * Check ddate > 365 to avoid issues with fs in stab but not dumpdates.
+        * Not a problem, because ddate is in seconds since the epoch anyways.
+        */
+       if (ddate > 365) {
+               char *date, *d;
+
+               date = (char *)ctime(&ddate);
+               d = strchr(date, '\n');
+               if (d) *d = '\0';
+               printf("Level %c, Date %s\n", level, date);
+       } else
                printf("never\n");
 }
 
@@ -600,7 +599,7 @@ lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */
        struct pfstab *pf;
        time_t tnow;
 
-       (void) time(&tnow);
+       tnow = time(NULL);
        getfstab();             /* /etc/fstab input */
        initdumptimes(0);       /* dumpdates input */
        if (ddatev == NULL && table == NULL) {
@@ -614,6 +613,7 @@ lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */
        else
                (void) printf("Last dump(s) done (Dump '>' file systems):\n");
 
+       /* For files in dumpdates, get the last dump level and date */
        if (ddatev != NULL) {
                struct dumpdates *dtwalk = NULL;
                int i;
@@ -632,16 +632,19 @@ lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */
                                /* Overload fs_freq as dump level and
                                 * fs_passno as date, because we can't
                                 * change struct fstab format.
-                                * A negative fs_freq means this
+                                * A positive fs_freq means this
                                 * filesystem needs to be dumped.
                                 */
                                dt->fs_passno = dtwalk->dd_ddate;
                                if (dt->fs_freq > 0 && (dtwalk->dd_ddate <
                                    tnow - (dt->fs_freq * 86400)))
-                                       dt->fs_freq = -dtwalk->dd_level - 1;
+                                       dt->fs_freq = dtwalk->dd_level;
                                else
-                                       dt->fs_freq = dtwalk->dd_level + 1;
-
+                                       dt->fs_freq = -dtwalk->dd_level;
+#ifdef FDEBUG
+                               printf("%s fs_freq set to %d\n", lastname,
+                                       dt->fs_freq);
+#endif
                        }
                }
        }
@@ -655,9 +658,10 @@ lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */
                        if (strncmp(dt->fs_vfstype, *type,
                                    sizeof(dt->fs_vfstype)) == 0) {
                                const char *disk = get_device_name(dt->fs_spec);
-                               print_wmsg(arg, dt->fs_freq < 0,
+                               print_wmsg(arg, dt->fs_freq > 0,
                                           disk ? disk : dt->fs_spec,
-                                          dt->fs_freq < 0 ? -dt->fs_freq - 1 : dt->fs_freq - 1, 
+                                          dt->fs_freq < 0 ? -dt->fs_freq :
+                                                             dt->fs_freq,
                                           dt->fs_file,
                                           dt->fs_passno);
                        }