Home | History | Annotate | Download | only in savecore
History log of /src/sbin/savecore/savecore.c
RevisionDateAuthorComments
 1.90  03-Apr-2020  maxv Avoid overflows when reading strings.
 1.89  06-Nov-2019  mrg elide recently introduced warnings that trigger in normal cases, eg:

savecore: dump_exists:471: kvm_read newdumpmag: _kvm_kvatop(ffffffff8180030c)
 1.88  27-Dec-2018  mrg avoid infinite loop in kmem_check(). fixes bug introduced in previous.
 1.87  06-Nov-2018  mrg put a bunch of the kvm_read + warn on failure code into a macro that
describes more about what failed. now errors tell you which actual
variable was being requested instead of simply saying "not yours".

tested on amd64 as working. written for arm64 testing.
 1.86  13-May-2013  christos branches: 1.86.26; 1.86.28;
- avoid using globals where it is simple.
- simplify: only use stdio for output.
 1.85  07-Apr-2012  christos branches: 1.85.2;
factor out rawname() from dump, fsck, savecore.
 1.84  13-Sep-2011  christos branches: 1.84.2;
print the missing flag if missing argument...
 1.83  12-Sep-2011  christos - always print corrupted dump messages instead of silently failing
- don't require /var/crash to be specified, default to it
- determine and print the kernel name
- print all messages to syslog
 1.82  29-Aug-2011  joerg static + __dead
 1.81  18-Aug-2009  dogcow Instead of exiting with an obscure error message if -N /kernelname isn't
specified, blithely assume the kernel will consume around 20 megs.
 1.80  06-Apr-2009  lukem fix sign-compare issues
 1.79  21-Mar-2009  tls Fix savecore so it uses /dev/ksyms when it can (doesn't override libkvm
default). Fixes misc/38425.
 1.78  28-Dec-2008  christos branches: 1.78.2;
fix dev_t format.
 1.77  05-Dec-2008  ad Enable the faked ELF kernel by default, now that ksyms output works with
gdb. Makes it possible to do post-mortem debugging on a modular kernel.
 1.76  20-Oct-2008  ad branches: 1.76.2;
- Add code to produce a fake ELF kernel containing only symbol info. Done
by extracting ksyms state from the dump, so we have symbols for modules
loaded at the time of the crash. If ksyms extraction fails, this falls
back to the current behaviour of copying /netbsd.

- Leave it disabled for the moment: (1) we are about to branch (2) most
tools understand the artificial kernel but gdb has trouble with it for
some reason.
 1.75  09-Oct-2008  joerg Explicitly check that the dump device is not the console, a tty or pty.
While the list is adhoc, the problems reported are always with
/dev/console. Adresses PR 38425 and similiar issues with Xen.
 1.74  20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
(Tweak some to use a consistent format.)
 1.73  20-Apr-2008  ad branches: 1.73.2;
sync() a couple of times to benefit diagnosis of sloppy kernel code that
crashes during boot to multiuser.
 1.72  15-Jan-2008  ad branches: 1.72.4; 1.72.6;
Don't use the block device to read crashdumps, if possible.
 1.71  12-Nov-2007  pooka branches: 1.71.2;
tyop: _time_seconf -> _time_second
 1.70  18-Dec-2006  christos branches: 1.70.4;
from Anon Ymous: remove (void)&var;
 1.69  16-Oct-2006  christos c99 initializers
 1.68  09-Jul-2006  kardel accept either "time_second" or "time" as kernel timevariable in
order to support common userland in enviroments where
timecounter kernels and non timecounter kernel co-exist
(e.g. xen & i386)
 1.67  07-Jun-2006  kardel support timecounters (struct time gone, use time_second then)
 1.66  17-Mar-2006  hubertf Free some allocated memory in the failure case when trying to
fetch the panic string.

Fixes Coverity CID 1856.
 1.65  16-Oct-2004  dsainty branches: 1.65.6;
Added -n option, which tests for a present core but doesn't write it
to disk or clear it (does 'nothing').

