* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)dumpoptr.c 5.1 (Berkeley) 6/5/85";
* This is from /usr/include/grp.h
* That defined struct group, which conflicts
* with the struct group defined in param.h
struct Group
{ /* see getgrent(3) */
struct Group
*getgrnam();
* Query the operator; This fascist piece of code requires
* 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("/dev/tty", "r")) == NULL
){
msg("fopen on /dev/tty fails\n");
if ( fgets(replybuffer
, 63, mytty
) == NULL
){
} else if ( (strcmp(replybuffer
, "yes\n") == 0) ||
(strcmp(replybuffer
, "Yes\n") == 0)){
} else if ( (strcmp(replybuffer
, "no\n") == 0) ||
(strcmp(replybuffer
, "No\n") == 0)){
msg("\"Yes\" or \"No\"?\n");
* Turn off the alarm, and reset the signal to trap out..
if (signal(SIGALRM
, sigalrm
) == 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
msg("NEEDS ATTENTION: %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?"))
signal(SIGINT
, interrupt
);
* 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*/
if (gp
== (struct Group
*)0){
msg("No entry in /etc/group for %s.\n",
* We fork a child to do the actual broadcasting, so
* that the process control groups are not messed up
localclock
= localtime(&clock
);
if((f_utmp
= fopen("/etc/utmp", "r")) == NULL
) {
msg("Cannot open /etc/utmp\n");
if (fread(&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",
utmp
.ut_name
, utmp
.ut_line
);
sendmes(utmp
.ut_line
, message
);
Exit(0); /* the wait in this same routine will catch this */
if((f_tty
= fopen(t
, "w")) != NULL
) {
fprintf(f_tty
, "\n\a\a\aMessage from the dump program to all operators at %d:%02d ...\r\n\n"
for (cp
= message
, c
= msize
; c
-- > 0; cp
++) {
* print out an estimate of the amount of time left to do the dump
deltat
= tstart_writing
- tnow
+
(((1.0*(tnow
- tstart_writing
))/blockswritten
) * esize
);
msg("%3.2f%% done, finished in %d:%02d\n",
(blockswritten
*100.0)/esize
,
deltat
/3600, (deltat
%3600)/60);
* esize: total number of blocks estimated over all reels
* blockswritten: blocks actually written, over all reels
* etapes: estimated number of tapes to write
* tsize: blocks can write on this reel
* asize: blocks written on this reel
* tapeno: number of tapes written so far
return(esize
- (etapes
- 1)*tsize
);
msg(fmt
, a1
, a2
, a3
, a4
, a5
)
fprintf(stderr
," DUMP: ");
fprintf(stderr
,"pid=%d ", getpid());
fprintf(stderr
, fmt
, a1
, a2
, a3
, a4
, a5
);
msgtail(fmt
, a1
, a2
, a3
, a4
, a5
)
fprintf(stderr
, fmt
, a1
, a2
, a3
, a4
, a5
);
* 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
));
cp
= malloc(strlen(fs
->fs_file
) + 1);
cp
= malloc(strlen(fs
->fs_type
) + 1);
cp
= malloc(strlen(fs
->fs_spec
) + 1);
new->fs_passno
= fs
->fs_passno
;
new->fs_freq
= fs
->fs_freq
;
static struct pfstab
*table
= NULL
;
register struct fstab
*fs
;
register struct pfstab
*pf
;
msg("Can't open %s for dump table information.\n", FSTAB
);
while (fs
= getfsent()) {
if (strcmp(fs
->fs_type
, FSTAB_RW
) &&
strcmp(fs
->fs_type
, FSTAB_RO
) &&
strcmp(fs
->fs_type
, FSTAB_RQ
))
pf
= (struct pfstab
*)malloc(sizeof (*pf
));
* 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
;
return ((struct fstab
*)0);
for (pf
= table
; pf
; pf
= pf
->pf_next
) {
if (strcmp(fs
->fs_file
, key
) == 0)
if (strcmp(fs
->fs_spec
, key
) == 0)
if (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 idates
*itwalk
;
getfstab(); /* /etc/fstab input */
inititimes(); /* /etc/dumpdates input */
qsort(idatev
, nidates
, sizeof(struct idates
*), idatesort
);
fprintf(stdout
, "Dump these file systems:\n");
fprintf(stdout
, "Last dump(s) done (Dump '>' file systems):\n");
if (strncmp(lastname
, itwalk
->id_name
, sizeof(itwalk
->id_name
)) == 0)
date
= (char *)ctime(&itwalk
->id_ddate
);
date
[16] = '\0'; /* blast away seconds and year */
lastname
= itwalk
->id_name
;
dt
= fstabsearch(itwalk
->id_name
);
&& (itwalk
->id_ddate
< tnow
- (dt
->fs_freq
*DAY
)));
if ( (arg
!= 'w') || dumpme
)
fprintf(stdout
,"%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
dumpme
&& (arg
!= 'w') ? '>' : ' ',
struct idates
**p1
, **p2
;
diff
= strncmp((*p1
)->id_name
, (*p2
)->id_name
, sizeof((*p1
)->id_name
));
return ((*p2
)->id_ddate
- (*p1
)->id_ddate
);