xref: /csrg-svn/sbin/dump/main.c (revision 59926)
147082Smckusick /*-
247082Smckusick  * Copyright (c) 1980, 1991 The Regents of the University of California.
347082Smckusick  * All rights reserved.
447082Smckusick  *
547082Smckusick  * %sccs.include.redist.c%
622037Sdist  */
722037Sdist 
822037Sdist #ifndef lint
947082Smckusick char copyright[] =
1047082Smckusick "@(#) Copyright (c) 1980, 1991 The Regents of the University of California.\n\
1147082Smckusick  All rights reserved.\n";
1246586Storek #endif /* not lint */
1322037Sdist 
1447082Smckusick #ifndef lint
15*59926Storek static char sccsid[] = "@(#)main.c	5.26 (Berkeley) 05/11/93";
1647082Smckusick #endif /* not lint */
1747082Smckusick 
1857725Smckusick #include <sys/param.h>
1957725Smckusick #include <sys/time.h>
2050496Smckusick #ifdef sunos
2157725Smckusick #include <sys/vnode.h>
2257725Smckusick 
2357725Smckusick #include <ufs/inode.h>
2454042Smckusick #include <ufs/fs.h>
2550496Smckusick #else
2654042Smckusick #include <ufs/ffs/fs.h>
2757725Smckusick #include <ufs/ufs/dinode.h>
2854042Smckusick #endif
2957725Smckusick 
3046795Sbostic #include <protocols/dumprestore.h>
3157725Smckusick 
32*59926Storek #include <ctype.h>
3357725Smckusick #include <errno.h>
3446795Sbostic #include <fcntl.h>
3546795Sbostic #include <fstab.h>
3657725Smckusick #include <signal.h>
3746795Sbostic #include <stdio.h>
3846795Sbostic #ifdef __STDC__
3946795Sbostic #include <stdlib.h>
4046795Sbostic #include <string.h>
4157725Smckusick #include <unistd.h>
4246795Sbostic #endif
4357725Smckusick 
441423Sroot #include "dump.h"
4537266Sbostic #include "pathnames.h"
461423Sroot 
47*59926Storek #ifndef SBOFF
48*59926Storek #define SBOFF (SBLOCK * DEV_BSIZE)
49*59926Storek #endif
50*59926Storek 
511423Sroot int	notify = 0;	/* notify operator flag */
521423Sroot int	blockswritten = 0;	/* number of blocks written on current tape */
531423Sroot int	tapeno = 0;	/* current tape number */
5410910Ssam int	density = 0;	/* density in bytes/0.1" */
5510910Ssam int	ntrec = NTREC;	/* # tape blocks in each tape record */
5610910Ssam int	cartridge = 0;	/* Assume non-cartridge tape */
5730560Smckusick long	dev_bsize = 1;	/* recalculated below */
5846614Smckusick long	blocksperfile;	/* output blocks per file */
5950495Smckusick char	*host = NULL;	/* remote host (if any) */
601423Sroot 
61*59926Storek static long numarg __P((int, char *, long, long, int *, char ***));
62*59926Storek static __dead void missingarg __P((int, char *));
63*59926Storek 
6457725Smckusick int
651423Sroot main(argc, argv)
6646794Smckusick 	int argc;
6746795Sbostic 	char **argv;
681423Sroot {
6946794Smckusick 	register ino_t ino;
7047058Smckusick 	register int dirty;
7146794Smckusick 	register struct dinode *dp;
7246794Smckusick 	register struct	fstab *dt;
7346794Smckusick 	register char *map;
7446794Smckusick 	register char *cp;
75*59926Storek 	int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1;
7646794Smckusick 	ino_t maxino;
771423Sroot 
7850495Smckusick 	spcl.c_date = 0;
79*59926Storek 	(void)time((time_t *)&spcl.c_date);
801423Sroot 
8110910Ssam 	tsize = 0;	/* Default later, based on 'c' option for cart tapes */
8237946Sbostic 	tape = _PATH_DEFTAPE;
8346794Smckusick 	dumpdates = _PATH_DUMPDATES;
8437266Sbostic 	temp = _PATH_DTMP;
8546586Storek 	if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0)
8646586Storek 		quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
8746794Smckusick 	level = '0';
8846794Smckusick 	argv++;
8946794Smckusick 	argc -= 2;
9046794Smckusick 	for (cp = *argv++; *cp; cp++) {
9146794Smckusick 		switch (*cp) {
9246794Smckusick 		case '-':
93*59926Storek 			break;
941423Sroot 
9546794Smckusick 		case 'w':
9646794Smckusick 			lastdump('w');	/* tell us only what has to be done */
9757725Smckusick 			exit(0);
9846794Smckusick 
9946794Smckusick 		case 'W':		/* what to do */
10046794Smckusick 			lastdump('W');	/* tell us state of what is done */
10157725Smckusick 			exit(0);	/* do nothing else */
10246794Smckusick 
10346794Smckusick 		case 'f':		/* output file */
10446794Smckusick 			if (argc < 1)
105*59926Storek 				missingarg('f', "output file");
10646794Smckusick 			tape = *argv++;
1071423Sroot 			argc--;
108*59926Storek 			break;
1091423Sroot 
11046794Smckusick 		case 'd':		/* density, in bits per inch */
111*59926Storek 			density = numarg('d', "density",
112*59926Storek 			    10L, 327670L, &argc, &argv) / 10;
11318494Smckusick 			if (density >= 625 && !bflag)
11418494Smckusick 				ntrec = HIGHDENSITYTREC;
115*59926Storek 			break;
1161423Sroot 
11746794Smckusick 		case 's':		/* tape size, feet */
118*59926Storek 			tsize = numarg('s', "size",
119*59926Storek 			    1L, 0L, &argc, &argv) * 12 * 10;
120*59926Storek 			break;
1211423Sroot 
12254042Smckusick 		case 'T':		/* time of last dump */
12354042Smckusick 			if (argc < 1)
124*59926Storek 				missingarg('T', "time of last dump");
12554042Smckusick 			spcl.c_ddate = unctime(*argv);
12654042Smckusick 			if (spcl.c_ddate < 0) {
127*59926Storek 				(void)fprintf(stderr, "bad time \"%s\"\n",
12854042Smckusick 				    *argv);
129*59926Storek 				exit(X_ABORT);
13054042Smckusick 			}
131*59926Storek 			Tflag = 1;
13254042Smckusick 			lastlevel = '?';
13354042Smckusick 			argc--;
13454042Smckusick 			argv++;
135*59926Storek 			break;
13654042Smckusick 
13746794Smckusick 		case 'b':		/* blocks per tape write */
138*59926Storek 			ntrec = numarg('b', "number of blocks per write",
139*59926Storek 			    1L, 1000L, &argc, &argv);
140*59926Storek 			break;
14110910Ssam 
14246794Smckusick 		case 'B':		/* blocks per output file */
143*59926Storek 			blocksperfile = numarg('B', "number of blocks per file",
144*59926Storek 			    1L, 0L, &argc, &argv);
145*59926Storek 			break;
14646614Smckusick 
14746794Smckusick 		case 'c':		/* Tape is cart. not 9-track */
148*59926Storek 			cartridge = 1;
149*59926Storek 			break;
15010910Ssam 
151*59926Storek 		/* dump level */
152*59926Storek 		case '0': case '1': case '2': case '3': case '4':
153*59926Storek 		case '5': case '6': case '7': case '8': case '9':
15446794Smckusick 			level = *cp;
155*59926Storek 			break;
1561423Sroot 
15746794Smckusick 		case 'u':		/* update /etc/dumpdates */
158*59926Storek 			uflag = 1;
159*59926Storek 			break;
1601423Sroot 
16146794Smckusick 		case 'n':		/* notify operators */
162*59926Storek 			notify = 1;
163*59926Storek 			break;
1641423Sroot 
165*59926Storek 		case 'h':
166*59926Storek 			honorlevel = numarg('h', "honor level",
167*59926Storek 			    0L, 10L, &argc, &argv);
168*59926Storek 			break;
169*59926Storek 
17046794Smckusick 		default:
171*59926Storek 			(void)fprintf(stderr, "bad key '%c'\n", *cp);
172*59926Storek 			exit(X_ABORT);
17346794Smckusick 		}
1741423Sroot 	}
17546794Smckusick 	if (argc < 1) {
176*59926Storek 		(void)fprintf(stderr, "Must specify disk or filesystem\n");
177*59926Storek 		exit(X_ABORT);
1781423Sroot 	}
179*59926Storek 	disk = *argv++;
180*59926Storek 	argc--;
18146794Smckusick 	if (argc >= 1) {
182*59926Storek 		(void)fprintf(stderr, "Unknown arguments to dump:");
18346794Smckusick 		while (argc--)
184*59926Storek 			(void)fprintf(stderr, " %s", *argv++);
185*59926Storek 		(void)fprintf(stderr, "\n");
186*59926Storek 		exit(X_ABORT);
18746794Smckusick 	}
18854042Smckusick 	if (Tflag && uflag) {
189*59926Storek 	        (void)fprintf(stderr,
19054042Smckusick 		    "You cannot use the T and u flags together.\n");
191*59926Storek 		exit(X_ABORT);
19254042Smckusick 	}
19312331Smckusick 	if (strcmp(tape, "-") == 0) {
19412331Smckusick 		pipeout++;
19512331Smckusick 		tape = "standard output";
19612331Smckusick 	}
19710910Ssam 
19846614Smckusick 	if (blocksperfile)
19946614Smckusick 		blocksperfile = blocksperfile / ntrec * ntrec; /* round down */
20046614Smckusick 	else {
20146614Smckusick 		/*
20246614Smckusick 		 * Determine how to default tape size and density
20346614Smckusick 		 *
20446614Smckusick 		 *         	density				tape size
20546614Smckusick 		 * 9-track	1600 bpi (160 bytes/.1")	2300 ft.
20646614Smckusick 		 * 9-track	6250 bpi (625 bytes/.1")	2300 ft.
20746614Smckusick 		 * cartridge	8000 bpi (100 bytes/.1")	1700 ft.
20846614Smckusick 		 *						(450*4 - slop)
20946614Smckusick 		 */
21046614Smckusick 		if (density == 0)
21146614Smckusick 			density = cartridge ? 100 : 160;
21246614Smckusick 		if (tsize == 0)
21346614Smckusick 			tsize = cartridge ? 1700L*120L : 2300L*120L;
21446614Smckusick 	}
21510910Ssam 
21650495Smckusick 	if (index(tape, ':')) {
21750495Smckusick 		host = tape;
21850495Smckusick 		tape = index(host, ':');
219*59926Storek 		*tape++ = '\0';
2206886Ssam #ifdef RDUMP
22150495Smckusick 		if (rmthost(host) == 0)
22257725Smckusick 			exit(X_ABORT);
22350495Smckusick #else
224*59926Storek 		(void)fprintf(stderr, "remote dump not enabled\n");
22557725Smckusick 		exit(X_ABORT);
22650495Smckusick #endif
2276886Ssam 	}
228*59926Storek 	(void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
22950495Smckusick 
23046614Smckusick 	if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
23155288Sbostic 		signal(SIGHUP, sig);
23246614Smckusick 	if (signal(SIGTRAP, SIG_IGN) != SIG_IGN)
23355288Sbostic 		signal(SIGTRAP, sig);
23446614Smckusick 	if (signal(SIGFPE, SIG_IGN) != SIG_IGN)
23555288Sbostic 		signal(SIGFPE, sig);
23646614Smckusick 	if (signal(SIGBUS, SIG_IGN) != SIG_IGN)
23755288Sbostic 		signal(SIGBUS, sig);
23846614Smckusick 	if (signal(SIGSEGV, SIG_IGN) != SIG_IGN)
23955288Sbostic 		signal(SIGSEGV, sig);
24046614Smckusick 	if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
24155288Sbostic 		signal(SIGTERM, sig);
2421423Sroot 	if (signal(SIGINT, interrupt) == SIG_IGN)
2431423Sroot 		signal(SIGINT, SIG_IGN);
2441423Sroot 
2451423Sroot 	set_operators();	/* /etc/group snarfed */
2461423Sroot 	getfstab();		/* /etc/fstab snarfed */
2471423Sroot 	/*
2481423Sroot 	 *	disk can be either the full special file name,
2491423Sroot 	 *	the suffix of the special file name,
2501423Sroot 	 *	the special name missing the leading '/',
2511423Sroot 	 *	the file system name with or without the leading '/'.
2521423Sroot 	 */
2531423Sroot 	dt = fstabsearch(disk);
254*59926Storek 	if (dt != NULL) {
2551423Sroot 		disk = rawname(dt->fs_spec);
256*59926Storek 		(void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN);
257*59926Storek 		(void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN);
25829900Smckusick 	} else {
259*59926Storek 		(void)strncpy(spcl.c_dev, disk, NAMELEN);
260*59926Storek 		(void)strncpy(spcl.c_filesys, "an unlisted file system",
26154042Smckusick 		    NAMELEN);
26229900Smckusick 	}
263*59926Storek 	(void)strcpy(spcl.c_label, "none");
264*59926Storek 	(void)gethostname(spcl.c_host, NAMELEN);
26546794Smckusick 	spcl.c_level = level - '0';
26629900Smckusick 	spcl.c_type = TS_TAPE;
26754042Smckusick 	if (!Tflag)
26854042Smckusick 	        getdumptime();		/* /etc/dumpdates snarfed */
2691423Sroot 
27046794Smckusick 	msg("Date of this level %c dump: %s", level,
27146794Smckusick 		spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date));
27246794Smckusick  	msg("Date of last level %c dump: %s", lastlevel,
27346794Smckusick 		spcl.c_ddate == 0 ? "the epoch\n" : ctime(&spcl.c_ddate));
2741423Sroot 	msg("Dumping %s ", disk);
275*59926Storek 	if (dt != NULL)
2761423Sroot 		msgtail("(%s) ", dt->fs_file);
27750495Smckusick 	if (host)
27850495Smckusick 		msgtail("to %s on host %s\n", tape, host);
27950495Smckusick 	else
28050495Smckusick 		msgtail("to %s\n", tape);
2811423Sroot 
28246794Smckusick 	if ((diskfd = open(disk, O_RDONLY)) < 0) {
2831423Sroot 		msg("Cannot open %s\n", disk);
284*59926Storek 		exit(X_ABORT);
2851423Sroot 	}
28646794Smckusick 	sync();
28754042Smckusick 	sblock = (struct fs *)sblock_buf;
28854042Smckusick 	bread(SBOFF, (char *) sblock, SBSIZE);
28946586Storek 	if (sblock->fs_magic != FS_MAGIC)
29046586Storek 		quit("bad sblock magic number\n");
29130560Smckusick 	dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1);
29246586Storek 	dev_bshift = ffs(dev_bsize) - 1;
29346586Storek 	if (dev_bsize != (1 << dev_bshift))
29446586Storek 		quit("dev_bsize (%d) is not a power of 2", dev_bsize);
29546586Storek 	tp_bshift = ffs(TP_BSIZE) - 1;
29646586Storek 	if (TP_BSIZE != (1 << tp_bshift))
29746586Storek 		quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE);
29857725Smckusick #ifdef FS_44INODEFMT
29954165Smckusick 	if (sblock->fs_inodefmt >= FS_44INODEFMT)
30054165Smckusick 		spcl.c_flags |= DR_NEWINODEFMT;
30157725Smckusick #endif
302*59926Storek 	maxino = sblock->fs_ipg * sblock->fs_ncg;
303*59926Storek 	mapsize = roundup(howmany(maxino, NBBY), TP_BSIZE);
30454042Smckusick 	usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
30554042Smckusick 	dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char));
30654042Smckusick 	dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
30746794Smckusick 	tapesize = 3 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
3081423Sroot 
309*59926Storek 	nonodump = spcl.c_level < honorlevel;
310*59926Storek 
3111423Sroot 	msg("mapping (Pass I) [regular files]\n");
31246794Smckusick 	anydirskipped = mapfiles(maxino, &tapesize);
3131423Sroot 
31446794Smckusick 	msg("mapping (Pass II) [directories]\n");
31546794Smckusick 	while (anydirskipped) {
31646794Smckusick 		anydirskipped = mapdirs(maxino, &tapesize);
31746794Smckusick 	}
3181423Sroot 
319*59926Storek 	if (pipeout) {
32046794Smckusick 		tapesize += 10;	/* 10 trailer blocks */
321*59926Storek 		msg("estimated %ld tape blocks.\n", tapesize);
322*59926Storek 	} else {
323*59926Storek 		double fetapes;
324*59926Storek 
32546614Smckusick 		if (blocksperfile)
326*59926Storek 			fetapes = (double) tapesize / blocksperfile;
32746614Smckusick 		else if (cartridge) {
32846614Smckusick 			/* Estimate number of tapes, assuming streaming stops at
32946614Smckusick 			   the end of each block written, and not in mid-block.
33046614Smckusick 			   Assume no erroneous blocks; this can be compensated
33146614Smckusick 			   for with an artificially low tape size. */
33246614Smckusick 			fetapes =
33346794Smckusick 			(	  tapesize	/* blocks */
33446614Smckusick 				* TP_BSIZE	/* bytes/block */
33546614Smckusick 				* (1.0/density)	/* 0.1" / byte */
33646614Smckusick 			  +
33746794Smckusick 				  tapesize	/* blocks */
33846614Smckusick 				* (1.0/ntrec)	/* streaming-stops per block */
33946614Smckusick 				* 15.48		/* 0.1" / streaming-stop */
34046614Smckusick 			) * (1.0 / tsize );	/* tape / 0.1" */
34146614Smckusick 		} else {
34246614Smckusick 			/* Estimate number of tapes, for old fashioned 9-track
34346614Smckusick 			   tape */
34446614Smckusick 			int tenthsperirg = (density == 625) ? 3 : 7;
34546614Smckusick 			fetapes =
34646794Smckusick 			(	  tapesize	/* blocks */
34746614Smckusick 				* TP_BSIZE	/* bytes / block */
34846614Smckusick 				* (1.0/density)	/* 0.1" / byte */
34946614Smckusick 			  +
35046794Smckusick 				  tapesize	/* blocks */
35146614Smckusick 				* (1.0/ntrec)	/* IRG's / block */
35246614Smckusick 				* tenthsperirg	/* 0.1" / IRG */
35346614Smckusick 			) * (1.0 / tsize );	/* tape / 0.1" */
35446614Smckusick 		}
35546614Smckusick 		etapes = fetapes;		/* truncating assignment */
35646614Smckusick 		etapes++;
35746794Smckusick 		/* count the dumped inodes map on each additional tape */
35846794Smckusick 		tapesize += (etapes - 1) *
35946794Smckusick 			(howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
36046794Smckusick 		tapesize += etapes + 10;	/* headers + 10 trailer blks */
36146614Smckusick 		msg("estimated %ld tape blocks on %3.2f tape(s).\n",
36246794Smckusick 		    tapesize, fetapes);
363*59926Storek 	}
3641423Sroot 
36554042Smckusick 	/*
366*59926Storek 	 * Allocate tape buffer.
36754042Smckusick 	 */
36854042Smckusick 	if (!alloctape())
36954042Smckusick 		quit("can't allocate tape buffers - try a smaller blocking factor.\n");
37010910Ssam 
37150495Smckusick 	startnewtape(1);
372*59926Storek 	(void)time((time_t *)&(tstart_writing));
373*59926Storek 	dumpmap(usedinomap, TS_CLRI, maxino - 1);
3741423Sroot 
3751423Sroot 	msg("dumping (Pass III) [directories]\n");
376*59926Storek 	dirty = 0;		/* XXX just to get gcc to shut up */
377*59926Storek 	for (map = dumpdirmap, ino = 1; ino < maxino; ino++) {
378*59926Storek 		if (((ino - 1) % NBBY) == 0)	/* map is offset by 1 */
37947058Smckusick 			dirty = *map++;
38046794Smckusick 		else
38147058Smckusick 			dirty >>= 1;
38247058Smckusick 		if ((dirty & 1) == 0)
38346794Smckusick 			continue;
38446794Smckusick 		/*
38546794Smckusick 		 * Skip directory inodes deleted and maybe reallocated
38646794Smckusick 		 */
38746794Smckusick 		dp = getino(ino);
38846794Smckusick 		if ((dp->di_mode & IFMT) != IFDIR)
38946794Smckusick 			continue;
390*59926Storek 		(void)dumpino(dp, ino);
39146794Smckusick 	}
3921423Sroot 
3931423Sroot 	msg("dumping (Pass IV) [regular files]\n");
394*59926Storek 	for (map = dumpinomap, ino = 1; ino < maxino; ino++) {
39557725Smckusick 		int mode;
39657725Smckusick 
397*59926Storek 		if (((ino - 1) % NBBY) == 0)	/* map is offset by 1 */
39847058Smckusick 			dirty = *map++;
39946794Smckusick 		else
40047058Smckusick 			dirty >>= 1;
40147058Smckusick 		if ((dirty & 1) == 0)
40246794Smckusick 			continue;
40346794Smckusick 		/*
40446794Smckusick 		 * Skip inodes deleted and reallocated as directories.
40546794Smckusick 		 */
40646794Smckusick 		dp = getino(ino);
40757725Smckusick 		mode = dp->di_mode & IFMT;
40857725Smckusick 		if (mode == IFDIR)
40946794Smckusick 			continue;
410*59926Storek 		(void)dumpino(dp, ino);
41146794Smckusick 	}
4121423Sroot 
4131423Sroot 	spcl.c_type = TS_END;
41446794Smckusick 	for (i = 0; i < ntrec; i++)
415*59926Storek 		writeheader(maxino - 1);
41646614Smckusick 	if (pipeout)
41746614Smckusick 		msg("DUMP: %ld tape blocks\n",spcl.c_tapea);
41846614Smckusick 	else
41946614Smckusick 		msg("DUMP: %ld tape blocks on %d volumes(s)\n",
42046614Smckusick 		    spcl.c_tapea, spcl.c_volume);
42146794Smckusick 	putdumptime();
42246239Storek 	trewind();
4231423Sroot 	broadcast("DUMP IS DONE!\7\7\n");
42450495Smckusick 	msg("DUMP IS DONE\n");
4251423Sroot 	Exit(X_FINOK);
42646586Storek 	/* NOTREACHED */
4271423Sroot }
4281423Sroot 
429*59926Storek /*
430*59926Storek  * Pick up a numeric argument.  It must be nonnegative and in the given
431*59926Storek  * range (except that a vmax of 0 means unlimited).
432*59926Storek  */
433*59926Storek static long
434*59926Storek numarg(letter, meaning, vmin, vmax, pargc, pargv)
435*59926Storek 	int letter;
436*59926Storek 	char *meaning;
437*59926Storek 	long vmin, vmax;
438*59926Storek 	int *pargc;
439*59926Storek 	char ***pargv;
440*59926Storek {
441*59926Storek 	register char *p;
442*59926Storek 	long val;
443*59926Storek 	char *str;
444*59926Storek 
445*59926Storek 	if (--*pargc < 0)
446*59926Storek 		missingarg(letter, meaning);
447*59926Storek 	str = *(*pargv)++;
448*59926Storek 	for (p = str; *p; p++)
449*59926Storek 		if (!isdigit(*p))
450*59926Storek 			goto bad;
451*59926Storek 	val = atol(str);
452*59926Storek 	if (val < vmin || (vmax && val > vmax))
453*59926Storek 		goto bad;
454*59926Storek 	return (val);
455*59926Storek 
456*59926Storek bad:
457*59926Storek 	(void)fprintf(stderr, "bad '%c' (%s) value \"%s\"\n",
458*59926Storek 	    letter, meaning, str);
459*59926Storek 	exit(X_ABORT);
460*59926Storek }
461*59926Storek 
462*59926Storek static __dead void
463*59926Storek missingarg(letter, meaning)
464*59926Storek 	int letter;
465*59926Storek 	char *meaning;
466*59926Storek {
467*59926Storek 
468*59926Storek 	(void)fprintf(stderr, "The '%c' flag (%s) requires an argument\n",
469*59926Storek 	    letter, meaning);
470*59926Storek 	exit(X_ABORT);
471*59926Storek }
472*59926Storek 
47346586Storek void
47455288Sbostic sig(signo)
47555288Sbostic 	int signo;
4761423Sroot {
47755288Sbostic 	switch(signo) {
47855288Sbostic 	case SIGALRM:
47955288Sbostic 	case SIGBUS:
48055288Sbostic 	case SIGFPE:
48155288Sbostic 	case SIGHUP:
48255288Sbostic 	case SIGTERM:
48355288Sbostic 	case SIGTRAP:
48455288Sbostic 		if (pipeout)
48555288Sbostic 			quit("Signal on pipe: cannot recover\n");
48655288Sbostic 		msg("Rewriting attempted as response to unknown signal.\n");
487*59926Storek 		(void)fflush(stderr);
488*59926Storek 		(void)fflush(stdout);
48955288Sbostic 		close_rewind();
49057725Smckusick 		exit(X_REWRITE);
49155288Sbostic 		/* NOTREACHED */
49255288Sbostic 	case SIGSEGV:
49355288Sbostic 		msg("SIGSEGV: ABORTING!\n");
494*59926Storek 		(void)signal(SIGSEGV, SIG_DFL);
495*59926Storek 		(void)kill(0, SIGSEGV);
49655288Sbostic 		/* NOTREACHED */
49755288Sbostic 	}
4981423Sroot }
4991423Sroot 
50046586Storek char *
50146586Storek rawname(cp)
5021423Sroot 	char *cp;
5031423Sroot {
5041423Sroot 	static char rawbuf[32];
5051423Sroot 	char *dp = rindex(cp, '/');
5061423Sroot 
507*59926Storek 	if (dp == NULL)
508*59926Storek 		return (NULL);
509*59926Storek 	*dp = '\0';
510*59926Storek 	(void)strcpy(rawbuf, cp);
5111423Sroot 	*dp = '/';
512*59926Storek 	(void)strcat(rawbuf, "/r");
513*59926Storek 	(void)strcat(rawbuf, dp + 1);
5141423Sroot 	return (rawbuf);
5151423Sroot }
51650496Smckusick 
51750496Smckusick #ifdef sunos
518*59926Storek const char *
51950496Smckusick strerror(errnum)
52050496Smckusick 	int errnum;
52150496Smckusick {
52250496Smckusick 	extern int sys_nerr;
523*59926Storek 	extern const char *const sys_errlist[];
52450496Smckusick 
525*59926Storek 	if (errnum < sys_nerr)
526*59926Storek 		return (sys_errlist[errnum]);
527*59926Storek 	else
528*59926Storek 		return ("bogus errno in strerror");
52950496Smckusick }
53050496Smckusick #endif
531