2 * Copyright (c) 1980, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static char sccsid[] = "@(#)optr.c 8.2 (Berkeley) 1/6/94";
38 static const char rcsid[] =
42 #include <sys/param.h>
43 #include <sys/queue.h>
59 #include "pathnames.h"
62 int datesort(const void *, const void *);
65 * Query the operator; This previously-fascist piece of code
66 * no longer requires an exact response.
67 * It is intended to protect dump aborting by inquisitive
68 * people banging on the console terminal to see what is
69 * happening which might cause dump to croak, destroying
70 * a large number of hours of work.
72 * Every 2 minutes we reprint the message, alerting others
73 * that dump needs attention.
76 static const char *attnmessage; /* attention message */
79 query(const char *question)
85 if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
86 quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
87 attnmessage = question;
93 if (fgets(replybuffer, 63, mytty) == NULL) {
95 if (++errcount > 30) /* XXX ugly */
96 quit("excessive operator query failures\n");
97 } else if (replybuffer[0] == 'y' || replybuffer[0] == 'Y') {
99 } else if (replybuffer[0] == 'n' || replybuffer[0] == 'N') {
102 (void) fprintf(stderr,
103 " DUMP: \"Yes\" or \"No\"?\n");
104 (void) fprintf(stderr,
105 " DUMP: %s: (\"yes\" or \"no\") ", question);
110 * Turn off the alarm, and reset the signal to trap out..
113 if (signal(SIGALRM, sig) == SIG_IGN)
114 signal(SIGALRM, SIG_IGN);
115 (void) fclose(mytty);
119 char lastmsg[BUFSIZ];
122 * Alert the console operator, and enable the alarm clock to
123 * sleep for 2 minutes in case nobody comes to satisfy dump
126 alarmcatch(int sig __unused)
130 (void) fprintf(stderr,
131 " DUMP: %s: (\"yes\" or \"no\") ",
138 broadcast(""); /* just print last msg */
140 (void) fprintf(stderr," DUMP: %s: (\"yes\" or \"no\") ",
143 signal(SIGALRM, alarmcatch);
149 * Here if an inquisitive operator interrupts the dump program
152 interrupt(int signo __unused)
154 msg("Interrupt received.\n");
155 if (query("Do you want to abort dump?"))
160 * We now use wall(1) to do the actual broadcasting.
163 broadcast(const char *message)
166 char buf[sizeof(_PATH_WALL) + sizeof(OPGRENT) + 3];
171 snprintf(buf, sizeof(buf), "%s -g %s", _PATH_WALL, OPGRENT);
172 if ((fp = popen(buf, "w")) == NULL)
175 (void) fputs("\a\a\aMessage from the dump program to all operators\n\nDUMP: NEEDS ATTENTION: ", fp);
177 (void) fputs(lastmsg, fp);
179 (void) fputs(message, fp);
185 * Print out an estimate of the amount of time left to do the dump
188 time_t tschedule = 0;
195 int deltat, hours, mins;
198 deltat = (blockswritten == 0) ? 0 : tstart_writing - tnow +
199 (double)(tnow - tstart_writing) / blockswritten * tapesize;
200 percent = (blockswritten * 100.0) / tapesize;
201 hours = deltat / 3600;
202 mins = (deltat % 3600) / 60;
204 setproctitle("%s: pass %d: %3.2f%% done, finished in %d:%02d",
205 disk, passno, percent, hours, mins);
206 if (tnow >= tschedule) {
207 tschedule = tnow + 300;
208 if (blockswritten < 500)
210 msg("%3.2f%% done, finished in %d:%02d\n", percent, hours,
216 * Schedule a printout of the estimate in the next call to timeest().
219 infosch(int signal __unused)
225 msg(const char *fmt, ...)
229 (void) fprintf(stderr," DUMP: ");
231 (void) fprintf(stderr, "pid=%d ", getpid());
234 (void) vfprintf(stderr, fmt, ap);
235 (void) fflush(stdout);
236 (void) fflush(stderr);
237 (void) vsnprintf(lastmsg, sizeof(lastmsg), fmt, ap);
242 msgtail(const char *fmt, ...)
246 (void) vfprintf(stderr, fmt, ap);
251 quit(const char *fmt, ...)
255 (void) fprintf(stderr," DUMP: ");
257 (void) fprintf(stderr, "pid=%d ", getpid());
260 (void) vfprintf(stderr, fmt, ap);
262 (void) fflush(stdout);
263 (void) fflush(stderr);
268 * Tell the operator what has to be done;
269 * we don't actually do it
273 allocfsent(const struct fstab *fs)
277 new = (struct fstab *)malloc(sizeof (*fs));
279 (new->fs_file = strdup(fs->fs_file)) == NULL ||
280 (new->fs_type = strdup(fs->fs_type)) == NULL ||
281 (new->fs_spec = strdup(fs->fs_spec)) == NULL)
282 quit("%s\n", strerror(errno));
283 new->fs_passno = fs->fs_passno;
284 new->fs_freq = fs->fs_freq;
289 SLIST_ENTRY(pfstab) pf_list;
290 struct fstab *pf_fstab;
293 static SLIST_HEAD(, pfstab) table;
301 if (setfsent() == 0) {
302 msg("Can't open %s for dump table information: %s\n",
303 _PATH_FSTAB, strerror(errno));
306 while ((fs = getfsent()) != NULL) {
307 if (strcmp(fs->fs_type, FSTAB_RW) &&
308 strcmp(fs->fs_type, FSTAB_RO) &&
309 strcmp(fs->fs_type, FSTAB_RQ))
312 if ((pf = (struct pfstab *)malloc(sizeof (*pf))) == NULL)
313 quit("%s\n", strerror(errno));
315 SLIST_INSERT_HEAD(&table, pf, pf_list);
321 * Search in the fstab for a file name.
322 * This file name can be either the special or the path file name.
324 * The file name can omit the leading '/'.
327 fstabsearch(const char *key)
333 SLIST_FOREACH(pf, &table, pf_list) {
335 if (strcmp(fs->fs_file, key) == 0 ||
336 strcmp(fs->fs_spec, key) == 0)
338 rn = rawname(fs->fs_spec);
339 if (rn != NULL && strcmp(rn, key) == 0)
342 if (*fs->fs_spec == '/' &&
343 strcmp(fs->fs_spec + 1, key) == 0)
345 if (*fs->fs_file == '/' &&
346 strcmp(fs->fs_file + 1, key) == 0)
354 * Tell the operator what to do
357 lastdump(int arg) /* w ==> just what to do; W ==> most recent dumps */
361 struct dumpdates *dtwalk;
362 char *lastname, *date;
368 getfstab(); /* /etc/fstab input */
369 initdumptimes(); /* /etc/dumpdates input */
370 qsort((char *) ddatev, nddates, sizeof(struct dumpdates *), datesort);
373 (void) printf("Dump these file systems:\n");
375 (void) printf("Last dump(s) done (Dump '>' file systems):\n");
377 ITITERATE(i, dtwalk) {
378 if (strncmp(lastname, dtwalk->dd_name,
379 sizeof(dtwalk->dd_name)) == 0)
381 date = (char *)ctime(&dtwalk->dd_ddate);
382 date[16] = '\0'; /* blast away seconds and year */
383 lastname = dtwalk->dd_name;
384 dt = fstabsearch(dtwalk->dd_name);
385 dumpme = (dt != NULL && dt->fs_freq != 0);
387 tlast = localtime(&dtwalk->dd_ddate);
388 dumpme = tnow > (dtwalk->dd_ddate - (tlast->tm_hour * 3600)
389 - (tlast->tm_min * 60) - tlast->tm_sec
390 + (dt->fs_freq * 86400));
392 if (arg != 'w' || dumpme)
394 "%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
395 dumpme && (arg != 'w') ? '>' : ' ',
397 dt ? dt->fs_file : "",
404 datesort(const void *a1, const void *a2)
406 struct dumpdates *d1 = *(struct dumpdates **)a1;
407 struct dumpdates *d2 = *(struct dumpdates **)a2;
410 diff = strncmp(d1->dd_name, d2->dd_name, sizeof(d1->dd_name));
412 return (d2->dd_ddate - d1->dd_ddate);