savecore.c revision 244319
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
9 * DARPA CHATS research program.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. The names of the authors may not be used to endorse or promote
20 *    products derived from this software without specific prior written
21 *    permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * Copyright (c) 1986, 1992, 1993
36 *	The Regents of the University of California.  All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 *    notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 *    notice, this list of conditions and the following disclaimer in the
45 *    documentation and/or other materials provided with the distribution.
46 * 4. Neither the name of the University nor the names of its contributors
47 *    may be used to endorse or promote products derived from this software
48 *    without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 */
62
63#include <sys/cdefs.h>
64__FBSDID("$FreeBSD: head/sbin/savecore/savecore.c 244319 2012-12-16 23:04:31Z pjd $");
65
66#include <sys/param.h>
67#include <sys/disk.h>
68#include <sys/kerneldump.h>
69#include <sys/mount.h>
70#include <sys/stat.h>
71#include <errno.h>
72#include <fcntl.h>
73#include <fstab.h>
74#include <paths.h>
75#include <signal.h>
76#include <stdarg.h>
77#include <stdio.h>
78#include <stdlib.h>
79#include <string.h>
80#include <syslog.h>
81#include <time.h>
82#include <unistd.h>
83
84/* The size of the buffer used for I/O. */
85#define	BUFFERSIZE	(1024*1024)
86
87#define	STATUS_BAD	0
88#define	STATUS_GOOD	1
89#define	STATUS_UNKNOWN	2
90
91static int checkfor, compress, clear, force, keep, verbose;	/* flags */
92static int nfound, nsaved, nerr;			/* statistics */
93
94extern FILE *zopen(const char *, const char *);
95
96static sig_atomic_t got_siginfo;
97static void infohandler(int);
98
99static void
100printheader(FILE *f, const struct kerneldumpheader *h, const char *device,
101    int bounds, const int status)
102{
103	uint64_t dumplen;
104	time_t t;
105	const char *stat_str;
106
107	fprintf(f, "Dump header from device %s\n", device);
108	fprintf(f, "  Architecture: %s\n", h->architecture);
109	fprintf(f, "  Architecture Version: %u\n",
110	    dtoh32(h->architectureversion));
111	dumplen = dtoh64(h->dumplength);
112	fprintf(f, "  Dump Length: %lldB (%lld MB)\n", (long long)dumplen,
113	    (long long)(dumplen >> 20));
114	fprintf(f, "  Blocksize: %d\n", dtoh32(h->blocksize));
115	t = dtoh64(h->dumptime);
116	fprintf(f, "  Dumptime: %s", ctime(&t));
117	fprintf(f, "  Hostname: %s\n", h->hostname);
118	fprintf(f, "  Magic: %s\n", h->magic);
119	fprintf(f, "  Version String: %s", h->versionstring);
120	fprintf(f, "  Panic String: %s\n", h->panicstring);
121	fprintf(f, "  Dump Parity: %u\n", h->parity);
122	fprintf(f, "  Bounds: %d\n", bounds);
123
124	switch(status) {
125	case STATUS_BAD:
126		stat_str = "bad";
127		break;
128	case STATUS_GOOD:
129		stat_str = "good";
130		break;
131	default:
132		stat_str = "unknown";
133	}
134	fprintf(f, "  Dump Status: %s\n", stat_str);
135	fflush(f);
136}
137
138static int
139getbounds(void) {
140	FILE *fp;
141	char buf[6];
142	int ret;
143
144	ret = 0;
145
146	if ((fp = fopen("bounds", "r")) == NULL) {
147		if (verbose)
148			printf("unable to open bounds file, using 0\n");
149		return (ret);
150	}
151
152	if (fgets(buf, sizeof buf, fp) == NULL) {
153		syslog(LOG_WARNING, "unable to read from bounds, using 0");
154		fclose(fp);
155		return (ret);
156	}
157
158	errno = 0;
159	ret = (int)strtol(buf, NULL, 10);
160	if (ret == 0 && (errno == EINVAL || errno == ERANGE))
161		syslog(LOG_WARNING, "invalid value found in bounds, using 0");
162	return (ret);
163}
164
165static void
166writebounds(int bounds) {
167	FILE *fp;
168
169	if ((fp = fopen("bounds", "w")) == NULL) {
170		syslog(LOG_WARNING, "unable to write to bounds file: %m");
171		return;
172	}
173
174	if (verbose)
175		printf("bounds number: %d\n", bounds);
176
177	fprintf(fp, "%d\n", bounds);
178	fclose(fp);
179}
180
181/*
182 * Check that sufficient space is available on the disk that holds the
183 * save directory.
184 */
185static int
186check_space(const char *savedir, off_t dumpsize)
187{
188	FILE *fp;
189	off_t minfree, spacefree, totfree, needed;
190	struct statfs fsbuf;
191	char buf[100];
192
193	if (statfs(".", &fsbuf) < 0) {
194		syslog(LOG_ERR, "%s: %m", savedir);
195		exit(1);
196	}
197	spacefree = ((off_t) fsbuf.f_bavail * fsbuf.f_bsize) / 1024;
198	totfree = ((off_t) fsbuf.f_bfree * fsbuf.f_bsize) / 1024;
199
200	if ((fp = fopen("minfree", "r")) == NULL)
201		minfree = 0;
202	else {
203		if (fgets(buf, sizeof(buf), fp) == NULL)
204			minfree = 0;
205		else
206			minfree = atoi(buf);
207		(void)fclose(fp);
208	}
209
210	needed = dumpsize / 1024 + 2;	/* 2 for info file */
211	if (((minfree > 0) ? spacefree : totfree) - needed < minfree) {
212		syslog(LOG_WARNING,
213	"no dump, not enough free space on device (%lld available, need %lld)",
214		    (long long)(minfree > 0 ? spacefree : totfree),
215		    (long long)needed);
216		return (0);
217	}
218	if (spacefree - needed < 0)
219		syslog(LOG_WARNING,
220		    "dump performed, but free space threshold crossed");
221	return (1);
222}
223
224#define BLOCKSIZE (1<<12)
225#define BLOCKMASK (~(BLOCKSIZE-1))
226
227static int
228DoRegularFile(int fd, off_t dumpsize, char *buf, const char *device,
229    const char *filename, FILE *fp)
230{
231	int he, hs, nr, nw, wl;
232	off_t dmpcnt, origsize;
233
234	dmpcnt = 0;
235	origsize = dumpsize;
236	he = 0;
237	while (dumpsize > 0) {
238		wl = BUFFERSIZE;
239		if (wl > dumpsize)
240			wl = dumpsize;
241		nr = read(fd, buf, wl);
242		if (nr != wl) {
243			if (nr == 0)
244				syslog(LOG_WARNING,
245				    "WARNING: EOF on dump device");
246			else
247				syslog(LOG_ERR, "read error on %s: %m", device);
248			nerr++;
249			return (-1);
250		}
251		if (compress) {
252			nw = fwrite(buf, 1, wl, fp);
253		} else {
254			for (nw = 0; nw < nr; nw = he) {
255				/* find a contiguous block of zeroes */
256				for (hs = nw; hs < nr; hs += BLOCKSIZE) {
257					for (he = hs; he < nr && buf[he] == 0;
258					    ++he)
259						/* nothing */ ;
260					/* is the hole long enough to matter? */
261					if (he >= hs + BLOCKSIZE)
262						break;
263				}
264
265				/* back down to a block boundary */
266				he &= BLOCKMASK;
267
268				/*
269				 * 1) Don't go beyond the end of the buffer.
270				 * 2) If the end of the buffer is less than
271				 *    BLOCKSIZE bytes away, we're at the end
272				 *    of the file, so just grab what's left.
273				 */
274				if (hs + BLOCKSIZE > nr)
275					hs = he = nr;
276
277				/*
278				 * At this point, we have a partial ordering:
279				 *     nw <= hs <= he <= nr
280				 * If hs > nw, buf[nw..hs] contains non-zero data.
281				 * If he > hs, buf[hs..he] is all zeroes.
282				 */
283				if (hs > nw)
284					if (fwrite(buf + nw, hs - nw, 1, fp)
285					    != 1)
286					break;
287				if (he > hs)
288					if (fseeko(fp, he - hs, SEEK_CUR) == -1)
289						break;
290			}
291		}
292		if (nw != wl) {
293			syslog(LOG_ERR,
294			    "write error on %s file: %m", filename);
295			syslog(LOG_WARNING,
296			    "WARNING: vmcore may be incomplete");
297			nerr++;
298			return (-1);
299		}
300		if (verbose) {
301			dmpcnt += wl;
302			printf("%llu\r", (unsigned long long)dmpcnt);
303			fflush(stdout);
304		}
305		dumpsize -= wl;
306		if (got_siginfo) {
307			printf("%s %.1lf%%\n", filename, (100.0 - (100.0 *
308			    (double)dumpsize / (double)origsize)));
309			got_siginfo = 0;
310		}
311	}
312	return (0);
313}
314
315/*
316 * Specialized version of dump-reading logic for use with textdumps, which
317 * are written backwards from the end of the partition, and must be reversed
318 * before being written to the file.  Textdumps are small, so do a bit less
319 * work to optimize/sparsify.
320 */
321static int
322DoTextdumpFile(int fd, off_t dumpsize, off_t lasthd, char *buf,
323    const char *device, const char *filename, FILE *fp)
324{
325	int nr, nw, wl;
326	off_t dmpcnt, totsize;
327
328	totsize = dumpsize;
329	dmpcnt = 0;
330	wl = 512;
331	if ((dumpsize % wl) != 0) {
332		syslog(LOG_ERR, "textdump uneven multiple of 512 on %s",
333		    device);
334		nerr++;
335		return (-1);
336	}
337	while (dumpsize > 0) {
338		nr = pread(fd, buf, wl, lasthd - (totsize - dumpsize) - wl);
339		if (nr != wl) {
340			if (nr == 0)
341				syslog(LOG_WARNING,
342				    "WARNING: EOF on dump device");
343			else
344				syslog(LOG_ERR, "read error on %s: %m", device);
345			nerr++;
346			return (-1);
347		}
348		nw = fwrite(buf, 1, wl, fp);
349		if (nw != wl) {
350			syslog(LOG_ERR,
351			    "write error on %s file: %m", filename);
352			syslog(LOG_WARNING,
353			    "WARNING: textdump may be incomplete");
354			nerr++;
355			return (-1);
356		}
357		if (verbose) {
358			dmpcnt += wl;
359			printf("%llu\r", (unsigned long long)dmpcnt);
360			fflush(stdout);
361		}
362		dumpsize -= wl;
363	}
364	return (0);
365}
366
367static void
368DoFile(const char *savedir, const char *device)
369{
370	static char filename[PATH_MAX];
371	static char *buf = NULL;
372	struct kerneldumpheader kdhf, kdhl;
373	off_t mediasize, dumpsize, firsthd, lasthd;
374	FILE *info, *fp;
375	mode_t oumask;
376	int fd, fdinfo, error;
377	int bounds, status;
378	u_int sectorsize;
379	int istextdump;
380
381	bounds = getbounds();
382	mediasize = 0;
383	status = STATUS_UNKNOWN;
384
385	if (buf == NULL) {
386		buf = malloc(BUFFERSIZE);
387		if (buf == NULL) {
388			syslog(LOG_ERR, "%m");
389			return;
390		}
391	}
392
393	if (verbose)
394		printf("checking for kernel dump on device %s\n", device);
395
396	fd = open(device, (checkfor || keep) ? O_RDONLY : O_RDWR);
397	if (fd < 0) {
398		syslog(LOG_ERR, "%s: %m", device);
399		return;
400	}
401
402	error = ioctl(fd, DIOCGMEDIASIZE, &mediasize);
403	if (!error)
404		error = ioctl(fd, DIOCGSECTORSIZE, &sectorsize);
405	if (error) {
406		syslog(LOG_ERR,
407		    "couldn't find media and/or sector size of %s: %m", device);
408		goto closefd;
409	}
410
411	if (verbose) {
412		printf("mediasize = %lld\n", (long long)mediasize);
413		printf("sectorsize = %u\n", sectorsize);
414	}
415
416	lasthd = mediasize - sectorsize;
417	lseek(fd, lasthd, SEEK_SET);
418	error = read(fd, &kdhl, sizeof kdhl);
419	if (error != sizeof kdhl) {
420		syslog(LOG_ERR,
421		    "error reading last dump header at offset %lld in %s: %m",
422		    (long long)lasthd, device);
423		goto closefd;
424	}
425	istextdump = 0;
426	if (strncmp(kdhl.magic, TEXTDUMPMAGIC, sizeof kdhl) == 0) {
427		if (verbose)
428			printf("textdump magic on last dump header on %s\n",
429			    device);
430		istextdump = 1;
431		if (dtoh32(kdhl.version) != KERNELDUMP_TEXT_VERSION) {
432			syslog(LOG_ERR,
433			    "unknown version (%d) in last dump header on %s",
434			    dtoh32(kdhl.version), device);
435
436			status = STATUS_BAD;
437			if (force == 0)
438				goto closefd;
439		}
440	} else if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic) ==
441	    0) {
442		if (dtoh32(kdhl.version) != KERNELDUMPVERSION) {
443			syslog(LOG_ERR,
444			    "unknown version (%d) in last dump header on %s",
445			    dtoh32(kdhl.version), device);
446
447			status = STATUS_BAD;
448			if (force == 0)
449				goto closefd;
450		}
451	} else {
452		if (verbose)
453			printf("magic mismatch on last dump header on %s\n",
454			    device);
455
456		status = STATUS_BAD;
457		if (force == 0)
458			goto closefd;
459
460		if (memcmp(kdhl.magic, KERNELDUMPMAGIC_CLEARED,
461			    sizeof kdhl.magic) == 0) {
462			if (verbose)
463				printf("forcing magic on %s\n", device);
464			memcpy(kdhl.magic, KERNELDUMPMAGIC,
465			    sizeof kdhl.magic);
466		} else {
467			syslog(LOG_ERR, "unable to force dump - bad magic");
468			goto closefd;
469		}
470		if (dtoh32(kdhl.version) != KERNELDUMPVERSION) {
471			syslog(LOG_ERR,
472			    "unknown version (%d) in last dump header on %s",
473			    dtoh32(kdhl.version), device);
474
475			status = STATUS_BAD;
476			if (force == 0)
477				goto closefd;
478		}
479	}
480
481	nfound++;
482	if (clear)
483		goto nuke;
484
485	if (kerneldump_parity(&kdhl)) {
486		syslog(LOG_ERR,
487		    "parity error on last dump header on %s", device);
488		nerr++;
489		status = STATUS_BAD;
490		if (force == 0)
491			goto closefd;
492	}
493	dumpsize = dtoh64(kdhl.dumplength);
494	firsthd = lasthd - dumpsize - sizeof kdhf;
495	lseek(fd, firsthd, SEEK_SET);
496	error = read(fd, &kdhf, sizeof kdhf);
497	if (error != sizeof kdhf) {
498		syslog(LOG_ERR,
499		    "error reading first dump header at offset %lld in %s: %m",
500		    (long long)firsthd, device);
501		nerr++;
502		goto closefd;
503	}
504
505	if (verbose >= 2) {
506		printf("First dump headers:\n");
507		printheader(stdout, &kdhf, device, bounds, -1);
508
509		printf("\nLast dump headers:\n");
510		printheader(stdout, &kdhl, device, bounds, -1);
511		printf("\n");
512	}
513
514	if (memcmp(&kdhl, &kdhf, sizeof kdhl)) {
515		syslog(LOG_ERR,
516		    "first and last dump headers disagree on %s", device);
517		nerr++;
518		status = STATUS_BAD;
519		if (force == 0)
520			goto closefd;
521	} else {
522		status = STATUS_GOOD;
523	}
524
525	if (checkfor) {
526		printf("A dump exists on %s\n", device);
527		close(fd);
528		exit(0);
529	}
530
531	if (kdhl.panicstring[0])
532		syslog(LOG_ALERT, "reboot after panic: %s", kdhl.panicstring);
533	else
534		syslog(LOG_ALERT, "reboot");
535
536	if (verbose)
537		printf("Checking for available free space\n");
538	if (!check_space(savedir, dumpsize)) {
539		nerr++;
540		goto closefd;
541	}
542
543	writebounds(bounds + 1);
544
545	snprintf(buf, sizeof(buf), "info.%d", bounds);
546
547	/*
548	 * Create or overwrite any existing dump header files.
549	 */
550	fdinfo = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600);
551	if (fdinfo < 0) {
552		syslog(LOG_ERR, "%s: %m", buf);
553		nerr++;
554		goto closefd;
555	}
556	oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/
557	if (compress) {
558		snprintf(filename, sizeof(filename), "%s.%d.gz",
559		    istextdump ? "textdump.tar" : "vmcore", bounds);
560		fp = zopen(filename, "w");
561	} else {
562		snprintf(filename, sizeof(filename), "%s.%d",
563		    istextdump ? "textdump.tar" : "vmcore", bounds);
564		fp = fopen(filename, "w");
565	}
566	if (fp == NULL) {
567		syslog(LOG_ERR, "%s: %m", filename);
568		close(fdinfo);
569		nerr++;
570		goto closefd;
571	}
572	(void)umask(oumask);
573
574	info = fdopen(fdinfo, "w");
575
576	if (info == NULL) {
577		syslog(LOG_ERR, "fdopen failed: %m");
578		nerr++;
579		goto closefd;
580	}
581
582	if (verbose)
583		printheader(stdout, &kdhl, device, bounds, status);
584
585	printheader(info, &kdhl, device, bounds, status);
586	fclose(info);
587
588	syslog(LOG_NOTICE, "writing %score to %s",
589	    compress ? "compressed " : "", filename);
590
591	if (istextdump) {
592		if (DoTextdumpFile(fd, dumpsize, lasthd, buf, device,
593		    filename, fp) < 0)
594			goto closeall;
595	} else {
596		if (DoRegularFile(fd, dumpsize, buf, device, filename, fp)
597		    < 0)
598			goto closeall;
599	}
600	if (verbose)
601		printf("\n");
602
603	if (fclose(fp) < 0) {
604		syslog(LOG_ERR, "error on %s: %m", filename);
605		nerr++;
606		goto closeall;
607	}
608	nsaved++;
609
610	if (verbose)
611		printf("dump saved\n");
612
613nuke:
614	if (!keep) {
615		if (verbose)
616			printf("clearing dump header\n");
617		memcpy(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic);
618		lseek(fd, lasthd, SEEK_SET);
619		error = write(fd, &kdhl, sizeof kdhl);
620		if (error != sizeof kdhl)
621			syslog(LOG_ERR,
622			    "error while clearing the dump header: %m");
623	}
624	close(fd);
625	return;
626
627closeall:
628	fclose(fp);
629
630closefd:
631	close(fd);
632}
633
634static void
635usage(void)
636{
637	fprintf(stderr, "%s\n%s\n%s\n",
638	    "usage: savecore -c [-v] [device ...]",
639	    "       savecore -C [-v] [device ...]",
640	    "       savecore [-fkvz] [directory [device ...]]");
641	exit (1);
642}
643
644int
645main(int argc, char **argv)
646{
647	const char *savedir = ".";
648	struct fstab *fsp;
649	int i, ch, error;
650
651	checkfor = compress = clear = force = keep = verbose = 0;
652	nfound = nsaved = nerr = 0;
653
654	openlog("savecore", LOG_PERROR, LOG_DAEMON);
655	signal(SIGINFO, infohandler);
656
657	while ((ch = getopt(argc, argv, "Ccfkvz")) != -1)
658		switch(ch) {
659		case 'C':
660			checkfor = 1;
661			break;
662		case 'c':
663			clear = 1;
664			break;
665		case 'f':
666			force = 1;
667			break;
668		case 'k':
669			keep = 1;
670			break;
671		case 'v':
672			verbose++;
673			break;
674		case 'z':
675			compress = 1;
676			break;
677		case '?':
678		default:
679			usage();
680		}
681	if (checkfor && (clear || force || keep))
682		usage();
683	if (clear && (compress || keep))
684		usage();
685	argc -= optind;
686	argv += optind;
687	if (argc >= 1 && !checkfor && !clear) {
688		error = chdir(argv[0]);
689		if (error) {
690			syslog(LOG_ERR, "chdir(%s): %m", argv[0]);
691			exit(1);
692		}
693		savedir = argv[0];
694		argc--;
695		argv++;
696	}
697	if (argc == 0) {
698		for (;;) {
699			fsp = getfsent();
700			if (fsp == NULL)
701				break;
702			if (strcmp(fsp->fs_vfstype, "swap") &&
703			    strcmp(fsp->fs_vfstype, "dump"))
704				continue;
705			DoFile(savedir, fsp->fs_spec);
706		}
707	} else {
708		for (i = 0; i < argc; i++)
709			DoFile(savedir, argv[i]);
710	}
711
712	/* Emit minimal output. */
713	if (nfound == 0) {
714		if (checkfor) {
715			printf("No dump exists\n");
716			exit(1);
717		}
718		syslog(LOG_WARNING, "no dumps found");
719	}
720	else if (nsaved == 0) {
721		if (nerr != 0)
722			syslog(LOG_WARNING, "unsaved dumps found but not saved");
723		else
724			syslog(LOG_WARNING, "no unsaved dumps found");
725	}
726
727	return (0);
728}
729
730static void
731infohandler(int sig __unused)
732{
733	got_siginfo = 1;
734}
735