* Copyright (c) 1980, 1988 The Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)optr.c 5.14 (Berkeley) %G%";
static void alarmcatch();
* Query the operator; This previously-fascist piece of code
* no longer requires an exact response.
* It is intended to protect dump aborting by inquisitive
* people banging on the console terminal to see what is
* happening which might cause dump to croak, destroying
* a large number of hours of work.
* Every 2 minutes we reprint the message, alerting others
* that dump needs attention.
char *attnmessage
; /* attention message */
if ((mytty
= fopen(_PATH_TTY
, "r")) == NULL
)
quit("fopen on %s fails: %s\n", _PATH_TTY
, strerror(errno
));
if (fgets(replybuffer
, 63, mytty
) == NULL
) {
if (++errcount
> 30) /* XXX ugly */
quit("excessive operator query failures\n");
} else if (replybuffer
[0] == 'y' || replybuffer
[0] == 'Y') {
} else if (replybuffer
[0] == 'n' || replybuffer
[0] == 'N') {
" DUMP: \"Yes\" or \"No\"?\n");
" DUMP: %s: (\"yes\" or \"no\") ", question
);
* Turn off the alarm, and reset the signal to trap out..
if (signal(SIGALRM
, sig
) == SIG_IGN
)
signal(SIGALRM
, SIG_IGN
);
* Alert the console operator, and enable the alarm clock to
* sleep for 2 minutes in case nobody comes to satisfy dump
" DUMP: %s: (\"yes\" or \"no\") ",
broadcast(""); /* just print last msg */
(void) fprintf(stderr
," DUMP: %s: (\"yes\" or \"no\") ",
signal(SIGALRM
, alarmcatch
);
* Here if an inquisitive operator interrupts the dump program
msg("Interrupt received.\n");
if (query("Do you want to abort dump?"))
* The following variables and routines manage alerting
* operators to the status of dump.
* This works much like wall(1) does.
* Get the names from the group entry "operator" to notify.
if (!notify
) /*not going to notify*/
msg("No group entry for %s.\n", OPGRENT
);
* We fork a child to do the actual broadcasting, so
* that the process control groups are not messed up
if (!notify
|| gp
== NULL
)
clock
= time((time_t *)0);
localclock
= localtime(&clock
);
if ((f_utmp
= fopen(_PATH_UTMP
, "r")) == NULL
) {
msg("Cannot open %s: %s\n", _PATH_UTMP
, strerror(errno
));
if (fread((char *) &utmp
, sizeof (struct utmp
), 1, f_utmp
) != 1)
if (utmp
.ut_name
[0] == 0)
for (np
= gp
->gr_mem
; *np
; np
++) {
if (strncmp(*np
, utmp
.ut_name
, sizeof(utmp
.ut_name
)) != 0)
* Do not send messages to operators on dialups
if (strncmp(utmp
.ut_line
, DIALUP
, strlen(DIALUP
)) == 0)
msg("Message to %s at %s\n", *np
, utmp
.ut_line
);
sendmes(utmp
.ut_line
, message
);
Exit(0); /* the wait in this same routine will catch this */
(void) strcpy(t
, _PATH_DEV
);
if ((f_tty
= fopen(t
, "w")) != NULL
) {
\7\7\7Message from the dump program to all operators at %d:%02d ...\r\n\n\
DUMP: NEEDS ATTENTION: ",
localclock
->tm_hour
, localclock
->tm_min
);
for (cp
= lastmsg
; ; cp
++) {
(void) putc('\r', f_tty
);
* print out an estimate of the amount of time left to do the dump
(void) time((time_t *) &tnow
);
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);
msg(const char *fmt
, ...)
(void) fprintf(stderr
," DUMP: ");
(void) fprintf(stderr
, "pid=%d ", getpid());
(void) vfprintf(stderr
, fmt
, ap
);
(void) vsprintf(lastmsg
, fmt
, ap
);
msgtail(const char *fmt
, ...)
(void) vfprintf(stderr
, fmt
, ap
);
quit(const char *fmt
, ...)
(void) fprintf(stderr
," DUMP: ");
(void) fprintf(stderr
, "pid=%d ", getpid());
(void) vfprintf(stderr
, fmt
, ap
);
* Tell the operator what has to be done;
* we don't actually do it
register struct fstab
*fs
;
register struct fstab
*new;
new = (struct fstab
*)malloc(sizeof (*fs
));
(new->fs_file
= strdup(fs
->fs_file
)) == NULL
||
(new->fs_type
= strdup(fs
->fs_type
)) == NULL
||
(new->fs_spec
= strdup(fs
->fs_spec
)) == NULL
)
quit("%s\n", strerror(errno
));
new->fs_passno
= fs
->fs_passno
;
new->fs_freq
= fs
->fs_freq
;
static struct pfstab
*table
;
register struct fstab
*fs
;
register struct pfstab
*pf
;
msg("Can't open %s for dump table information: %s\n",
_PATH_FSTAB
, strerror(errno
));
while (fs
= getfsent()) {
if (strcmp(fs
->fs_type
, FSTAB_RW
) &&
strcmp(fs
->fs_type
, FSTAB_RO
) &&
strcmp(fs
->fs_type
, FSTAB_RQ
))
if ((pf
= (struct pfstab
*)malloc(sizeof (*pf
))) == NULL
)
quit("%s\n", strerror(errno
));
* Search in the fstab for a file name.
* This file name can be either the special or the path file name.
* The entries in the fstab are the BLOCK special names, not the
* character special names.
* The caller of fstabsearch assures that the character device
* is dumped (that is much faster)
* The file name can omit the leading '/'.
register struct pfstab
*pf
;
register struct fstab
*fs
;
for (pf
= table
; pf
!= NULL
; pf
= pf
->pf_next
) {
if (strcmp(fs
->fs_file
, key
) == 0 ||
strcmp(fs
->fs_spec
, key
) == 0 ||
strcmp(rawname(fs
->fs_spec
), key
) == 0)
if (*fs
->fs_spec
== '/' &&
strcmp(fs
->fs_spec
+ 1, key
) == 0)
if (*fs
->fs_file
== '/' &&
strcmp(fs
->fs_file
+ 1, key
) == 0)
* Tell the operator what to do
char arg
; /* w ==> just what to do; W ==> most recent dumps */
register struct fstab
*dt
;
register struct dumpdates
*dtwalk
;
getfstab(); /* /etc/fstab input */
initdumptimes(); /* /etc/dumpdates input */
qsort((char *) ddatev
, nddates
, sizeof(struct dumpdates
*), datesort
);
(void) printf("Dump these file systems:\n");
(void) printf("Last dump(s) done (Dump '>' file systems):\n");
if (strncmp(lastname
, dtwalk
->dd_name
,
sizeof(dtwalk
->dd_name
)) == 0)
date
= (char *)ctime(&dtwalk
->dd_ddate
);
date
[16] = '\0'; /* blast away seconds and year */
lastname
= dtwalk
->dd_name
;
dt
= fstabsearch(dtwalk
->dd_name
);
dtwalk
->dd_ddate
< tnow
- (dt
->fs_freq
* SECSPERDAY
));
if (arg
!= 'w' || dumpme
)
"%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
dumpme
&& (arg
!= 'w') ? '>' : ' ',
struct dumpdates
*d1
= *(struct dumpdates
**)a1
;
struct dumpdates
*d2
= *(struct dumpdates
**)a2
;
diff
= strncmp(d1
->dd_name
, d2
->dd_name
, sizeof(d1
->dd_name
));
return (d2
->dd_ddate
- d1
->dd_ddate
);