http://mail-index.netbsd.org/tech-userlevel/2004/10/09/0000.html
 1.64  14-Jul-2004  tls Fix an integer overflow that prevented saving cores from machines with
more than 2GB of RAM.

"dumpsize" in the on-disk core header is in pages, but, unfortunately,
c.size in our kcore format is an unsigned 32-bit int, gross.

We sleaze it, using a 64-bit int internally here and handing it to
libkvm as a *signed* 32-bit int. Won't always work, but shouldn't be
broken any worse than it is now, and sometimes work better.

We must fix the kcore format and libkvm.
 1.63  21-Apr-2004  christos Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.62  30-Mar-2004  christos Give a 60 day leeway instead of a week when judging if the dumptime is valid.
7 days is too short when you are debugging time problems.
 1.61  07-Aug-2003  agc branches: 1.61.2;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22308, verified by myself.
 1.60  18-May-2003  itojun simplify by strlcpy
 1.59  06-Dec-2002  thorpej Remove prototype for non-existent function log().
 1.58  27-Sep-2002  drochner use humanize_number(3) for progress printout
 1.57  19-Mar-2002  christos branches: 1.57.2;
PR/15502: Wolfgang Rupprecht: savecore fails for > 2GB files.
 1.56  06-Mar-2002  tsutsui Change type of dumpmag and newdumpmag from int to u_int32_t
since they hold 32bit unsigned magic numbers. (sync with kernels)
 1.55  01-Nov-2001  lukem fix a couple of -Wshadow warnings
 1.54  12-Sep-2001  lukem explicitly set the default compression level to 1 (from the implicit 6),
because it's significantly faster and doesn't use that much more disk space.
 1.53  12-Sep-2001  lukem Add "-Z level" to control the compression level that -z uses (which
defaults to -Z 6). Depending on the relative speed of the CPU
versus disk, "-zZ1" might be faster than no compression at all.
 1.52  13-Jun-2001  wiz Use getbootfile(3) instead of _PATH_UNIX by default.
Sprinkle some const.
 1.51  06-May-2001  simonb If the position of the formatted panic string can be found in the
message buffer, use that instead of the raw panic string.

Suggested by Jason Thorpe eons ago.
 1.50  11-Jan-2001  martin Make option flag variables static. This avoids a conflict between
'int compress' in savecore.c and the function 'compress' in libz.
Gnu ld 2.10 (with BFD 2.10) used on sparc64 warns this conflict
(symbol "compress" changed size).
 1.49  02-Jan-2001  joda use gzip instead of compress
 1.48  02-Jan-2001  lukem Bump the field width of `K to go' from 6 to 8; some systems have more
than 999999 KB of RAM... (this will suffice until it's common to have
~ 100 GB of RAM :)
 1.47  11-Dec-2000  wiz Back out sysctl part for now, awaiting the result of further discussion,
on request of Andrew Doran.
 1.46  08-Dec-2000  wiz Output proper warning if dumplo == -1 (as it can happen on macppc without
swap partition), instead of "kvm_dump_mkheader: Pread: Invalid argument".
 1.45  07-Dec-2000  wiz de-__P(), and generally try to be more conforming to the new NetBSD style.
Use %m in syslog strings where appropriate.
Reduce warnings with WARNS=2.
 1.44  07-Dec-2000  wiz Fix argument handling, which was pretty broken.
If sysctl supports it, try to get the kernel name with CPU_BOOTED_KERNEL.
Get current kernels version string in all cases.
Adapt some error messages to the correct kernel name.
Reviewed by Simon Burge.
 1.43  08-Oct-2000  darrenr initialize kernel to _PATH_UNIX and remove local variables in functions
which are essentially copies of kernel.
 1.42  01-Oct-2000  darrenr savecore was looking up dumpdev, etc, from the wrong kernel
 1.41  01-Aug-2000  eeh time is a `struct timeval' not a `time_t', so read it in properly.
 1.40  02-Aug-1999  mycroft branches: 1.40.8;
s/on device/in [dirname]/, to be a bit clearer...
 1.39  01-Jul-1999  cgd Remove an extraneous fclose() call which would cause savecore to crash
