1994-05-26 06:35:07 +00:00
|
|
|
/*-
|
2002-03-31 22:26:56 +00:00
|
|
|
* Copyright (c) 2002 Poul-Henning Kamp
|
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Poul-Henning Kamp
|
|
|
|
* and NAI Labs, the Security Research Division of Network Associates, Inc.
|
|
|
|
* under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
|
|
|
|
* DARPA CHATS research program.
|
1994-05-26 06:35:07 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2002-03-31 22:26:56 +00:00
|
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
1994-05-26 06:35:07 +00:00
|
|
|
*
|
2002-03-31 22:26:56 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
1994-05-26 06:35:07 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2002-03-31 22:26:56 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1994-05-26 06:35:07 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2002-05-05 01:04:00 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1986, 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1994-05-26 06:35:07 +00:00
|
|
|
*/
|
|
|
|
|
2002-04-21 07:18:16 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
#include <sys/param.h>
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/kerneldump.h>
|
2002-05-04 10:36:35 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
2002-03-31 22:26:56 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fstab.h>
|
2002-05-04 10:36:35 +00:00
|
|
|
#include <paths.h>
|
2002-05-05 01:04:00 +00:00
|
|
|
#include <stdarg.h>
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-05-05 01:04:00 +00:00
|
|
|
#include <syslog.h>
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
#include <time.h>
|
2002-03-31 22:26:56 +00:00
|
|
|
#include <unistd.h>
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-06-02 19:20:37 +00:00
|
|
|
/* The size of the buffer used for I/O. */
|
|
|
|
#define BUFFERSIZE (1024*1024)
|
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
int compress, clear, force, keep, verbose; /* flags */
|
|
|
|
int nfound, nsaved, nerr; /* statistics */
|
|
|
|
|
|
|
|
extern FILE *zopen(const char *, const char *);
|
2002-03-31 22:26:56 +00:00
|
|
|
|
|
|
|
static void
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
printheader(FILE *f, const struct kerneldumpheader *h, const char *device,
|
2002-05-05 01:04:00 +00:00
|
|
|
int bounds)
|
2002-03-31 22:26:56 +00:00
|
|
|
{
|
2002-04-03 07:24:12 +00:00
|
|
|
uint64_t dumplen;
|
2002-03-31 22:26:56 +00:00
|
|
|
time_t t;
|
|
|
|
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
fprintf(f, "Good dump found on device %s\n", device);
|
2002-03-31 22:26:56 +00:00
|
|
|
fprintf(f, " Architecture: %s\n", h->architecture);
|
2002-04-03 07:24:12 +00:00
|
|
|
fprintf(f, " Architecture version: %d\n",
|
|
|
|
dtoh32(h->architectureversion));
|
|
|
|
dumplen = dtoh64(h->dumplength);
|
|
|
|
fprintf(f, " Dump length: %lldB (%lld MB)\n", (long long)dumplen,
|
|
|
|
(long long)(dumplen >> 20));
|
|
|
|
fprintf(f, " Blocksize: %d\n", dtoh32(h->blocksize));
|
|
|
|
t = dtoh64(h->dumptime);
|
2002-03-31 22:26:56 +00:00
|
|
|
fprintf(f, " Dumptime: %s", ctime(&t));
|
|
|
|
fprintf(f, " Hostname: %s\n", h->hostname);
|
|
|
|
fprintf(f, " Versionstring: %s", h->versionstring);
|
|
|
|
fprintf(f, " Panicstring: %s\n", h->panicstring);
|
2002-05-05 01:04:00 +00:00
|
|
|
fprintf(f, " Bounds: %d\n", bounds);
|
2002-04-19 09:38:45 +00:00
|
|
|
fflush(f);
|
2002-03-31 22:26:56 +00:00
|
|
|
}
|
2002-04-03 07:24:12 +00:00
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
static int
|
|
|
|
getbounds(void) {
|
|
|
|
FILE *fp;
|
|
|
|
char buf[6];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
if ((fp = fopen("bounds", "r")) == NULL) {
|
|
|
|
syslog(LOG_WARNING, "unable to open bounds file, using 0");
|
|
|
|
goto newfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fgets(buf, sizeof buf, fp) == NULL) {
|
|
|
|
syslog(LOG_WARNING, "unable to read from bounds, using 0");
|
|
|
|
fclose(fp);
|
|
|
|
goto newfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ret = (int)strtol(buf, NULL, 10);
|
|
|
|
if (ret == 0 && (errno == EINVAL || errno == ERANGE))
|
|
|
|
syslog(LOG_WARNING, "invalid value found in bounds, using 0");
|
|
|
|
|
|
|
|
newfile:
|
|
|
|
|
|
|
|
if ((fp = fopen("bounds", "w")) == NULL) {
|
|
|
|
syslog(LOG_WARNING, "unable to write to bounds file: %m");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
printf("bounds number: %d\n", ret);
|
|
|
|
|
|
|
|
fprintf(fp, "%d\n", (ret + 1));
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2002-05-04 10:36:35 +00:00
|
|
|
/*
|
|
|
|
* Check that sufficient space is available on the disk that holds the
|
|
|
|
* save directory.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
check_space(char *savedir, off_t dumpsize)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
2002-05-05 01:04:00 +00:00
|
|
|
off_t minfree, spacefree, totfree, needed;
|
2002-05-04 10:36:35 +00:00
|
|
|
struct statfs fsbuf;
|
|
|
|
char buf[100], path[MAXPATHLEN];
|
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
if (statfs(savedir, &fsbuf) < 0) {
|
|
|
|
syslog(LOG_ERR, "%s: %m", savedir);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-05-04 10:36:35 +00:00
|
|
|
spacefree = ((off_t) fsbuf.f_bavail * fsbuf.f_bsize) / 1024;
|
|
|
|
totfree = ((off_t) fsbuf.f_bfree * fsbuf.f_bsize) / 1024;
|
|
|
|
|
|
|
|
(void)snprintf(path, sizeof(path), "%s/minfree", savedir);
|
|
|
|
if ((fp = fopen(path, "r")) == NULL)
|
|
|
|
minfree = 0;
|
|
|
|
else {
|
|
|
|
if (fgets(buf, sizeof(buf), fp) == NULL)
|
|
|
|
minfree = 0;
|
|
|
|
else
|
|
|
|
minfree = atoi(buf);
|
|
|
|
(void)fclose(fp);
|
|
|
|
}
|
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
needed = dumpsize / 1024 + 2; /* 2 for info file */
|
2002-05-04 10:36:35 +00:00
|
|
|
if (((minfree > 0) ? spacefree : totfree) - needed < minfree) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_WARNING,
|
|
|
|
"no dump, not enough free space on device (%lld available, need %lld)",
|
2002-05-04 10:36:35 +00:00
|
|
|
(long long)(minfree > 0 ? spacefree : totfree),
|
|
|
|
(long long)needed);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (spacefree - needed < 0)
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_WARNING,
|
|
|
|
"dump performed, but free space threshold crossed");
|
2002-05-04 10:36:35 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
#define BLOCKSIZE (1<<12)
|
|
|
|
#define BLOCKMASK (~(BLOCKSIZE-1))
|
2002-03-31 22:26:56 +00:00
|
|
|
|
|
|
|
static void
|
2002-05-04 10:36:35 +00:00
|
|
|
DoFile(char *savedir, const char *device)
|
2002-03-31 22:26:56 +00:00
|
|
|
{
|
2002-05-27 07:54:43 +00:00
|
|
|
static char *buf = NULL;
|
2002-03-31 22:26:56 +00:00
|
|
|
struct kerneldumpheader kdhf, kdhl;
|
2002-05-05 01:04:00 +00:00
|
|
|
off_t mediasize, dumpsize, firsthd, lasthd, dmpcnt;
|
|
|
|
FILE *info, *fp;
|
|
|
|
int fd, fdinfo, error, wl;
|
|
|
|
int nr, nw, hs, he;
|
|
|
|
int bounds;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
u_int sectorsize;
|
2002-05-05 01:04:00 +00:00
|
|
|
mode_t oumask;
|
|
|
|
|
|
|
|
dmpcnt = 0;
|
|
|
|
mediasize = 0;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-05-27 07:54:43 +00:00
|
|
|
/*
|
|
|
|
* XXX On ia64 something breaks when the buffer is put on the
|
|
|
|
* stack. When the buffer is roughly larger than 128K the read()
|
|
|
|
* below simply fails with errno=14 (EFAULT). We work around
|
2003-01-01 18:49:04 +00:00
|
|
|
* this by doing a one-time allocation...
|
2002-05-27 07:54:43 +00:00
|
|
|
*/
|
|
|
|
if (buf == NULL) {
|
2002-06-02 19:20:37 +00:00
|
|
|
buf = malloc(BUFFERSIZE);
|
2002-05-27 07:54:43 +00:00
|
|
|
if (buf == NULL) {
|
|
|
|
syslog(LOG_ERR, "%m");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
if (verbose)
|
2002-05-05 01:04:00 +00:00
|
|
|
printf("checking for kernel dump on device %s\n", device);
|
2002-03-31 22:26:56 +00:00
|
|
|
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
fd = open(device, O_RDWR);
|
2002-03-31 22:26:56 +00:00
|
|
|
if (fd < 0) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR, "%s: %m", device);
|
2002-03-31 22:26:56 +00:00
|
|
|
return;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-05-27 07:54:43 +00:00
|
|
|
|
2002-03-31 22:26:56 +00:00
|
|
|
error = ioctl(fd, DIOCGMEDIASIZE, &mediasize);
|
|
|
|
if (!error)
|
|
|
|
error = ioctl(fd, DIOCGSECTORSIZE, §orsize);
|
|
|
|
if (error) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"couldn't find media and/or sector size of %s: %m", device);
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
goto closefd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose) {
|
2002-05-05 01:04:00 +00:00
|
|
|
printf("mediasize = %lld\n", (long long)mediasize);
|
|
|
|
printf("sectorsize = %u\n", sectorsize);
|
1999-05-13 04:29:09 +00:00
|
|
|
}
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-03-31 22:26:56 +00:00
|
|
|
lasthd = mediasize - sectorsize;
|
|
|
|
lseek(fd, lasthd, SEEK_SET);
|
|
|
|
error = read(fd, &kdhl, sizeof kdhl);
|
|
|
|
if (error != sizeof kdhl) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"error reading last dump header at offset %lld in %s: %m",
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
(long long)lasthd, device);
|
|
|
|
goto closefd;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-03-31 22:26:56 +00:00
|
|
|
if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic)) {
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
if (verbose)
|
2002-05-05 01:04:00 +00:00
|
|
|
printf("magic mismatch on last dump header on %s\n",
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
device);
|
2002-05-05 01:04:00 +00:00
|
|
|
|
|
|
|
if (force == 0)
|
|
|
|
goto closefd;
|
|
|
|
|
|
|
|
if (memcmp(kdhl.magic, KERNELDUMPMAGIC_CLEARED,
|
|
|
|
sizeof kdhl.magic) == 0) {
|
|
|
|
if (verbose)
|
|
|
|
printf("forcing magic on %s\n", device);
|
|
|
|
memcpy(kdhl.magic, KERNELDUMPMAGIC,
|
|
|
|
sizeof kdhl.magic);
|
|
|
|
} else {
|
|
|
|
syslog(LOG_ERR, "unable to force dump - bad magic");
|
|
|
|
goto closefd;
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-04-03 07:24:12 +00:00
|
|
|
if (dtoh32(kdhl.version) != KERNELDUMPVERSION) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"unknown version (%d) in last dump header on %s",
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
dtoh32(kdhl.version), device);
|
|
|
|
goto closefd;
|
|
|
|
}
|
|
|
|
|
|
|
|
nfound++;
|
|
|
|
if (clear)
|
|
|
|
goto nuke;
|
|
|
|
|
|
|
|
if (kerneldump_parity(&kdhl)) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"parity error on last dump header on %s", device);
|
2002-05-04 10:36:35 +00:00
|
|
|
nerr++;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
goto closefd;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-04-03 07:24:12 +00:00
|
|
|
dumpsize = dtoh64(kdhl.dumplength);
|
|
|
|
firsthd = lasthd - dumpsize - sizeof kdhf;
|
2002-03-31 22:26:56 +00:00
|
|
|
lseek(fd, firsthd, SEEK_SET);
|
|
|
|
error = read(fd, &kdhf, sizeof kdhf);
|
|
|
|
if (error != sizeof kdhf) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"error reading first dump header at offset %lld in %s: %m",
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
(long long)firsthd, device);
|
2002-05-04 10:36:35 +00:00
|
|
|
nerr++;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
goto closefd;
|
2000-09-28 20:09:36 +00:00
|
|
|
}
|
2002-03-31 22:26:56 +00:00
|
|
|
if (memcmp(&kdhl, &kdhf, sizeof kdhl)) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"first and last dump headers disagree on %s", device);
|
2002-05-04 10:36:35 +00:00
|
|
|
nerr++;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
goto closefd;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
if (kdhl.panicstring[0])
|
|
|
|
syslog(LOG_ALERT, "reboot after panic: %s", kdhl.panicstring);
|
|
|
|
else
|
|
|
|
syslog(LOG_ALERT, "reboot");
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
if (verbose)
|
|
|
|
printf("Checking for available free space\n");
|
2002-05-04 10:36:35 +00:00
|
|
|
if (!check_space(savedir, dumpsize)) {
|
|
|
|
nerr++;
|
|
|
|
goto closefd;
|
|
|
|
}
|
2002-05-05 01:04:00 +00:00
|
|
|
|
|
|
|
bounds = getbounds();
|
|
|
|
|
|
|
|
sprintf(buf, "info.%d", bounds);
|
|
|
|
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
/*
|
|
|
|
* Create or overwrite any existing files.
|
|
|
|
*/
|
|
|
|
fdinfo = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600);
|
2002-03-31 22:26:56 +00:00
|
|
|
if (fdinfo < 0) {
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR, "%s: %m", buf);
|
2002-05-04 10:36:35 +00:00
|
|
|
nerr++;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
goto closefd;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-05-05 01:04:00 +00:00
|
|
|
oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/
|
|
|
|
if (compress) {
|
|
|
|
sprintf(buf, "vmcore.%d.gz", bounds);
|
|
|
|
fp = zopen(buf, "w");
|
|
|
|
} else {
|
|
|
|
sprintf(buf, "vmcore.%d", bounds);
|
|
|
|
fp = fopen(buf, "w");
|
|
|
|
}
|
|
|
|
if (fp == NULL) {
|
|
|
|
syslog(LOG_ERR, "%s: %m", buf);
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
close(fdinfo);
|
2002-05-04 10:36:35 +00:00
|
|
|
nerr++;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
goto closefd;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-05-05 01:04:00 +00:00
|
|
|
(void)umask(oumask);
|
|
|
|
|
2002-03-31 22:26:56 +00:00
|
|
|
info = fdopen(fdinfo, "w");
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
|
|
|
if (verbose)
|
2002-05-05 01:04:00 +00:00
|
|
|
printheader(stdout, &kdhl, device, bounds);
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
printheader(info, &kdhl, device, bounds);
|
|
|
|
fclose(info);
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_NOTICE, "writing %score to %s",
|
|
|
|
compress ? "compressed " : "", buf);
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-03-31 22:26:56 +00:00
|
|
|
while (dumpsize > 0) {
|
2002-06-02 19:20:37 +00:00
|
|
|
wl = BUFFERSIZE;
|
2002-03-31 22:26:56 +00:00
|
|
|
if (wl > dumpsize)
|
|
|
|
wl = dumpsize;
|
2002-05-05 01:04:00 +00:00
|
|
|
nr = read(fd, buf, wl);
|
|
|
|
if (nr != wl) {
|
|
|
|
if (nr == 0)
|
|
|
|
syslog(LOG_WARNING,
|
|
|
|
"WARNING: EOF on dump device");
|
|
|
|
else
|
|
|
|
syslog(LOG_ERR, "read error on %s: %m", device);
|
2002-05-04 10:36:35 +00:00
|
|
|
nerr++;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
goto closeall;
|
2000-10-17 22:43:41 +00:00
|
|
|
}
|
2002-05-05 01:04:00 +00:00
|
|
|
if (compress) {
|
|
|
|
nw = fwrite(buf, 1, wl, fp);
|
|
|
|
} else {
|
|
|
|
for (nw = 0; nw < nr; nw = he) {
|
|
|
|
/* find a contiguous block of zeroes */
|
|
|
|
for (hs = nw; hs < nr; hs += BLOCKSIZE) {
|
|
|
|
for (he = hs; he < nr && buf[he] == 0; ++he)
|
|
|
|
/* nothing */ ;
|
|
|
|
/* is the hole long enough to matter? */
|
|
|
|
if (he >= hs + BLOCKSIZE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* back down to a block boundary */
|
|
|
|
he &= BLOCKMASK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1) Don't go beyond the end of the buffer.
|
|
|
|
* 2) If the end of the buffer is less than
|
|
|
|
* BLOCKSIZE bytes away, we're at the end
|
|
|
|
* of the file, so just grab what's left.
|
|
|
|
*/
|
|
|
|
if (hs + BLOCKSIZE > nr)
|
|
|
|
hs = he = nr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, we have a partial ordering:
|
|
|
|
* nw <= hs <= he <= nr
|
|
|
|
* If hs > nw, buf[nw..hs] contains non-zero data.
|
|
|
|
* If he > hs, buf[hs..he] is all zeroes.
|
|
|
|
*/
|
|
|
|
if (hs > nw)
|
|
|
|
if (fwrite(buf + nw, hs - nw, 1, fp) != 1)
|
|
|
|
break;
|
|
|
|
if (he > hs)
|
|
|
|
if (fseek(fp, he - hs, SEEK_CUR) == -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nw != wl) {
|
|
|
|
syslog(LOG_ERR,
|
|
|
|
"write error on vmcore.%d file: %m", bounds);
|
|
|
|
syslog(LOG_WARNING,
|
|
|
|
"WARNING: vmcore may be incomplete");
|
2002-05-04 10:36:35 +00:00
|
|
|
nerr++;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
goto closeall;
|
2002-03-31 22:26:56 +00:00
|
|
|
}
|
2002-05-05 01:04:00 +00:00
|
|
|
if (verbose) {
|
|
|
|
dmpcnt += wl;
|
2002-05-06 08:27:21 +00:00
|
|
|
printf("%llu\r", (unsigned long long)dmpcnt);
|
2002-05-05 01:04:00 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
2002-03-31 22:26:56 +00:00
|
|
|
dumpsize -= wl;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-05-05 01:04:00 +00:00
|
|
|
if (verbose)
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (fclose(fp) < 0) {
|
|
|
|
syslog(LOG_ERR, "error on vmcore.%d: %m", bounds);
|
|
|
|
nerr++;
|
|
|
|
goto closeall;
|
|
|
|
}
|
2002-05-04 10:36:35 +00:00
|
|
|
nsaved++;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
|
|
|
if (verbose)
|
2002-05-05 01:04:00 +00:00
|
|
|
printf("dump saved\n");
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
nuke:
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
if (clear || !keep) {
|
|
|
|
if (verbose)
|
2002-05-05 01:04:00 +00:00
|
|
|
printf("clearing dump header\n");
|
|
|
|
memcpy(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic);
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
lseek(fd, lasthd, SEEK_SET);
|
|
|
|
error = write(fd, &kdhl, sizeof kdhl);
|
|
|
|
if (error != sizeof kdhl)
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"error while clearing the dump header: %m");
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
closeall:
|
|
|
|
fclose(fp);
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
closefd:
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
close(fd);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2002-03-31 22:26:56 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-04-21 07:18:16 +00:00
|
|
|
fprintf(stderr, "usage: savecore [-cfkv] [directory [device...]]\n");
|
2002-03-31 22:26:56 +00:00
|
|
|
exit (1);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-03-31 22:26:56 +00:00
|
|
|
main(int argc, char **argv)
|
1999-08-31 18:12:44 +00:00
|
|
|
{
|
2002-03-31 22:26:56 +00:00
|
|
|
int i, ch, error;
|
|
|
|
struct fstab *fsp;
|
2002-05-04 10:36:35 +00:00
|
|
|
char *savedir;
|
1999-08-31 18:12:44 +00:00
|
|
|
|
2002-05-05 01:04:00 +00:00
|
|
|
openlog("savecore", LOG_PERROR, LOG_DAEMON);
|
|
|
|
|
2002-05-04 10:36:35 +00:00
|
|
|
savedir = strdup(".");
|
2002-05-05 01:04:00 +00:00
|
|
|
if (savedir == NULL) {
|
|
|
|
syslog(LOG_ERR, "Cannot allocate memory");
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-03-31 22:26:56 +00:00
|
|
|
while ((ch = getopt(argc, argv, "cdfkN:vz")) != -1)
|
|
|
|
switch(ch) {
|
|
|
|
case 'c':
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
clear = 1;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
keep = 1;
|
|
|
|
break;
|
2002-03-31 22:26:56 +00:00
|
|
|
case 'v':
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
verbose = 1;
|
|
|
|
break;
|
2002-03-31 22:26:56 +00:00
|
|
|
case 'f':
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
force = 1;
|
|
|
|
break;
|
2002-05-05 01:04:00 +00:00
|
|
|
case 'z':
|
|
|
|
compress = 1;
|
|
|
|
break;
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
case 'd': /* Obsolete */
|
2002-03-31 22:26:56 +00:00
|
|
|
case 'N':
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (argc >= 1) {
|
|
|
|
error = chdir(argv[0]);
|
2002-05-05 01:04:00 +00:00
|
|
|
if (error) {
|
|
|
|
syslog(LOG_ERR, "chdir(%s): %m", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-05-04 10:36:35 +00:00
|
|
|
savedir = argv[0];
|
2002-03-31 22:26:56 +00:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
if (argc == 0) {
|
|
|
|
for (;;) {
|
|
|
|
fsp = getfsent();
|
|
|
|
if (fsp == NULL)
|
|
|
|
break;
|
|
|
|
if (strcmp(fsp->fs_vfstype, "swap") &&
|
|
|
|
strcmp(fsp->fs_vfstype, "dump"))
|
|
|
|
continue;
|
2002-05-04 10:36:35 +00:00
|
|
|
DoFile(savedir, fsp->fs_spec);
|
2002-03-31 22:26:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < argc; i++)
|
2002-05-04 10:36:35 +00:00
|
|
|
DoFile(savedir, argv[i]);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
|
|
|
/* Emit minimal output. */
|
|
|
|
if (nfound == 0)
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_WARNING, "no dumps found");
|
2002-05-04 10:36:35 +00:00
|
|
|
else if (nsaved == 0) {
|
|
|
|
if (nerr != 0)
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_WARNING, "unsaved dumps found but not saved");
|
2002-05-04 10:36:35 +00:00
|
|
|
else
|
2002-05-05 01:04:00 +00:00
|
|
|
syslog(LOG_WARNING, "no unsaved dumps found");
|
2002-05-04 10:36:35 +00:00
|
|
|
}
|
High-level changes (user visible):
o Implement -c (clear) to clear previously kept headers (note that
dumps not cleared will remain until -c is used),
o Implement -f (force) to allow re-saving a previously saved dump,
o Implement -k (keep) and make clearing the dump header the default,
o Implement -v (verbose) and make most output conditional upon it,
o Emit minimal output for the non-verbose case with the assumption
that savecore is run mostly from within /etc/rc,
o Update usage message to reflect what is and what's not,
o mark -d as obsolete.
Low-level changes:
o Rename devname to device, for devname mirrors a global declaration
and GCC 3.x warns about it,
o Open the dump device R/W for clear and !keep to work,
o Reorder the locals of DoFile according to style(9),
o Remove newlines from strings passed to warn* and err*,
o Use stat(2) to check if a dump has been saved before,
o Truncate existing core and info files to support force,
o First check for the magic and the version before we complain about
parity errors. This prevents emitting parity error messages when
there's no dump,
o Keep track of the number of headers found and the number of headers
saved to support the minimal output,
o Close files we opened in DoFile. Not critical, but cleaner.
2002-04-13 08:20:15 +00:00
|
|
|
|
2002-03-31 22:26:56 +00:00
|
|
|
return (0);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|