X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=dump%2Foptr.c;h=81823a7865a0e7d26f6a9248ea87ca209c9ddbe2;hp=99d7295cbb04ae5470ffcc5abb47dce027dc5199;hb=a18d599791e977f3e3d26123031e6ed4e64d6d08;hpb=109e9e1d1a904627eeae4d519a0f694795b2892c diff --git a/dump/optr.c b/dump/optr.c index 99d7295..81823a7 100644 --- a/dump/optr.c +++ b/dump/optr.c @@ -2,8 +2,8 @@ * Ported to Linux's Second Extended File System as part of the * dump and restore backup suit * Remy Card , 1994-1997 - * Stelian Pop , 1999-2000 - * Stelian Pop - Alcôve , 2000 + * Stelian Pop , 1999-2000 + * Stelian Pop - Alcôve , 2000-2002 */ /*- @@ -41,12 +41,14 @@ #ifndef lint static const char rcsid[] = - "$Id: optr.c,v 1.16 2000/12/04 15:43:16 stelian Exp $"; + "$Id: optr.c,v 1.32 2002/07/19 14:57:39 stelian Exp $"; #endif /* not lint */ +#include #include #include #include +#include #include #include @@ -60,7 +62,11 @@ static const char rcsid[] = #include #ifdef __linux__ +#ifdef HAVE_EXT2FS_EXT2_FS_H +#include +#else #include +#endif #include #include #include @@ -99,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)); @@ -136,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); } @@ -157,7 +161,7 @@ char lastmsg[BUFSIZ]; * sleep for 2 minutes in case nobody comes to satisfy dump */ static void -alarmcatch(int signo) +alarmcatch(UNUSED(int signo)) { int save_errno = errno; if (notify == 0) { @@ -185,7 +189,7 @@ alarmcatch(int signo) * Here if an inquisitive operator interrupts the dump program */ void -interrupt(int signo) +interrupt(UNUSED(int signo)) { msg("Interrupt received.\n"); if (query("Do you want to abort dump?")) @@ -245,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) { @@ -281,7 +285,7 @@ static void sendmes(const char *tty, const char *message) { char t[MAXPATHLEN], buf[BUFSIZ]; - register const char *cp; + const char *cp; int lmsg = 1; FILE *f_tty; @@ -322,25 +326,16 @@ time_t tschedule = 0; void timeest(void) { - time_t tnow, deltat; + 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; - if (blockswritten < 500) - return; - if (blockswritten > tapesize) - tapesize = blockswritten; - deltat = tstart_writing - tnow + - (1.0 * (tnow - tstart_writing)) - / blockswritten * tapesize; - msg("%3.2f%% done, finished in %d:%02d\n", - (blockswritten * 100.0) / tapesize, - deltat / 3600, (deltat % 3600) / 60); + if (buf) { + fprintf(stderr, " DUMP: "); + fwrite(buf, strlen(buf), 1, stderr); + fflush(stderr); + } } } @@ -431,7 +426,7 @@ quit(fmt, va_alist) static struct fstab * allocfsent(struct fstab *fs) { - register struct fstab *new; + struct fstab *new; new = (struct fstab *)malloc(sizeof (*fs)); if (new == NULL) @@ -505,9 +500,9 @@ getfstab(void) struct fstab * fstabsearch(const char *key) { - register struct pfstab *pf; - register struct fstab *fs; - char *rn; + struct pfstab *pf; + struct fstab *fs; + const char *rn; for (pf = table; pf != NULL; pf = pf->pf_next) { fs = pf->pf_fstab; @@ -533,9 +528,9 @@ fstabsearch(const char *key) struct fstab * fstabsearchdir(const char *key, char *directory) { - register struct pfstab *pf; - register struct fstab *fs; - register struct fstab *found_fs = NULL; + struct pfstab *pf; + struct fstab *fs; + struct fstab *found_fs = NULL; unsigned int size = 0; struct stat buf; @@ -545,7 +540,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] == '/')) { @@ -570,15 +565,9 @@ static void print_wmsg(char arg, int dumpme, const char *dev, int level, const char *mtpt, time_t ddate) { - char *date; - - 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; @@ -587,10 +576,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"); } @@ -603,7 +600,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) { @@ -617,6 +614,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; @@ -635,16 +633,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 } } } @@ -658,9 +659,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); }