summaryrefslogtreecommitdiffstats
path: root/sbin/savecore
diff options
context:
space:
mode:
authordougb <dougb@FreeBSD.org>2003-09-04 10:07:01 +0000
committerdougb <dougb@FreeBSD.org>2003-09-04 10:07:01 +0000
commit724364937f46aff1745c4eb77eac7867eb5cddf1 (patch)
tree331b17dab23808bef2db1a9cff5cda15a4366424 /sbin/savecore
parent480778ce65fd1888aac1652a022fa301036ad443 (diff)
downloadFreeBSD-src-724364937f46aff1745c4eb77eac7867eb5cddf1.zip
FreeBSD-src-724364937f46aff1745c4eb77eac7867eb5cddf1.tar.gz
Add a flag that reports the existence of a dump, and does nothing else.
The immediate purpose for this option is to use it in rc.d so that we can make savecore behavior conditional. Tremendous assistance with ideas and sanity checking provided by tjr and b@etek.chalmers.se.
Diffstat (limited to 'sbin/savecore')
-rw-r--r--sbin/savecore/savecore.812
-rw-r--r--sbin/savecore/savecore.c24
2 files changed, 32 insertions, 4 deletions
diff --git a/sbin/savecore/savecore.8 b/sbin/savecore/savecore.8
index 5ec8799..cd8518b 100644
--- a/sbin/savecore/savecore.8
+++ b/sbin/savecore/savecore.8
@@ -42,6 +42,10 @@
.Nm
.Fl c
.Nm
+.Fl C
+.Op Fl v
+.Op Ar directory device
+.Nm
.Op Fl fkvz
.Op Ar directory Op Ar device ...
.Sh DESCRIPTION
@@ -58,6 +62,14 @@ the system log.
.Pp
The options are as follows:
.Bl -tag -width indent
+.It Fl C
+Check to see if a dump exists,
+and display a brief message to indicate the status.
+An exit status of 0 indicates that a dump is there,
+1 indicates that none exists.
+This option is compatible only with the
+.Op Fl v
+option.
.It Fl c
Clear the dump, so that future invocations of
.Nm
diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c
index 019d184..c7b4f1f 100644
--- a/sbin/savecore/savecore.c
+++ b/sbin/savecore/savecore.c
@@ -88,7 +88,7 @@ __FBSDID("$FreeBSD$");
/* The size of the buffer used for I/O. */
#define BUFFERSIZE (1024*1024)
-int compress, clear, force, keep, verbose; /* flags */
+int checkfor, compress, clear, force, keep, verbose; /* flags */
int nfound, nsaved, nerr; /* statistics */
extern FILE *zopen(const char *, const char *);
@@ -321,6 +321,12 @@ DoFile(char *savedir, const char *device)
goto closefd;
}
+ if (checkfor) {
+ printf("A dump exists on %s\n", device);
+ close(fd);
+ exit(0);
+ }
+
if (kdhl.panicstring[0])
syslog(LOG_ALERT, "reboot after panic: %s", kdhl.panicstring);
else
@@ -478,7 +484,7 @@ closefd:
static void
usage(void)
{
- fprintf(stderr, "usage: savecore [-cfkv] [directory [device...]]\n");
+ fprintf(stderr, "usage: savecore [-Cv|-cfkv] [directory [device...]]\n");
exit (1);
}
@@ -496,8 +502,11 @@ main(int argc, char **argv)
syslog(LOG_ERR, "Cannot allocate memory");
exit(1);
}
- while ((ch = getopt(argc, argv, "cdfkN:vz")) != -1)
+ while ((ch = getopt(argc, argv, "CcdfkN:vz")) != -1)
switch(ch) {
+ case 'C':
+ checkfor = 1;
+ break;
case 'c':
clear = 1;
break;
@@ -519,6 +528,8 @@ main(int argc, char **argv)
default:
usage();
}
+ if (checkfor && (clear || force || keep))
+ usage();
argc -= optind;
argv += optind;
if (argc >= 1) {
@@ -547,8 +558,13 @@ main(int argc, char **argv)
}
/* Emit minimal output. */
- if (nfound == 0)
+ if (nfound == 0) {
+ if (checkfor) {
+ printf("No dump exists\n");
+ exit(1);
+ }
syslog(LOG_WARNING, "no dumps found");
+ }
else if (nsaved == 0) {
if (nerr != 0)
syslog(LOG_WARNING, "unsaved dumps found but not saved");
OpenPOWER on IntegriCloud