if the bounds file was unwritable (e.g. because /var was read-only).
Fix supplied by Ronald Khoo in PR#7887.
 1.38  27-Feb-1999  sommerfe branches: 1.38.2;
Crash dumps should *not* be world readable.
 1.37  23-Jul-1998  sommerfe Avoid truncating partition size in freespace calculation
 1.36  01-Apr-1998  kleink Need <time.h> for time() and ctime() prototypes.
 1.35  18-Feb-1998  thorpej Avoid
 1.34  16-Sep-1997  lukem resolve conflicts from lite-2 merge
 1.33  16-Sep-1997  mrg make these compile on the alpha after WARNS=1.
 1.32  15-Sep-1997  lukem * cleanup for WARNS=1
* fix .Nm usage
* deprecate register
 1.31  25-Aug-1997  kleink Lseek(2) usage cleanup: the use of L_SET/L_INCR/L_XTND is deprecated,
use SEEK_SET/SEEK_CUR/SEEK_END instead.
 1.30  19-May-1997  pk More error checking.
 1.29  21-Apr-1997  mrg set umask for savecore.
 1.28  01-Oct-1996  cgd make datas item copied out from kernel (panicstr) and/or used as kvm pointers
(panicloc) be 'long's, not 'int's.
 1.27  23-Jun-1996  leo If kvm_dump_mkheader() returns 0, simply state 'no core dump' instead
of logging and error.
 1.26  18-Mar-1996  leo Omit kd_live argument to kvm_dump_mkheader().
 1.25  16-Mar-1996  leo New libkvm/savecore implementation. With the following differences:
1) savecore will not access the dump or live-kernel directly. It
will always use the kvm-functions. Allowing it to work on kernels
that don't have a 1-1 PA-VA mapping.
2) the kvm-lib has some additional functions to accomplish 1
- kvm_dump_mkheader()
- kvm_dump_wrtheader()
- kvm_dump_inval()
3) the file formats of the dump generated by the kernel and the dump
generated by savecore have been changed. The file format now looks
like the format produced for 'normal' core dumps.
Ports not yet supporting the new kvm-format will be using libkvm.old/
savecore.old for the time being.
 1.24  08-Mar-1996  mycroft Put the compression suffix *last*.
 1.23  24-Jul-1995  cgd set dumpsize in dump_exists(), not save_core(), so that minfree check
works again. solves pr 1257, but sets dumpsize earlier than suggested
in that pr, so that dumpsize is set if a core doesn't appear to be
present (because dumpsize would be used if the '-f' flag is given).
 1.22  25-Jun-1995  cgd fix verbose printf of dumplo, clean up printfs slightly
 1.21  18-Mar-1995  cgd convert to new RCS Id conventions; reduce my headache
 1.20  04-Jan-1995  mycroft Fix getopt string and test on return value.
 1.19  31-Oct-1994  cgd oops; get rid of previous (iffy) zopen declaration
 1.18  31-Oct-1994  cgd make a proto for zopen (yech)
 1.17  23-Sep-1994  mycroft Eliminate uses of some obsolete functions.
 1.16  18-Sep-1994  deraadt prototype zopen()
NBPG --> getpagesize()
 1.15  17-Sep-1994  mycroft vmunix --> kernel (for variable names), and make the core file naming
convention match that of other executables.
 1.14  11-Jun-1994  mycroft Fix up RCS ids.
 1.13  10-Jun-1994  pk Update to 4.4-lite, local changes to man page.
 1.12  31-May-1994  pk Initialize return value from save_core() in case dumpsize == 0.
 1.11  27-May-1994  pk Don't clear dump if writing it to the filesystem fails (eg. file system full)
 1.10  21-Apr-1994  cgd queue/struct changes
 1.9  06-Apr-1994  cgd kill two casts
 1.8  06-Apr-1994  cgd serious perversion:
