xref: /csrg-svn/sbin/dump/main.c (revision 65540)
147082Smckusick /*-
261484Sbostic  * Copyright (c) 1980, 1991, 1993
361484Sbostic  *	The Regents of the University of California.  All rights reserved.
447082Smckusick  *
547082Smckusick  * %sccs.include.redist.c%
622037Sdist  */
722037Sdist 
822037Sdist #ifndef lint
961484Sbostic static char copyright[] =
1061484Sbostic "@(#) Copyright (c) 1980, 1991, 1993\n\
1161484Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1246586Storek #endif /* not lint */
1322037Sdist 
1447082Smckusick #ifndef lint
15*65540Smckusick static char sccsid[] = "@(#)main.c	8.2 (Berkeley) 01/06/94";
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 
3259926Storek #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 
4759926Storek #ifndef SBOFF
4859926Storek #define SBOFF (SBLOCK * DEV_BSIZE)
4959926Storek #endif
5059926Storek 
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 
6159926Storek static long numarg __P((int, char *, long, long, int *, char ***));
6259926Storek static __dead void missingarg __P((int, char *));
6359926Storek 
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;
7559926Storek 	int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1;
7646794Smckusick 	ino_t maxino;
771423Sroot 
7850495Smckusick 	spcl.c_date = 0;
7959926Storek 	(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 '-':
9359926Storek 			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)
10559926Storek 				missingarg('f', "output file");
10646794Smckusick 			tape = *argv++;
1071423Sroot 			argc--;
10859926Storek 			break;
1091423Sroot 
11046794Smckusick 		case 'd':		/* density, in bits per inch */
11159926Storek 			density = numarg('d', "density",
11259926Storek 			    10L, 327670L, &argc, &argv) / 10;
11318494Smckusick 			if (density >= 625 && !bflag)
11418494Smckusick 				ntrec = HIGHDENSITYTREC;
11559926Storek 			break;
1161423Sroot 
11746794Smckusick 		case 's':		/* tape size, feet */
11859926Storek 			tsize = numarg('s', "size",
11959926Storek 			    1L, 0L, &argc, &argv) * 12 * 10;
12059926Storek 			break;
1211423Sroot 
12254042Smckusick 		case 'T':		/* time of last dump */
12354042Smckusick 			if (argc < 1)
12459926Storek 				missingarg('T', "time of last dump");
12554042Smckusick 			spcl.c_ddate = unctime(*argv);
12654042Smckusick 			if (spcl.c_ddate < 0) {
12759926Storek 				(void)fprintf(stderr, "bad time \"%s\"\n",
12854042Smckusick 				    *argv);
12959926Storek 				exit(X_ABORT);
13054042Smckusick 			}
13159926Storek 			Tflag = 1;
13254042Smckusick 			lastlevel = '?';
13354042Smckusick 			argc--;
13454042Smckusick 			argv++;
13559926Storek 			break;
13654042Smckusick 
13746794Smckusick 		case 'b':		/* blocks per tape write */
13859926Storek 			ntrec = numarg('b', "number of blocks per write",
13959926Storek 			    1L, 1000L, &argc, &argv);
14059926Storek 			break;
14110910Ssam 
14246794Smckusick 		case 'B':		/* blocks per output file */
14359926Storek 			blocksperfile = numarg('B', "number of blocks per file",
14459926Storek 			    1L, 0L, &argc, &argv);
14559926Storek 			break;
14646614Smckusick 
14746794Smckusick 		case 'c':		/* Tape is cart. not 9-track */
14859926Storek 			cartridge = 1;
14959926Storek 			break;
15010910Ssam 
15159926Storek 		/* dump level */
15259926Storek 		case '0': case '1': case '2': case '3': case '4':
15359926Storek 		case '5': case '6': case '7': case '8': case '9':
15446794Smckusick 			level = *cp;
15559926Storek 			break;
1561423Sroot 
15746794Smckusick 		case 'u':		/* update /etc/dumpdates */
15859926Storek 			uflag = 1;
15959926Storek 			break;
1601423Sroot 
16146794Smckusick 		case 'n':		/* notify operators */
16259926Storek 			notify = 1;
16359926Storek 			break;
1641423Sroot 
16559926Storek 		case 'h':
16659926Storek 			honorlevel = numarg('h', "honor level",
16759926Storek 			    0L, 10L, &argc, &argv);
16859926Storek 			break;
16959926Storek 
17046794Smckusick 		default:
17159926Storek 			(void)fprintf(stderr, "bad key '%c'\n", *cp);
17259926Storek 			exit(X_ABORT);
17346794Smckusick 		}
1741423Sroot 	}
17546794Smckusick 	if (argc < 1) {
17659926Storek 		(void)fprintf(stderr, "Must specify disk or filesystem\n");
17759926Storek 		exit(X_ABORT);
1781423Sroot 	}
17959926Storek 	disk = *argv++;
18059926Storek 	argc--;
18146794Smckusick 	if (argc >= 1) {
18259926Storek 		(void)fprintf(stderr, "Unknown arguments to dump:");
18346794Smckusick 		while (argc--)
18459926Storek 			(void)fprintf(stderr, " %s", *argv++);
18559926Storek 		(void)fprintf(stderr, "\n");
18659926Storek 		exit(X_ABORT);
18746794Smckusick 	}
18854042Smckusick 	if (Tflag && uflag) {
18959926Storek 	        (void)fprintf(stderr,
19054042Smckusick 		    "You cannot use the T and u flags together.\n");
19159926Storek 		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, ':');
21959926Storek 		*tape++ = '\0';
2206886Ssam #ifdef RDUMP
22150495Smckusick 		if (rmthost(host) == 0)
22257725Smckusick 			exit(X_ABORT);
22350495Smckusick #else
22459926Storek 		(void)fprintf(stderr, "remote dump not enabled\n");
22557725Smckusick 		exit(X_ABORT);
22650495Smckusick #endif
2276886Ssam 	}
22859926Storek 	(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);
25459926Storek 	if (dt != NULL) {
2551423Sroot 		disk = rawname(dt->fs_spec);
25659926Storek 		(void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN);
25759926Storek 		(void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN);
25829900Smckusick 	} else {
25959926Storek 		(void)strncpy(spcl.c_dev, disk, NAMELEN);
26059926Storek 		(void)strncpy(spcl.c_filesys, "an unlisted file system",
26154042Smckusick 		    NAMELEN);
26229900Smckusick 	}
26359926Storek 	(void)strcpy(spcl.c_label, "none");
26459926Storek 	(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);
27559926Storek 	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);
28459926Storek 		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
30259926Storek 	maxino = sblock->fs_ipg * sblock->fs_ncg;
30359926Storek 	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 
30959926Storek 	nonodump = spcl.c_level < honorlevel;
31059926Storek 
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 
31959926Storek 	if (pipeout) {
32046794Smckusick 		tapesize += 10;	/* 10 trailer blocks */
32159926Storek 		msg("estimated %ld tape blocks.\n", tapesize);
32259926Storek 	} else {
32359926Storek 		double fetapes;
32459926Storek 
32546614Smckusick 		if (blocksperfile)
32659926Storek 			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);
36359926Storek 	}
3641423Sroot 
36554042Smckusick 	/*
36659926Storek 	 * Allocate tape buffer.
36754042Smckusick 	 */
36854042Smckusick 	if (!alloctape())
36954042Smckusick 		quit("can't allocate tape buffers - try a smaller blocking factor.\n");
37010910Ssam 
37150495Smckusick 	startnewtape(1);
37259926Storek 	(void)time((time_t *)&(tstart_writing));
37359926Storek 	dumpmap(usedinomap, TS_CLRI, maxino - 1);
3741423Sroot 
3751423Sroot 	msg("dumping (Pass III) [directories]\n");
37659926Storek 	dirty = 0;		/* XXX just to get gcc to shut up */
37759926Storek 	for (map = dumpdirmap, ino = 1; ino < maxino; ino++) {
37859926Storek 		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;
39059926Storek 		(void)dumpino(dp, ino);
39146794Smckusick 	}
3921423Sroot 
3931423Sroot 	msg("dumping (Pass IV) [regular files]\n");
39459926Storek 	for (map = dumpinomap, ino = 1; ino < maxino; ino++) {
39557725Smckusick 		int mode;
39657725Smckusick 
39759926Storek 		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;
41059926Storek 		(void)dumpino(dp, ino);
41146794Smckusick 	}
4121423Sroot 
4131423Sroot 	spcl.c_type = TS_END;
41446794Smckusick 	for (i = 0; i < ntrec; i++)
41559926Storek 		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 
42959926Storek /*
43059926Storek  * Pick up a numeric argument.  It must be nonnegative and in the given
43159926Storek  * range (except that a vmax of 0 means unlimited).
43259926Storek  */
43359926Storek static long
43459926Storek numarg(letter, meaning, vmin, vmax, pargc, pargv)
43559926Storek 	int letter;
43659926Storek 	char *meaning;
43759926Storek 	long vmin, vmax;
43859926Storek 	int *pargc;
43959926Storek 	char ***pargv;
44059926Storek {
44159926Storek 	register char *p;
44259926Storek 	long val;
44359926Storek 	char *str;
44459926Storek 
44559926Storek 	if (--*pargc < 0)
44659926Storek 		missingarg(letter, meaning);
44759926Storek 	str = *(*pargv)++;
44859926Storek 	for (p = str; *p; p++)
44959926Storek 		if (!isdigit(*p))
45059926Storek 			goto bad;
45159926Storek 	val = atol(str);
45259926Storek 	if (val < vmin || (vmax && val > vmax))
45359926Storek 		goto bad;
45459926Storek 	return (val);
45559926Storek 
45659926Storek bad:
45759926Storek 	(void)fprintf(stderr, "bad '%c' (%s) value \"%s\"\n",
45859926Storek 	    letter, meaning, str);
45959926Storek 	exit(X_ABORT);
46059926Storek }
46159926Storek 
46259926Storek static __dead void
46359926Storek missingarg(letter, meaning)
46459926Storek 	int letter;
46559926Storek 	char *meaning;
46659926Storek {
46759926Storek 
46859926Storek 	(void)fprintf(stderr, "The '%c' flag (%s) requires an argument\n",
46959926Storek 	    letter, meaning);
47059926Storek 	exit(X_ABORT);
47159926Storek }
47259926Storek 
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");
48759926Storek 		(void)fflush(stderr);
48859926Storek 		(void)fflush(stdout);
48955288Sbostic 		close_rewind();
49057725Smckusick 		exit(X_REWRITE);
49155288Sbostic 		/* NOTREACHED */
49255288Sbostic 	case SIGSEGV:
49355288Sbostic 		msg("SIGSEGV: ABORTING!\n");
49459926Storek 		(void)signal(SIGSEGV, SIG_DFL);
49559926Storek 		(void)kill(0, SIGSEGV);
49655288Sbostic 		/* NOTREACHED */
49755288Sbostic 	}
4981423Sroot }
4991423Sroot 
50046586Storek char *
50146586Storek rawname(cp)
5021423Sroot 	char *cp;
5031423Sroot {
504*65540Smckusick 	static char rawbuf[MAXPATHLEN];
5051423Sroot 	char *dp = rindex(cp, '/');
5061423Sroot 
50759926Storek 	if (dp == NULL)
50859926Storek 		return (NULL);
50959926Storek 	*dp = '\0';
51059926Storek 	(void)strcpy(rawbuf, cp);
5111423Sroot 	*dp = '/';
51259926Storek 	(void)strcat(rawbuf, "/r");
51359926Storek 	(void)strcat(rawbuf, dp + 1);
5141423Sroot 	return (rawbuf);
5151423Sroot }
51650496Smckusick 
51750496Smckusick #ifdef sunos
51859926Storek const char *
51950496Smckusick strerror(errnum)
52050496Smckusick 	int errnum;
52150496Smckusick {
52250496Smckusick 	extern int sys_nerr;
52359926Storek 	extern const char *const sys_errlist[];
52450496Smckusick 
52559926Storek 	if (errnum < sys_nerr)
52659926Storek 		return (sys_errlist[errnum]);
52759926Storek 	else
52859926Storek 		return ("bogus errno in strerror");
52950496Smckusick }
53050496Smckusick #endif
531