optr.c revision 71787
11558Srgrimes/*-
21558Srgrimes * Copyright (c) 1980, 1988, 1993
31558Srgrimes *	The Regents of the University of California.  All rights reserved.
41558Srgrimes *
51558Srgrimes * Redistribution and use in source and binary forms, with or without
61558Srgrimes * modification, are permitted provided that the following conditions
71558Srgrimes * are met:
81558Srgrimes * 1. Redistributions of source code must retain the above copyright
91558Srgrimes *    notice, this list of conditions and the following disclaimer.
101558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111558Srgrimes *    notice, this list of conditions and the following disclaimer in the
121558Srgrimes *    documentation and/or other materials provided with the distribution.
131558Srgrimes * 3. All advertising materials mentioning features or use of this software
141558Srgrimes *    must display the following acknowledgement:
151558Srgrimes *	This product includes software developed by the University of
161558Srgrimes *	California, Berkeley and its contributors.
171558Srgrimes * 4. Neither the name of the University nor the names of its contributors
181558Srgrimes *    may be used to endorse or promote products derived from this software
191558Srgrimes *    without specific prior written permission.
201558Srgrimes *
211558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241558Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311558Srgrimes * SUCH DAMAGE.
321558Srgrimes */
331558Srgrimes
341558Srgrimes#ifndef lint
3536997Scharnier#if 0
361558Srgrimesstatic char sccsid[] = "@(#)optr.c	8.2 (Berkeley) 1/6/94";
3736997Scharnier#endif
3836997Scharnierstatic const char rcsid[] =
3950476Speter  "$FreeBSD: head/sbin/dump/optr.c 71787 2001-01-29 09:45:51Z phk $";
401558Srgrimes#endif /* not lint */
411558Srgrimes
421558Srgrimes#include <sys/param.h>
4371787Sphk#include <sys/queue.h>
441558Srgrimes#include <sys/wait.h>
451558Srgrimes#include <sys/time.h>
461558Srgrimes
471558Srgrimes#include <errno.h>
481558Srgrimes#include <fstab.h>
491558Srgrimes#include <grp.h>
501558Srgrimes#include <stdio.h>
511558Srgrimes#include <stdlib.h>
521558Srgrimes#include <string.h>
531558Srgrimes#include <stdarg.h>
541558Srgrimes#include <unistd.h>
551558Srgrimes#include <utmp.h>
561558Srgrimes
571558Srgrimes#include "dump.h"
581558Srgrimes#include "pathnames.h"
591558Srgrimes
601558Srgrimesvoid	alarmcatch __P((/* int, int */));
611558Srgrimesint	datesort __P((const void *, const void *));
621558Srgrimesstatic	void sendmes __P((char *, char *));
631558Srgrimes
641558Srgrimes/*
651558Srgrimes *	Query the operator; This previously-fascist piece of code
661558Srgrimes *	no longer requires an exact response.
671558Srgrimes *	It is intended to protect dump aborting by inquisitive
681558Srgrimes *	people banging on the console terminal to see what is
691558Srgrimes *	happening which might cause dump to croak, destroying
701558Srgrimes *	a large number of hours of work.
711558Srgrimes *
721558Srgrimes *	Every 2 minutes we reprint the message, alerting others
731558Srgrimes *	that dump needs attention.
741558Srgrimes */
751558Srgrimesstatic	int timeout;
761558Srgrimesstatic	char *attnmessage;		/* attention message */
771558Srgrimes
781558Srgrimesint
791558Srgrimesquery(question)
801558Srgrimes	char	*question;
811558Srgrimes{
821558Srgrimes	char	replybuffer[64];
831558Srgrimes	int	back, errcount;
841558Srgrimes	FILE	*mytty;
851558Srgrimes
861558Srgrimes	if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
871558Srgrimes		quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
881558Srgrimes	attnmessage = question;
891558Srgrimes	timeout = 0;
901558Srgrimes	alarmcatch();
911558Srgrimes	back = -1;
921558Srgrimes	errcount = 0;
931558Srgrimes	do {
941558Srgrimes		if (fgets(replybuffer, 63, mytty) == NULL) {
951558Srgrimes			clearerr(mytty);
961558Srgrimes			if (++errcount > 30)	/* XXX	ugly */
971558Srgrimes				quit("excessive operator query failures\n");
981558Srgrimes		} else if (replybuffer[0] == 'y' || replybuffer[0] == 'Y') {
991558Srgrimes			back = 1;
1001558Srgrimes		} else if (replybuffer[0] == 'n' || replybuffer[0] == 'N') {
1011558Srgrimes			back = 0;
1021558Srgrimes		} else {
1031558Srgrimes			(void) fprintf(stderr,
1041558Srgrimes			    "  DUMP: \"Yes\" or \"No\"?\n");
1051558Srgrimes			(void) fprintf(stderr,
1061558Srgrimes			    "  DUMP: %s: (\"yes\" or \"no\") ", question);
1071558Srgrimes		}
1081558Srgrimes	} while (back < 0);
1091558Srgrimes
1101558Srgrimes	/*
1111558Srgrimes	 *	Turn off the alarm, and reset the signal to trap out..
1121558Srgrimes	 */
1131558Srgrimes	(void) alarm(0);
1141558Srgrimes	if (signal(SIGALRM, sig) == SIG_IGN)
1151558Srgrimes		signal(SIGALRM, SIG_IGN);
1161558Srgrimes	(void) fclose(mytty);
1171558Srgrimes	return(back);
1181558Srgrimes}
1191558Srgrimes
1201558Srgrimeschar lastmsg[100];
1211558Srgrimes
1221558Srgrimes/*
1231558Srgrimes *	Alert the console operator, and enable the alarm clock to
1241558Srgrimes *	sleep for 2 minutes in case nobody comes to satisfy dump
1251558Srgrimes */
1261558Srgrimesvoid
1271558Srgrimesalarmcatch()
1281558Srgrimes{
1291558Srgrimes	if (notify == 0) {
1301558Srgrimes		if (timeout == 0)
1311558Srgrimes			(void) fprintf(stderr,
1321558Srgrimes			    "  DUMP: %s: (\"yes\" or \"no\") ",
1331558Srgrimes			    attnmessage);
1341558Srgrimes		else
13571750Sphk			msgtail("\a\a");
1361558Srgrimes	} else {
1371558Srgrimes		if (timeout) {
1381558Srgrimes			msgtail("\n");
1391558Srgrimes			broadcast("");		/* just print last msg */
1401558Srgrimes		}
1411558Srgrimes		(void) fprintf(stderr,"  DUMP: %s: (\"yes\" or \"no\") ",
1421558Srgrimes		    attnmessage);
1431558Srgrimes	}
1441558Srgrimes	signal(SIGALRM, alarmcatch);
1451558Srgrimes	(void) alarm(120);
1461558Srgrimes	timeout = 1;
1471558Srgrimes}
1481558Srgrimes
1491558Srgrimes/*
1501558Srgrimes *	Here if an inquisitive operator interrupts the dump program
1511558Srgrimes */
1521558Srgrimesvoid
1531558Srgrimesinterrupt(signo)
1541558Srgrimes	int signo;
1551558Srgrimes{
1561558Srgrimes	msg("Interrupt received.\n");
1571558Srgrimes	if (query("Do you want to abort dump?"))
1581558Srgrimes		dumpabort(0);
1591558Srgrimes}
1601558Srgrimes
1611558Srgrimes/*
1621558Srgrimes *	The following variables and routines manage alerting
1631558Srgrimes *	operators to the status of dump.
1641558Srgrimes *	This works much like wall(1) does.
1651558Srgrimes */
1661558Srgrimesstruct	group *gp;
1671558Srgrimes
1681558Srgrimes/*
1691558Srgrimes *	Get the names from the group entry "operator" to notify.
1708871Srgrimes */
1711558Srgrimesvoid
1721558Srgrimesset_operators()
1731558Srgrimes{
1741558Srgrimes	if (!notify)		/*not going to notify*/
1751558Srgrimes		return;
1761558Srgrimes	gp = getgrnam(OPGRENT);
1771558Srgrimes	(void) endgrent();
1781558Srgrimes	if (gp == NULL) {
1791558Srgrimes		msg("No group entry for %s.\n", OPGRENT);
1801558Srgrimes		notify = 0;
1811558Srgrimes		return;
1821558Srgrimes	}
1831558Srgrimes}
1841558Srgrimes
1851558Srgrimesstruct tm *localclock;
1861558Srgrimes
1871558Srgrimes/*
1881558Srgrimes *	We fork a child to do the actual broadcasting, so
1891558Srgrimes *	that the process control groups are not messed up
1901558Srgrimes */
1911558Srgrimesvoid
1921558Srgrimesbroadcast(message)
1931558Srgrimes	char	*message;
1941558Srgrimes{
1951558Srgrimes	time_t		clock;
1961558Srgrimes	FILE	*f_utmp;
1971558Srgrimes	struct	utmp	utmp;
1981558Srgrimes	char	**np;
1991558Srgrimes	int	pid, s;
2001558Srgrimes
2011558Srgrimes	if (!notify || gp == NULL)
2021558Srgrimes		return;
2031558Srgrimes
2041558Srgrimes	switch (pid = fork()) {
2051558Srgrimes	case -1:
2061558Srgrimes		return;
2071558Srgrimes	case 0:
2081558Srgrimes		break;
2091558Srgrimes	default:
2101558Srgrimes		while (wait(&s) != pid)
2111558Srgrimes			continue;
2121558Srgrimes		return;
2131558Srgrimes	}
2141558Srgrimes
2151558Srgrimes	clock = time((time_t *)0);
2161558Srgrimes	localclock = localtime(&clock);
2171558Srgrimes
2181558Srgrimes	if ((f_utmp = fopen(_PATH_UTMP, "r")) == NULL) {
2191558Srgrimes		msg("Cannot open %s: %s\n", _PATH_UTMP, strerror(errno));
2201558Srgrimes		return;
2211558Srgrimes	}
2221558Srgrimes
2231558Srgrimes	while (!feof(f_utmp)) {
2241558Srgrimes		if (fread((char *) &utmp, sizeof (struct utmp), 1, f_utmp) != 1)
2251558Srgrimes			break;
2261558Srgrimes		if (utmp.ut_name[0] == 0)
2271558Srgrimes			continue;
2281558Srgrimes		for (np = gp->gr_mem; *np; np++) {
2291558Srgrimes			if (strncmp(*np, utmp.ut_name, sizeof(utmp.ut_name)) != 0)
2301558Srgrimes				continue;
2311558Srgrimes			/*
2321558Srgrimes			 *	Do not send messages to operators on dialups
2331558Srgrimes			 */
2341558Srgrimes			if (strncmp(utmp.ut_line, DIALUP, strlen(DIALUP)) == 0)
2351558Srgrimes				continue;
2361558Srgrimes#ifdef DEBUG
2371558Srgrimes			msg("Message to %s at %s\n", *np, utmp.ut_line);
2381558Srgrimes#endif
2391558Srgrimes			sendmes(utmp.ut_line, message);
2401558Srgrimes		}
2411558Srgrimes	}
2421558Srgrimes	(void) fclose(f_utmp);
2431558Srgrimes	Exit(0);	/* the wait in this same routine will catch this */
2441558Srgrimes	/* NOTREACHED */
2451558Srgrimes}
2461558Srgrimes
2471558Srgrimesstatic void
2481558Srgrimessendmes(tty, message)
2491558Srgrimes	char *tty, *message;
2501558Srgrimes{
25121409Simp	char t[MAXPATHLEN], buf[BUFSIZ];
2521558Srgrimes	register char *cp;
2531558Srgrimes	int lmsg = 1;
2541558Srgrimes	FILE *f_tty;
2551558Srgrimes
2561558Srgrimes	(void) strcpy(t, _PATH_DEV);
25721409Simp	(void) strncat(t, tty, sizeof t - strlen(_PATH_DEV) - 1);
2581558Srgrimes
2591558Srgrimes	if ((f_tty = fopen(t, "w")) != NULL) {
2601558Srgrimes		setbuf(f_tty, buf);
2611558Srgrimes		(void) fprintf(f_tty,
2621558Srgrimes		    "\n\
26371750Sphk\a\a\aMessage from the dump program to all operators at %d:%02d ...\r\n\n\
2641558SrgrimesDUMP: NEEDS ATTENTION: ",
2651558Srgrimes		    localclock->tm_hour, localclock->tm_min);
2661558Srgrimes		for (cp = lastmsg; ; cp++) {
2671558Srgrimes			if (*cp == '\0') {
2681558Srgrimes				if (lmsg) {
2691558Srgrimes					cp = message;
2701558Srgrimes					if (*cp == '\0')
2711558Srgrimes						break;
2721558Srgrimes					lmsg = 0;
2731558Srgrimes				} else
2741558Srgrimes					break;
2751558Srgrimes			}
2761558Srgrimes			if (*cp == '\n')
2771558Srgrimes				(void) putc('\r', f_tty);
2781558Srgrimes			(void) putc(*cp, f_tty);
2791558Srgrimes		}
2801558Srgrimes		(void) fclose(f_tty);
2811558Srgrimes	}
2821558Srgrimes}
2831558Srgrimes
2841558Srgrimes/*
2851558Srgrimes *	print out an estimate of the amount of time left to do the dump
2861558Srgrimes */
2871558Srgrimes
2881558Srgrimestime_t	tschedule = 0;
2891558Srgrimes
2901558Srgrimesvoid
2911558Srgrimestimeest()
2921558Srgrimes{
2931558Srgrimes	time_t	tnow, deltat;
2941558Srgrimes
2951558Srgrimes	(void) time((time_t *) &tnow);
2961558Srgrimes	if (tnow >= tschedule) {
2971558Srgrimes		tschedule = tnow + 300;
2981558Srgrimes		if (blockswritten < 500)
2998871Srgrimes			return;
3001558Srgrimes		deltat = tstart_writing - tnow +
3011558Srgrimes			(1.0 * (tnow - tstart_writing))
3021558Srgrimes			/ blockswritten * tapesize;
3031558Srgrimes		msg("%3.2f%% done, finished in %d:%02d\n",
3041558Srgrimes			(blockswritten * 100.0) / tapesize,
3051558Srgrimes			deltat / 3600, (deltat % 3600) / 60);
3061558Srgrimes	}
3071558Srgrimes}
3081558Srgrimes
3091558Srgrimesvoid
3101558Srgrimes#if __STDC__
3111558Srgrimesmsg(const char *fmt, ...)
3121558Srgrimes#else
3131558Srgrimesmsg(fmt, va_alist)
3141558Srgrimes	char *fmt;
3151558Srgrimes	va_dcl
3161558Srgrimes#endif
3171558Srgrimes{
3181558Srgrimes	va_list ap;
3191558Srgrimes
3201558Srgrimes	(void) fprintf(stderr,"  DUMP: ");
3211558Srgrimes#ifdef TDEBUG
3221558Srgrimes	(void) fprintf(stderr, "pid=%d ", getpid());
3231558Srgrimes#endif
3241558Srgrimes#if __STDC__
3251558Srgrimes	va_start(ap, fmt);
3261558Srgrimes#else
3271558Srgrimes	va_start(ap);
3281558Srgrimes#endif
3291558Srgrimes	(void) vfprintf(stderr, fmt, ap);
3301558Srgrimes	(void) fflush(stdout);
3311558Srgrimes	(void) fflush(stderr);
33253084Simp	(void) vsnprintf(lastmsg, sizeof(lastmsg), fmt, ap);
3331558Srgrimes	va_end(ap);
3341558Srgrimes}
3351558Srgrimes
3361558Srgrimesvoid
3371558Srgrimes#if __STDC__
3381558Srgrimesmsgtail(const char *fmt, ...)
3391558Srgrimes#else
3401558Srgrimesmsgtail(fmt, va_alist)
3411558Srgrimes	char *fmt;
3421558Srgrimes	va_dcl
3431558Srgrimes#endif
3441558Srgrimes{
3451558Srgrimes	va_list ap;
3461558Srgrimes#if __STDC__
3471558Srgrimes	va_start(ap, fmt);
3481558Srgrimes#else
3491558Srgrimes	va_start(ap);
3501558Srgrimes#endif
3511558Srgrimes	(void) vfprintf(stderr, fmt, ap);
3521558Srgrimes	va_end(ap);
3531558Srgrimes}
3541558Srgrimes
3551558Srgrimesvoid
3561558Srgrimes#if __STDC__
3571558Srgrimesquit(const char *fmt, ...)
3581558Srgrimes#else
3591558Srgrimesquit(fmt, va_alist)
3601558Srgrimes	char *fmt;
3611558Srgrimes	va_dcl
3621558Srgrimes#endif
3631558Srgrimes{
3641558Srgrimes	va_list ap;
3651558Srgrimes
3661558Srgrimes	(void) fprintf(stderr,"  DUMP: ");
3671558Srgrimes#ifdef TDEBUG
3681558Srgrimes	(void) fprintf(stderr, "pid=%d ", getpid());
3691558Srgrimes#endif
3701558Srgrimes#if __STDC__
3711558Srgrimes	va_start(ap, fmt);
3721558Srgrimes#else
3731558Srgrimes	va_start(ap);
3741558Srgrimes#endif
3751558Srgrimes	(void) vfprintf(stderr, fmt, ap);
3761558Srgrimes	va_end(ap);
3771558Srgrimes	(void) fflush(stdout);
3781558Srgrimes	(void) fflush(stderr);
3791558Srgrimes	dumpabort(0);
3801558Srgrimes}
3811558Srgrimes
3821558Srgrimes/*
3831558Srgrimes *	Tell the operator what has to be done;
3841558Srgrimes *	we don't actually do it
3851558Srgrimes */
3861558Srgrimes
3871558Srgrimesstruct fstab *
3881558Srgrimesallocfsent(fs)
3891558Srgrimes	register struct fstab *fs;
3901558Srgrimes{
3911558Srgrimes	register struct fstab *new;
3921558Srgrimes
3931558Srgrimes	new = (struct fstab *)malloc(sizeof (*fs));
3941558Srgrimes	if (new == NULL ||
3951558Srgrimes	    (new->fs_file = strdup(fs->fs_file)) == NULL ||
3961558Srgrimes	    (new->fs_type = strdup(fs->fs_type)) == NULL ||
3971558Srgrimes	    (new->fs_spec = strdup(fs->fs_spec)) == NULL)
3981558Srgrimes		quit("%s\n", strerror(errno));
3991558Srgrimes	new->fs_passno = fs->fs_passno;
4001558Srgrimes	new->fs_freq = fs->fs_freq;
4011558Srgrimes	return (new);
4021558Srgrimes}
4031558Srgrimes
4041558Srgrimesstruct	pfstab {
40571787Sphk	SLIST_ENTRY(pfstab) pf_list;
4061558Srgrimes	struct	fstab *pf_fstab;
4071558Srgrimes};
4081558Srgrimes
40971787Sphkstatic	SLIST_HEAD(, pfstab) table;
4101558Srgrimes
4111558Srgrimesvoid
4121558Srgrimesgetfstab()
4131558Srgrimes{
4141558Srgrimes	register struct fstab *fs;
4151558Srgrimes	register struct pfstab *pf;
4161558Srgrimes
4171558Srgrimes	if (setfsent() == 0) {
4181558Srgrimes		msg("Can't open %s for dump table information: %s\n",
4191558Srgrimes		    _PATH_FSTAB, strerror(errno));
4201558Srgrimes		return;
4211558Srgrimes	}
4221558Srgrimes	while ((fs = getfsent()) != NULL) {
4231558Srgrimes		if (strcmp(fs->fs_type, FSTAB_RW) &&
4241558Srgrimes		    strcmp(fs->fs_type, FSTAB_RO) &&
4251558Srgrimes		    strcmp(fs->fs_type, FSTAB_RQ))
4261558Srgrimes			continue;
4271558Srgrimes		fs = allocfsent(fs);
4281558Srgrimes		if ((pf = (struct pfstab *)malloc(sizeof (*pf))) == NULL)
4291558Srgrimes			quit("%s\n", strerror(errno));
4301558Srgrimes		pf->pf_fstab = fs;
43171787Sphk		SLIST_INSERT_HEAD(&table, pf, pf_list);
4321558Srgrimes	}
4331558Srgrimes	(void) endfsent();
4341558Srgrimes}
4351558Srgrimes
4361558Srgrimes/*
4371558Srgrimes * Search in the fstab for a file name.
4381558Srgrimes * This file name can be either the special or the path file name.
4391558Srgrimes *
4401558Srgrimes * The file name can omit the leading '/'.
4411558Srgrimes */
4421558Srgrimesstruct fstab *
4431558Srgrimesfstabsearch(key)
4441558Srgrimes	char *key;
4451558Srgrimes{
4461558Srgrimes	register struct pfstab *pf;
4471558Srgrimes	register struct fstab *fs;
4481558Srgrimes	char *rn;
4491558Srgrimes
45071787Sphk	SLIST_FOREACH(pf, &table, pf_list) {
4511558Srgrimes		fs = pf->pf_fstab;
4521558Srgrimes		if (strcmp(fs->fs_file, key) == 0 ||
4531558Srgrimes		    strcmp(fs->fs_spec, key) == 0)
4541558Srgrimes			return (fs);
4551558Srgrimes		rn = rawname(fs->fs_spec);
4561558Srgrimes		if (rn != NULL && strcmp(rn, key) == 0)
4571558Srgrimes			return (fs);
4581558Srgrimes		if (key[0] != '/') {
4591558Srgrimes			if (*fs->fs_spec == '/' &&
4601558Srgrimes			    strcmp(fs->fs_spec + 1, key) == 0)
4611558Srgrimes				return (fs);
4621558Srgrimes			if (*fs->fs_file == '/' &&
4631558Srgrimes			    strcmp(fs->fs_file + 1, key) == 0)
4641558Srgrimes				return (fs);
4651558Srgrimes		}
4661558Srgrimes	}
4671558Srgrimes	return (NULL);
4681558Srgrimes}
4691558Srgrimes
4701558Srgrimes/*
4711558Srgrimes *	Tell the operator what to do
4721558Srgrimes */
4731558Srgrimesvoid
4741558Srgrimeslastdump(arg)
4751558Srgrimes	char	arg;	/* w ==> just what to do; W ==> most recent dumps */
4761558Srgrimes{
4771558Srgrimes	register int i;
4781558Srgrimes	register struct fstab *dt;
4791558Srgrimes	register struct dumpdates *dtwalk;
4801558Srgrimes	char *lastname, *date;
4811558Srgrimes	int dumpme;
48248447Sjkh	time_t tnow;
48348447Sjkh	struct tm *tlast;
4841558Srgrimes
4851558Srgrimes	(void) time(&tnow);
4861558Srgrimes	getfstab();		/* /etc/fstab input */
4871558Srgrimes	initdumptimes();	/* /etc/dumpdates input */
4881558Srgrimes	qsort((char *) ddatev, nddates, sizeof(struct dumpdates *), datesort);
4891558Srgrimes
4901558Srgrimes	if (arg == 'w')
4911558Srgrimes		(void) printf("Dump these file systems:\n");
4921558Srgrimes	else
4931558Srgrimes		(void) printf("Last dump(s) done (Dump '>' file systems):\n");
4941558Srgrimes	lastname = "??";
4951558Srgrimes	ITITERATE(i, dtwalk) {
4961558Srgrimes		if (strncmp(lastname, dtwalk->dd_name,
4971558Srgrimes		    sizeof(dtwalk->dd_name)) == 0)
4981558Srgrimes			continue;
49948447Sjkh		date = (char *)ctime(&dtwalk->dd_ddate);
5001558Srgrimes		date[16] = '\0';	/* blast away seconds and year */
5011558Srgrimes		lastname = dtwalk->dd_name;
5021558Srgrimes		dt = fstabsearch(dtwalk->dd_name);
50348447Sjkh		dumpme = (dt != NULL && dt->fs_freq != 0);
50448447Sjkh		if (dumpme) {
50548447Sjkh		    tlast = localtime(&dtwalk->dd_ddate);
50648447Sjkh		    dumpme = tnow > (dtwalk->dd_ddate - (tlast->tm_hour * 3600)
50748447Sjkh				     - (tlast->tm_min * 60) - tlast->tm_sec
50848447Sjkh				     + (dt->fs_freq * 86400));
50948447Sjkh		};
5101558Srgrimes		if (arg != 'w' || dumpme)
5111558Srgrimes			(void) printf(
5121558Srgrimes			    "%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
5131558Srgrimes			    dumpme && (arg != 'w') ? '>' : ' ',
5141558Srgrimes			    dtwalk->dd_name,
5151558Srgrimes			    dt ? dt->fs_file : "",
5161558Srgrimes			    dtwalk->dd_level,
5171558Srgrimes			    date);
5181558Srgrimes	}
5191558Srgrimes}
5201558Srgrimes
5211558Srgrimesint
5221558Srgrimesdatesort(a1, a2)
5231558Srgrimes	const void *a1, *a2;
5241558Srgrimes{
5251558Srgrimes	struct dumpdates *d1 = *(struct dumpdates **)a1;
5261558Srgrimes	struct dumpdates *d2 = *(struct dumpdates **)a2;
5271558Srgrimes	int diff;
5281558Srgrimes
5291558Srgrimes	diff = strncmp(d1->dd_name, d2->dd_name, sizeof(d1->dd_name));
5301558Srgrimes	if (diff == 0)
5311558Srgrimes		return (d2->dd_ddate - d1->dd_ddate);
5321558Srgrimes	return (diff);
5331558Srgrimes}
534