most of the 'off' arguments to Lseek() (the internal lseek() wrapper)
are unsigned longs. we need them to be sign extended, though, so change
Lseek() to take a 'long' rather than an 'off_t', and let the compiler
do the dirty work via implicit casts.
 1.7  04-Apr-1994  cgd lseek stuff, and clean up. this is perverse.
 1.6  14-Feb-1994  cgd correct ok() calculation for all architectures.
 1.5  08-Dec-1993  pk Check for dumpdev being NODEV. If so, exit silently, unless verbose is on.
 1.4  01-Aug-1993  mycroft Add RCS identifiers.
 1.3  23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2  22-Mar-1993  cgd added rcs ids to all files
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3  16-Sep-1997  lukem imported from lite-2
 1.1.1.2  13-Jun-1994  mycroft Import 4.4-Lite version.
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.38.2.1  02-Jul-1999  perry pullup 1.38->1.39 (cgd)
 1.40.8.1  07-Aug-2000  mrg pull up 1.41 (approved by jhawk):
>time is a `struct timeval' not a `time_t', so read it in properly.
 1.57.2.1  23-Jul-2004  tron Apply patch (requested by dbj in ticket 1724):
Fix problems when building the netbsd-1-6 branch with GCC 3.3.3.
 1.61.2.3  14-Jul-2004  tron Pull up revision 1.64 (requested by tls in ticket #650):
Fix an integer overflow that prevented saving cores from machines with
more than 2GB of RAM.
"dumpsize" in the on-disk core header is in pages, but, unfortunately,
c.size in our kcore format is an unsigned 32-bit int, gross.
We sleaze it, using a 64-bit int internally here and handing it to
libkvm as a *signed* 32-bit int. Won't always work, but shouldn't be
broken any worse than it is now, and sometimes work better.
We must fix the kcore format and libkvm.
 1.61.2.2  14-Jul-2004  tls revert accidental commit to branch
 1.61.2.1  14-Jul-2004  tls Fix an integer overflow that prevented saving cores from machines with
more than 2GB of RAM.

"dumpsize" in the on-disk core header is in pages, but, unfortunately,
c.size in our kcore format is an unsigned 32-bit int, gross.

We sleaze it, using a 64-bit int internally here and handing it to
libkvm as a *signed* 32-bit int. Won't always work, but shouldn't be
broken any worse than it is now, and sometimes work better.

We must fix the kcore format and libkvm.
 1.65.6.2  22-Apr-2006  simonb Sync with head.
 1.65.6.1  04-Feb-2006  simonb If we have timecounters, read time_second from the kernel for the
dump time instead of time.tv.sec.
 1.70.4.2  23-Mar-2008  matt sync with HEAD
 1.70.4.1  09-Jan-2008  matt sync with HEAD
 1.71.2.1  18-Feb-2008  mjf Sync with HEAD.
 1.72.6.1  18-May-2008  yamt sync with head.
 1.72.4.3  17-Jan-2009  mjf Sync with HEAD.
 1.72.4.2  28-Sep-2008  mjf Sync with HEAD.
 1.72.4.1  02-Jun-2008  mjf Sync with HEAD.
 1.73.2.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.76.2.2  28-Nov-2009  bouyer Pull up following revision(s) (requested by dogcow in ticket #1157):
sbin/savecore/savecore.c: revision 1.81
Instead of exiting with an obscure error message if -N /kernelname isn't
specified, blithely assume the kernel will consume around 20 megs.
 1.76.2.1  24-Mar-2009  snj branches: 1.76.2.1.4;
Pull up following revision(s) (requested by tls in ticket #598):
sbin/savecore/savecore.c: revision 1.79
Fix savecore so it uses /dev/ksyms when it can (doesn't override libkvm
default). Fixes misc/38425.
 1.76.2.1.4.1  21-Apr-2010  matt sync to netbsd-5
 1.78.2.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.84.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.84.2.1  17-Apr-2012  yamt sync with head
 1.85.2.1  23-Jun-2013  tls resync from head
 1.86.28.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.86.28.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.86.28.1  10-Jun-2019  christos Sync with HEAD
 1.86.26.2  18-Jan-2019  pgoyette Synch with HEAD
 1.86.26.1  26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts

RSS XML Feed