From a152a6a92ae8f48b8185c80c37a289cf97826b7c Mon Sep 17 00:00:00 2001 From: blymn Date: Mon, 15 Oct 2001 13:25:33 +0000 Subject: [PATCH] Add the capability for dump to print timestamps on all informational messages. --- sbin/dump/dump.8 | 31 ++++++++++++++++++++++++++++--- sbin/dump/dump.h | 3 ++- sbin/dump/main.c | 26 +++++++++++++++++++------- sbin/dump/optr.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 93 insertions(+), 15 deletions(-) diff --git a/sbin/dump/dump.8 b/sbin/dump/dump.8 index 335a74864e2d..21e02bd96617 100644 --- a/sbin/dump/dump.8 +++ b/sbin/dump/dump.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: dump.8,v 1.38 2001/08/14 06:51:36 lukem Exp $ +.\" $NetBSD: dump.8,v 1.39 2001/10/15 13:25:33 blymn Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" Regents of the University of California. @@ -43,7 +43,7 @@ .Nd file system backup .Sh SYNOPSIS .Nm "" -.Op Fl 0123456789ceFnSu +.Op Fl 0123456789ceFnStu .Op Fl B Ar records .Op Fl b Ar blocksize .Op Fl d Ar density @@ -227,6 +227,12 @@ The default tape length is 2300 feet. .It Fl S Display an estimate of the backup size and the number of tapes required, and exit without actually performing the dump. +.It Fl t +All informational log messages printed by +.Nm +will have the time prepended to them. Also, the completion time +interval estimations will have the estimated time at which the dump +will complete printed at the end of the line. .It Fl T Ar date Use the specified date as the starting time for the dump instead of the time determined from looking in @@ -419,6 +425,24 @@ rather than to invoke .Xr rmt 8 on the remote machine. +.It Ev TIMEFORMAT +can be used to control the format of the timestamps produced by the +.Fl t +option. +.Ev TIMEFORMAT +is a string containing embedded formatting commands for +.Xr strftime 3 . +The total formatted string is limited to about 80 characters, if this +limit is exceeded then +.Qo +ERROR: TIMEFORMAT too long, reverting to default +.Qc +will be printed and the time format will revert to the default one. If +.Ev TIMEFORMAT +is not set then the format string defaults to +.Qo +%T %Z +.Qc .El .Sh FILES .Bl -tag -width /etc/dumpdates -compact @@ -444,7 +468,8 @@ to find group .Xr fstab 5 , .Xr restore 8 , .Xr rmt 8 , -.Xr st 4 +.Xr st 4 , +.Xr environ 7 .Sh DIAGNOSTICS Many, and verbose. .Pp diff --git a/sbin/dump/dump.h b/sbin/dump/dump.h index 4edd6c1a0201..20e798e7e427 100644 --- a/sbin/dump/dump.h +++ b/sbin/dump/dump.h @@ -1,4 +1,4 @@ -/* $NetBSD: dump.h,v 1.28 2001/08/14 05:44:44 lukem Exp $ */ +/* $NetBSD: dump.h,v 1.29 2001/10/15 13:25:34 blymn Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -111,6 +111,7 @@ int nonodump; /* if set, do not honor UF_NODUMP user flags */ extern int density; /* density in 0.1" units */ extern int notify; /* notify operator flag */ +extern int timestamp; /* timestamp messages */ extern int blockswritten; /* number of blocks written on current tape */ extern int tapeno; /* current tape number */ diff --git a/sbin/dump/main.c b/sbin/dump/main.c index 87ed06dbe988..41d02e15baf7 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.38 2001/08/14 06:51:37 lukem Exp $ */ +/* $NetBSD: main.c,v 1.39 2001/10/15 13:25:34 blymn Exp $ */ /*- * Copyright (c) 1980, 1991, 1993, 1994 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\n\ #if 0 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/1/95"; #else -__RCSID("$NetBSD: main.c,v 1.38 2001/08/14 06:51:37 lukem Exp $"); +__RCSID("$NetBSD: main.c,v 1.39 2001/10/15 13:25:34 blymn Exp $"); #endif #endif /* not lint */ @@ -81,6 +81,7 @@ __RCSID("$NetBSD: main.c,v 1.38 2001/08/14 06:51:37 lukem Exp $"); #include "pathnames.h" gid_t egid; /* Retain tty privs for notification */ +int timestamp; /* print message timestamps */ int notify; /* notify operator flag */ int blockswritten; /* number of blocks written on current tape */ int tapeno; /* current tape number */ @@ -92,6 +93,8 @@ long blocksperfile; /* output blocks per file */ char *host; /* remote host (if any) */ int readcache = -1; /* read cache size (in readblksize blks) */ int readblksize = 32 * 1024; /* read block size */ +char default_time_string[] = "%T %Z"; /* default timestamp string */ +char *time_string = default_time_string; /* timestamp string */ int main(int, char *[]); static long numarg(char *, long, long); @@ -115,10 +118,14 @@ main(int argc, char *argv[]) char *mountpoint; int just_estimate = 0; char labelstr[LBLSIZE]; - + char *new_time_format; + spcl.c_date = 0; (void)time((time_t *)&spcl.c_date); - + tzset(); /* set up timezone for strftime */ + if ((new_time_format = getenv("TIMEFORMAT")) != NULL) + time_string = new_time_format; + /* Save setgid bit for use later */ egid = getegid(); setegid(getgid()); @@ -132,13 +139,14 @@ main(int argc, char *argv[]) if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) quit("TP_BSIZE must be a multiple of DEV_BSIZE\n"); level = '0'; - + timestamp = 0; + if (argc < 2) usage(); obsolete(&argc, &argv); while ((ch = getopt(argc, argv, - "0123456789B:b:cd:eFf:h:k:L:nr:s:ST:uWw")) != -1) + "0123456789B:b:cd:eFf:h:k:L:nr:s:StT:uWw")) != -1) switch (ch) { /* dump level */ case '0': case '1': case '2': case '3': case '4': @@ -217,6 +225,10 @@ main(int argc, char *argv[]) just_estimate = 1; break; + case 't': + timestamp = 1; + break; + case 'T': /* time of last dump */ spcl.c_ddate = unctime(optarg); if (spcl.c_ddate < 0) { @@ -595,7 +607,7 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", -"usage: dump [-0123456789ceFnu] [-B records] [-b blocksize] [-d density]", +"usage: dump [-0123456789ceFntu] [-B records] [-b blocksize] [-d density]", " [-f file] [-h level] [-k read block size] [-L label]", " [-r read cache size] [-s feet] [-T date] file system", " dump [-W | -w]"); diff --git a/sbin/dump/optr.c b/sbin/dump/optr.c index f931eba8182a..ee2530f77c35 100644 --- a/sbin/dump/optr.c +++ b/sbin/dump/optr.c @@ -1,4 +1,4 @@ -/* $NetBSD: optr.c,v 1.18 2001/08/08 16:49:54 david Exp $ */ +/* $NetBSD: optr.c,v 1.19 2001/10/15 13:25:34 blymn Exp $ */ /*- * Copyright (c) 1980, 1988, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)optr.c 8.2 (Berkeley) 1/6/94"; #else -__RCSID("$NetBSD: optr.c,v 1.18 2001/08/08 16:49:54 david Exp $"); +__RCSID("$NetBSD: optr.c,v 1.19 2001/10/15 13:25:34 blymn Exp $"); #endif #endif /* not lint */ @@ -69,6 +69,10 @@ struct fstab *allocfsent(struct fstab *); int datesort(const void *, const void *); static void sendmes(char *, char *); extern gid_t egid; +extern char *time_string; +extern char default_time_string[]; + +static void do_timestamp(time_t time, char *msg); /* * Query the operator; This previously-fascist piece of code @@ -304,6 +308,29 @@ DUMP: NEEDS ATTENTION: ", } } +/* + * print out the timestamp string to stderr. + */ +#define STAMP_LENGTH 80 + +static void +do_timestamp(time_t time, char *msg) +{ + struct tm tm_time; + char then[STAMP_LENGTH + 1]; + + (void) localtime_r(&time, &tm_time); + if (strftime(then, STAMP_LENGTH, time_string, &tm_time) == 0) { + time_string = default_time_string; + strftime(then, STAMP_LENGTH, time_string, &tm_time); + fprintf(stderr, + "DUMP: ERROR: TIMEFORMAT too long, reverting to default\n"); + } + + fprintf(stderr, msg, then); +} + + /* * print out an estimate of the amount of time left to do the dump */ @@ -323,18 +350,31 @@ timeest(void) deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing)) / blockswritten * tapesize; - msg("%3.2f%% done, finished in %ld:%02ld\n", + + msg("%3.2f%% done, finished in %ld:%02ld", (blockswritten * 100.0) / tapesize, (long)(deltat / 3600), (long)((deltat % 3600) / 60)); + + if (timestamp == 1) + do_timestamp(tnow + deltat, " (at %s)"); + + fprintf(stderr, "\n"); } } void msg(const char *fmt, ...) { + time_t tnow; va_list ap; - (void) fprintf(stderr," DUMP: "); + fprintf(stderr, " "); + if (timestamp == 1) { + (void) time((time_t *) &tnow); + do_timestamp(tnow, "[%s] "); + } + + (void) fprintf(stderr,"DUMP: "); #ifdef TDEBUG (void) fprintf(stderr, "pid=%d ", getpid()); #endif