History log of /freebsd-current/sbin/savecore/savecore.c
Revision Date Author Comments
# c7bdc25d 03-Apr-2024 Yan-Hao Wang <bses30074@gmail.com>

savecore(8): Complete libxo transition

Reviewed by: des
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D41392


# 32e86a82 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

sbin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 0a5c04a8 17-Apr-2022 Mitchell Horne <mhorne@FreeBSD.org>

savecore: add an option to save a live minidump

The new '-L' flag will cause savecore to invoke the new mem(4) kernel
dump ioctl, taking a dump of the running system and writing the result
to a temporary file. Validation of the dump header is performed, similar
to regular crash dumps, and the final result is written to
livecore.X[.zst|.gz].

Also added is the '-Z' flag, which instructs the kernel to compress the
livedump compressed with zstd, akin to the existing -z flag. This option
has no effect in normal savecore(8) operation, but in theory could be
extended to perform such compression while reading the dump from the
dump device.

Encryption is unsupported for live dumps.

For example: 'savecore -Lz /var/crash' would create:
/var/crash/livecore.0.gz

Reviewed by: markj
MFC after: 2 weeks
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D34347


# cf02cf8d 17-Apr-2022 Mitchell Horne <mhorne@FreeBSD.org>

savecore: factor out info file handling

Move it to a separate function, allowing its reuse.

Reviewed by: markj
MFC after: 3 days
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D34822


# fafeb534 17-Apr-2022 Mitchell Horne <mhorne@FreeBSD.org>

savecore: decrease filename buffer sizes

All files are now created relative to savedirfd, e.g. with openat(2).
Therefore, we do not need character buffers to be PATH_MAX bytes long,
just long enough to hold the complete filename. 32 bytes is long enough
in all cases. These can be allocated on the stack.

While here, fix an error message that attempts to use an uninitialized
infoname.

Reviewed by: markj
MFC after: 3 days
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D34821


# 4243d307 17-Apr-2022 Mitchell Horne <mhorne@FreeBSD.org>

savecore: fold maxdumps check into getbounds()

So that new callers of getbounds() don't need to duplicate it.

Reviewed by: markj
MFC after: 3 days
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D34783


# 173fc6f4 05-Apr-2022 Mitchell Horne <mhorne@FreeBSD.org>

savecore: include '-u' flag in usage message

Reported by: Pau Amma <pauamma@gundo.com>
Fixes bc7ed46b635e ("Add '-u' switch that would...")
MFC after: 3 days


# ace38c58 07-Dec-2021 Kyle Evans <kevans@FreeBSD.org>

savecore: emit information about saved cores under verbose

Declare how many cores we saved, and where we saved them to. Drop a
comment about emitting little information; it's obvious from the block
in question that we emit nothing without verbose.

Reviewed by: markj
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
X-NetApp-PR: #65
Differential Revision: https://reviews.freebsd.org/D31393


# 61261ef5 11-Dec-2020 Ryan Libby <rlibby@FreeBSD.org>

savecore: bail on write error even when decompressing

Reviewed by: markj
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D27560


# bc7ed46b 18-Nov-2020 Gleb Smirnoff <glebius@FreeBSD.org>

Add '-u' switch that would uncompress cores that were compressed by
kernel during dump time.

A real life scenario is that cores are compressed to reduce
size of dumpon partition, but we either don't care about space
in the /var/crash or we have a filesystem level compression of
/var/crash. And we want cores to be uncompressed in /var/crash
because we'd like to instantily read them with kgdb. In this
case we want kernel to write cores compressed, but savecore(1)
write them uncompressed.

Reviewed by: markj, gallatin
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D27245


# 32fbec42 03-Nov-2020 Gleb Smirnoff <glebius@FreeBSD.org>

Style, not functional changes:
- Improve spelling of a false check [1]
- A missing line from r367150.

Submitted by: kib


# 0de93324 29-Oct-2020 Gleb Smirnoff <glebius@FreeBSD.org>

Convert flags from int to bool. Some (compress) were already used in
comparisons with bool values. No functional changes.


# 81884a24 29-Jun-2020 Alan Somers <asomers@FreeBSD.org>

savecore: accept device names without the /dev/ prefix

dumpon has accepted device names without the prefix ever since r291207.
Since dumpon and savecore are always paired, they ought to accept the same
arguments. Prior to this change, specifying 'dumpdev="da3"' in
/etc/rc.conf, for example, would result in dumpon working just fine but
savecore complaining that "Dump device does not exist".

PR: 247618
Reviewed by: cem, bcr
MFC after: 2 weeks
Sponsored by: Axcient
Differential Revision: https://reviews.freebsd.org/D25500


# a532f299 13-Jan-2020 Eric van Gyzen <vangyzen@FreeBSD.org>

savecore: include time zone in info.N file

This helps with event correlation when machines are distributed
across multiple time zones.

Format the time with relaxed ISO 8601 for all the usual reasons.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon


# d76eef34 17-Apr-2019 Ed Maste <emaste@FreeBSD.org>

cap_fileargs: chase r346315, update fileargs_init in consumers

Reported by: ci.freebsd.org (8 times so far)
MFC after: 3 weeks
MFC with: r346315
Sponsored by: The FreeBSD Foundation


# 2e4c75c1 02-Jan-2019 Mark Johnston <markj@FreeBSD.org>

Fix an error check after r342699.

Reported by: gcc
MFC with: r342699
Sponsored by: The FreeBSD Foundation


# d7fffd06 02-Jan-2019 Mark Johnston <markj@FreeBSD.org>

Capsicumize savecore(8).

- Use cap_fileargs(3) to open dump devices after entering capability
mode, and use cap_syslog(3) to log messages.
- Use a relative directory fd to open output files.
- Use zdopen(3) to compress kernel dumps in capability mode.

Reviewed by: cem, oshogbo
MFC after: 2 months
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D18458


# fe1ba250 29-May-2018 Mark Johnston <markj@FreeBSD.org>

The extension for zstd-compressed files is ".zst".

Reported by: manu


# b761400b 15-Feb-2018 Mike Silbersack <silby@FreeBSD.org>

Prevent savecore from reading bounds from the current directory.

Rev 244218 removed the requirement that you provide a dump
directory when checking if there is a coredump ready to be written.
That had the side-effect of causing the bounds file to be read
from the current working directory instead of the dump directory.
As the bounds file is irrelevant when just checking, the simplest
fix is to not read the bounds file when checking.

Reviewed by: markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D14383


# 6026dcd7 13-Feb-2018 Mark Johnston <markj@FreeBSD.org>

Add support for zstd-compressed user and kernel core dumps.

This works similarly to the existing gzip compression support, but
zstd is typically faster and gives better compression ratios.

Support for this functionality must be configured by adding ZSTDIO to
one's kernel configuration file. dumpon(8)'s new -Z option is used to
configure zstd compression for kernel dumps. savecore(8) now recognizes
and saves zstd-compressed kernel dumps with a .zst extension.

Submitted by: cem (original version)
Relnotes: yes
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D13101,
https://reviews.freebsd.org/D13633


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# 64a16434 24-Oct-2017 Mark Johnston <markj@FreeBSD.org>

Add support for compressed kernel dumps.

When using a kernel built with the GZIO config option, dumpon -z can be
used to configure gzip compression using the in-kernel copy of zlib.
This is useful on systems with large amounts of RAM, which require a
correspondingly large dump device. Recovery of compressed dumps is also
faster since fewer bytes need to be copied from the dump device.

Because we have no way of knowing the final size of a compressed dump
until it is written, the kernel will always attempt to dump when
compression is configured, regardless of the dump device size. If the
dump is aborted because we run out of space, an error is reported on
the console.

savecore(8) is modified to handle compressed dumps and save them to
vmcore.<index>.gz, as it does when given the -z option.

A new rc.conf variable, dumpon_flags, is added. Its value is added to
the boot-time dumpon(8) invocation that occurs when a dump device is
configured in rc.conf.

Reviewed by: cem (earlier version)
Discussed with: def, rgrimes
Relnotes: yes
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D11723


# cf8eb490 24-Jul-2017 Mark Johnston <markj@FreeBSD.org>

Fix style and wrap lines to 80 columns in savecore.c.

No functional change intended.

MFC after: 3 days


# ab384d75 15-Jul-2017 Mark Johnston <markj@FreeBSD.org>

Revert r320918 and have mkdumpheader() handle version string truncation.

Reported by: jhb
MFC after: 1 week


# 5aaf7667 12-Jul-2017 Mark Johnston <markj@FreeBSD.org>

Add a newline after the version string.

MFC after: 3 days


# 4e287bd8 11-Jul-2017 Mark Johnston <markj@FreeBSD.org>

Add a subroutine for comparing kerneldump identifiers.

MFC after: 2 weeks


# 6f11c9ca 15-Apr-2017 Enji Cooper <ngie@FreeBSD.org>

Switch back to non-IEC units for 1024 bytes

I was swayed a little too quickly when I saw the wiki page discussing
kB vs KiB. Switch back as none of the code in base openly uses
IEC units via humanize_number(3) (which was my next step), and there's
a large degree of dislike with IEC vs more SI-like units.

MFC after: 7 weeks
Submitted by: jhb, rgrimes
Sponsored by: Dell EMC Isilon


# f09cb4f2 14-Apr-2017 Enji Cooper <ngie@FreeBSD.org>

savecore: fix space calculation with respect to `minfree` in check_space(..)

- Use strtoll(3) instead of atoi(3), because atoi(3) limits the
representable data to INT_MAX. Check the values received from
strtoll(3), trimming trailing whitespace off the end to maintain
POLA.
- Use `KiB` instead of `kB` when describing free space, total space,
etc. I am now fully aware of `KiB` being the IEC standard for 1024
bytes and `kB` being the IEC standard for 1000 bytes.
- Store available number of KiB in `available` so it can be more
easily queried and compared to ensure that there are enough KiB to
store the dump image on disk.
- Print out the reserved space on disk, per `minfree`, so end-users
can troubleshoot why check_space(..) is reporting that there isn't
enough free space.

MFC after: 7 weeks
Reviewed by: Anton Rang <rang@acm.com> (earlier diff), cem (earlier diff)
Tested with: positive/negative cases (see review); make tinderbox
Sponsored by: Dell EMC Isilon
Differential Revision: D10379


# 397b5714 12-Apr-2017 Enji Cooper <ngie@FreeBSD.org>

Clarify units for mediasize and sectorsize in DoFile(..)

They're byte quantities.

MFC after: 7 weeks
Sponsored by: Dell EMC Isilon


# e1f7a5d6 12-Apr-2017 Enji Cooper <ngie@FreeBSD.org>

Clarify `minfree` warning message in check_space(..)

- State that the units are kB.
- Be more complete/concise in terms of what is required (in this case
`minfree` must be at least `X`kB)

MFC after: 7 weeks
Sponsored by: Dell EMC Isilon


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 6f03f3d8 19-Feb-2017 Edward Tomasz Napierala <trasz@FreeBSD.org>

Make savecore(8) output nicer by specifying the maximum field width
instead of minimum one (precision instead of width).

MFC after: 2 weeks
Sponsored by: DARPA, AFRL


# 3c7ccf15 04-Feb-2017 Konrad Witaszczyk <def@FreeBSD.org>

Fix bugs found by Coverity in decryptcore(8) and savecore(8):
- Perform final decryption and write decrypted data in case of non-block aligned
input data;
- Use strlcpy(3) instead of strncpy(3) to verify if paths aren't too long;
- Check errno after calling unlink(2) instead of calling stat(2) in order to
verify if a decrypted core was created by a child process;
- Free dumpkey.

Reported by: Coverity, cem, pfg
Suggested by: cem
CID: 1366936, 1366942, 1366951, 1366952
Approved by: pjd (mentor)


# 480f31c2 10-Dec-2016 Konrad Witaszczyk <def@FreeBSD.org>

Add support for encrypted kernel crash dumps.

Changes include modifications in kernel crash dump routines, dumpon(8) and
savecore(8). A new tool called decryptcore(8) was added.

A new DIOCSKERNELDUMP I/O control was added to send a kernel crash dump
configuration in the diocskerneldump_arg structure to the kernel.
The old DIOCSKERNELDUMP I/O control was renamed to DIOCSKERNELDUMP_FREEBSD11 for
backward ABI compatibility.

dumpon(8) generates an one-time random symmetric key and encrypts it using
an RSA public key in capability mode. Currently only AES-256-CBC is supported
but EKCD was designed to implement support for other algorithms in the future.
The public key is chosen using the -k flag. The dumpon rc(8) script can do this
automatically during startup using the dumppubkey rc.conf(5) variable. Once the
keys are calculated dumpon sends them to the kernel via DIOCSKERNELDUMP I/O
control.

When the kernel receives the DIOCSKERNELDUMP I/O control it generates a random
IV and sets up the key schedule for the specified algorithm. Each time the
kernel tries to write a crash dump to the dump device, the IV is replaced by
a SHA-256 hash of the previous value. This is intended to make a possible
differential cryptanalysis harder since it is possible to write multiple crash
dumps without reboot by repeating the following commands:
# sysctl debug.kdb.enter=1
db> call doadump(0)
db> continue
# savecore

A kernel dump key consists of an algorithm identifier, an IV and an encrypted
symmetric key. The kernel dump key size is included in a kernel dump header.
The size is an unsigned 32-bit integer and it is aligned to a block size.
The header structure has 512 bytes to match the block size so it was required to
make a panic string 4 bytes shorter to add a new field to the header structure.
If the kernel dump key size in the header is nonzero it is assumed that the
kernel dump key is placed after the first header on the dump device and the core
dump is encrypted.

Separate functions were implemented to write the kernel dump header and the
kernel dump key as they need to be unencrypted. The dump_write function encrypts
data if the kernel was compiled with the EKCD option. Encrypted kernel textdumps
are not supported due to the way they are constructed which makes it impossible
to use the CBC mode for encryption. It should be also noted that textdumps don't
contain sensitive data by design as a user decides what information should be
dumped.

savecore(8) writes the kernel dump key to a key.# file if its size in the header
is nonzero. # is the number of the current core dump.

decryptcore(8) decrypts the core dump using a private RSA key and the kernel
dump key. This is performed by a child process in capability mode.
If the decryption was not successful the parent process removes a partially
decrypted core dump.

Description on how to encrypt crash dumps was added to the decryptcore(8),
dumpon(8), rc.conf(5) and savecore(8) manual pages.

EKCD was tested on amd64 using bhyve and i386, mipsel and sparc64 using QEMU.
The feature still has to be tested on arm and arm64 as it wasn't possible to run
FreeBSD due to the problems with QEMU emulation and lack of hardware.

Designed by: def, pjd
Reviewed by: cem, oshogbo, pjd
Partial review: delphij, emaste, jhb, kib
Approved by: pjd (mentor)
Differential Revision: https://reviews.freebsd.org/D4712


# 8df55592 05-Oct-2016 Conrad Meyer <cem@FreeBSD.org>

savecore(8): Fix buffer overrun inspecting disks with varying sector size

A premature optimization lead to caching a native-sector sized memory
allocation. If the program examined a 512 byte sector disk, then a 4096
byte sector disk, the program would overrun the cached 512 byte buffer.

Just remove the optimization to fix the bug. This was introduced with the 4Kn
dump support in r298076.

Reported by: markj
Reviewed by: markj, rpokala
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D8162


# 3ae587fd 19-Apr-2016 Enji Cooper <ngie@FreeBSD.org>

Don't leak fd on sectorsize malloc failure

Also, call endfsent after calling getfsent (i.e. when not explicitly called
with a swap device) for code cleanliness

CID: 1354785
Differential Revision: https://reviews.freebsd.org/D6014
X-MFC with: r298076
Reported by: Coverity
Reviewed by: cem
Sponsored by: EMC / Isilon Storage Division


# fca84076 15-Apr-2016 Conrad Meyer <cem@FreeBSD.org>

savecore(8): Explicitly cast to fix i386 warning


# 5dc5dab6 15-Apr-2016 Conrad Meyer <cem@FreeBSD.org>

Add 4Kn kernel dump support

(And 4Kn minidump support, but only for amd64.)

Make sure all I/O to the dump device is of the native sector size. To
that end, we keep a native sector sized buffer associated with dump
devices (di->blockbuf) and use it to pad smaller objects as needed (e.g.
kerneldumpheader).

Add dump_write_pad() as a convenience API to dump smaller objects with
zero padding. (Rather than pull in NPM leftpad, we wrote our own.)

Savecore(1) has been updated to deal with these dumps. The format for
512-byte sector dumps should remain backwards compatible.

Minidumps for other architectures are left as an exercise for the
reader.

PR: 194279
Submitted by: ambrisko@
Reviewed by: cem (earlier version), rpokala
Tested by: rpokala (4Kn/512 except 512 fulldump), cem (512 fulldump)
Relnotes: yes
Sponsored by: EMC / Isilon Storage Division
Differential Revision: https://reviews.freebsd.org/D5848


# fc6f845e 07-Nov-2015 Conrad Meyer <cem@FreeBSD.org>

savecore(8): Be quiet unless the user asks for verbose

Make savecore(8) more suitable for init-time scripts; be quiet by default.

Sponsored by: EMC / Isilon Storage Division
Differential Revision: https://reviews.freebsd.org/D3229


# 49f1692b 06-Nov-2015 Alan Somers <asomers@FreeBSD.org>

Always check the return value of lseek.

This is a follow-up to r289845, which only fixed one occurence of CID
1009429.

Coverity CID: 1009429
Reviewed by: markj
MFC after: 2 weeks
X-MFC-With: r289845
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D4096


# 6123d3f6 23-Oct-2015 Alan Somers <asomers@FreeBSD.org>

Fix various Coverity issues in sbin/savecore/savecore.c:

CID1009429: Fix unchecked return value from lseek while clearing dump
CID1007781: Fix file descriptor leak in DoFile
CID1007261: Don't send potentially unterminated string to syslog(3)

Coverity CID: 1009429
Coverity CID: 1007781
Coverity CID: 1007261
MFC after: 2 weeks
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D3991


# d16528b2 22-Mar-2015 Scott Long <scottl@FreeBSD.org>

Convert savecore to libxo. The 'verbose' paths still use printf since they're
meant for interactivity on the command line and contain a lot of redundant
information.

Obtained from: Netflix, Inc.


# 5e93a4b4 17-Sep-2014 Bryan Drewery <bdrewery@FreeBSD.org>

If fgets(3) fails in getbounds(), show strerror(3) if not an EOF. Also fix
a FILE* leak in getbounds().

Submitted by: Conrad Meyer <conrad.meyer@isilon.com>
PR: 192032
Sponsored by: EMC / Isilon Storage Division
MFC after: 1 week


# 27e21758 14-Apr-2014 Christian Brueffer <brueffer@FreeBSD.org>

Fix double fclose() in an error case.

CID: 1006120
Found with: Coverity Prevent(tm)
MFC after: 1 week


# 776f03d2 04-Mar-2014 Mark Johnston <markj@FreeBSD.org>

Log the name of the device that we failed to open rather than an
uninitialized buffer.

MFC after: 3 days


# 165557e2 16-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

With rotating kernel dumps the higest dump number is not necessarily the
last one. To make it easier to find the last one create symlinks with 'last'
suffix that will point to the files of the last coredump, eg.:

info.last -> info.5
textdump.tar.last.gz -> textdump.tar.5.gz

Reviewed by: avg
Obtained from: WHEEL Systems


# eeff0b1b 16-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Implement -m option to savecore(8) that allows to limit number of kernel
dumps stored. Once the limit is reached it restarts from 0.

Reviewed by: avg
Obtained from: WHEEL Systems


# 30f6c389 16-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Make use of the fact that we changed working directory to the dump directory
earlier.

Obtained from: WHEEL Systems


# 3a6e0feb 16-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Sort flags properly.

Obtained from: WHEEL Systems


# 87c3930b 16-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Prefer snprintf() over sprintf().

Obtained from: WHEEL Systems


# 349d039b 14-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

- When checking if a dump exists on the given device there is no need to
provide dump directory. Eliminate this redundant argument. This changes
the usage, but the only risk here is that a warning will be printed
about directory given as device.

- Update usage of -C option.

- When clearing dump header from the given device there is also no need to
provide dump directory, although additional arguments for -c were not
documented.

- Document that -v can be used with -c and that list of devices can be given.

Obtained from: WHEEL Systems


# 22374de9 14-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

The clear option (-c) is not compatible with keep (-k) and compress (-z)
options.

Obtained from: WHEEL Systems


# 41060469 14-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

If we are not going to clear the dump (we are either just checking if the dump
exists or we want to keep it), open device read-only.

Obtained from: WHEEL Systems


# 26ef9e4a 14-Dec-2012 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Whitespace cleanups.


# 45385614 09-Apr-2012 Robert Millan <rmh@FreeBSD.org>

Include <signal.h> (for SIGINFO).


# ecd9e552 24-Jun-2011 Kevin Lo <kevlo@FreeBSD.org>

Remove duplicated header files


# f041f6a7 12-Dec-2010 Joel Dahl <joel@FreeBSD.org>

Remove the advertising clause from UCB copyrighted files in sbin. This
is in accordance with the information at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 0d239eef 25-Aug-2009 Ulf Lilleengen <lulf@FreeBSD.org>

- Add a SIGINFO handler for savecore.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# df0b82f1 27-Dec-2007 Robert Watson <rwatson@FreeBSD.org>

Compare kernel dump header magic with textdump magic using strncmp()
rather than the memcmp() which is used for regular dumps: the
textdump string is one character shorter, so we need to stop
comparing at the end of the string.

Use independent version checking logic for architecture-specific
version number vs. textdump version number, as the version sequences
may (someday) differ.

Run into by: rrs


# 10187cae 26-Dec-2007 Robert Watson <rwatson@FreeBSD.org>

Teach savecore(8) how to extract textdump(4) dumps.

Update savecore(8) man page to reflect textdump additions.

MFC after: 3 months


# 76f23bd5 28-May-2007 Kevin Lo <kevlo@FreeBSD.org>

Check fdopen return value.

Reviewed by: phk


# 125450bb 02-Oct-2005 Maxim Konovalov <maxim@FreeBSD.org>

o Restore kerneldumpheader.architectureversion bytes swopping
mangled in rev. 1.72.

PR: bin/86805
Submitted by: Gavin Atkinson
MFC after: 3 days


# d32e7ba7 13-Sep-2005 Robert Watson <rwatson@FreeBSD.org>

Don't consider being unable to open the bounds file worthy of printing
at LOG_WARNING by default; instead, consider it something to be printed
to the tty when 'verbose' mode is set. This avoids printing out extra
lines at every boot on a system with crash dumps enabled, but that has
not yet had to generate a crashdump.

MFC after: 1 week


# 9520784e 20-Jun-2005 Doug White <dwhite@FreeBSD.org>

Don't bump bounds every time savecore(8) is run.

Submitted by: Ed Maste <emaste@sandvine.com>
Approved by: re


# 466e103c 29-May-2005 Xin LI <delphij@FreeBSD.org>

Constify savedir pointer, and remove an accompaning strdup() call.


# ecb90dcc 25-Feb-2005 David E. O'Brien <obrien@FreeBSD.org>

style(9).


# 5fb7027c 23-Feb-2005 David E. O'Brien <obrien@FreeBSD.org>

Allow a forced dump even if the dump header information is inconsistent.
Output more verbosity with additional -v's.

Submitted by: seanc


# 8d646af5 10-Feb-2005 Ruslan Ermilov <ru@FreeBSD.org>

Sync program's usage() with manpage's SYNOPSIS.


# e80cfa46 10-Jan-2005 Xin LI <delphij@FreeBSD.org>

Initialize "he" in DoFile, so savecore(8) is WARNS=6 clean.
Bump WARNS accordingly.


# 9f676d2e 16-Aug-2004 Ruslan Ermilov <ru@FreeBSD.org>

Use a local "compress" symbol corresponding to a variable in BSS,
rather than the one from libz, corresponding to a function, when
linking statically.

PR: bin/70392


# 34ee70a6 28-Feb-2004 Maxim Konovalov <maxim@FreeBSD.org>

o Remove obsoleted '-N' and '-d' flags.


# 1e581b97 28-Feb-2004 Maxim Konovalov <maxim@FreeBSD.org>

o Sync usage() with reality: add 'z' flag.

MFC after: 1 week


# 65922d0b 19-Feb-2004 Tim J. Robbins <tjr@FreeBSD.org>

Merge from RELENG_4 1.28.2.13: Fix saving system crash dumps larger than
2 GB by using fseeko() instead of fseek().


# 4b290df1 08-Oct-2003 Marcel Moolenaar <marcel@FreeBSD.org>

Revision 1.61 changed the allocation of buffer 'buf' in DoFile() from
the stack to the heap to work around a problem on ia64. Now, roughly
16 months and two compiler updates later, it isn't an issue anymore
in the sense that putting a 1M buffer on the stack just works and we
don't actually need to work around anything anymore.
However, since there's no advantage or need to put the buffer on the
stack (again), this change merely removes the XXX comment describing
that there's an explicit reason for the heap allocation. Hence, this
change is a functional no-op.

PR: ia64/38677


# 628d16a3 04-Sep-2003 Doug Barton <dougb@FreeBSD.org>

Add a flag that reports the existence of a dump, and does nothing else.

The immediate purpose for this option is to use it in rc.d so that we
can make savecore behavior conditional.

Tremendous assistance with ideas and sanity checking provided by tjr
and b@etek.chalmers.se.


# 9d5abbdd 01-Jan-2003 Jens Schweikhardt <schweikh@FreeBSD.org>

Correct typos, mostly s/ a / an / where appropriate. Some whitespace cleanup,
especially in troff files.


# acc66230 02-Jun-2002 Marcel Moolenaar <marcel@FreeBSD.org>

Fix breakage caused by allocating the I/O buffer. There was a
sizeof(buf) lurking around that I missed.

PR: 38811
Submitted by: Adrian Colley <aecolley@spamcop.net>


# 6db5f8a7 27-May-2002 Marcel Moolenaar <marcel@FreeBSD.org>

Work around a memory fault on ia64 caused by having the 1MB buffer on
the stack in DoFile(). This needs some investigation. In the mean time
we do a one time malloc() for the buffer to have it on the heap instead.


# fac09f6b 06-May-2002 Marcel Moolenaar <marcel@FreeBSD.org>

Make argument to printf match format.


# edc4f96e 04-May-2002 Bill Fenner <fenner@FreeBSD.org>

- revert back to vmcore.#
- reimplement -z
- use syslog()
- improve consistancy of messages
- allow -f to recover cleared dumps
- return bufsize to 1024 * 1024
- return the ability to write sparse files
- update man page
- fix minfree to require 2k for info file instead of the kernel size
- include Berkeley copyright too due to amount of old code copied

Submitted by: Chad David <davidc@acns.ab.ca>


# 3203428d 04-May-2002 Maxime Henrion <mux@FreeBSD.org>

Restore the minfree functionality into savecore. This patch
restores the check_space() function with small modifications
to make it work with the current code. The patch was slightly
modified by Bill Fenner to handle error messages better.

Reviewed by: fenner


# 4b8b6734 21-Apr-2002 Philippe Charnier <charnier@FreeBSD.org>

Add FBSDID. Start errx(3) messages with lowercase. Remove a ')' with no '('.
In usage(), use fprintf(3) instead of errx(3), to make the printed string really
start with `usage: ...'.
Reviewed by: marcel


# dce9aaab 19-Apr-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Push the .info file contents out when we're done so people can
read the description while the megs shift from one place to another.


# 5da217f6 13-Apr-2002 Marcel Moolenaar <marcel@FreeBSD.org>

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.


# 2dd527b3 08-Apr-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Move generic disk ioctls from <sys/disklabel.h> to <sys/disk.h>.

Sponsored by: DARPA & NAI Labs


# 5cb87b0c 03-Apr-2002 Marcel Moolenaar <marcel@FreeBSD.org>

Make the kernel dump header endianness invariant by always dumping
in dump byte order (=network byte order). Swap blocksize and dumptime
to avoid extraneous padding on 64-bit architectures. Use CTASSERT
instead of runtime checks to make sure the header is 512 bytes large.
Various style(9) fixes.

Reviewed by: phk, bde, mike


# 3837db64 01-Apr-2002 John Baldwin <jhb@FreeBSD.org>

Add long long casts so that this compiles on archs with 64-bit longs.

Pointy-hat to: phk


# d503fad0 31-Mar-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Savecore:

Commandline compatible with the previous savecore unless you specify
any options, none of them are implemented (yet).

Scans all devices marked "dump" or "swap" for dump header signatures
and saves dumps off under a name which is a MD5 hash of the header
information. This should give unique filenames. A *.info file contains
ascii version of the header information.


# d476a036 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

o remove __P
o remove main prototype


# 3d438ad6 20-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Remove 'register' keyword.
It does not help modern compilers, and some may take some hit from it.
(I also found several functions that listed *every* of its 10 local vars with
"register" -- just how many free registers do people think machines have?)


# 66a79b3d 11-Mar-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Sparc64 support.


# 9ee15327 04-Oct-2001 Peter Wemm <peter@FreeBSD.org>

Remove some bogus "(off_t)(dumplo + value)" and "(off_t)dumplo" casts,
since dumplo is now an off_t. Scratch a couple of other itches as well.
s/L_SET/SEEK_SET/


# 1ade1386 04-Oct-2001 Peter Wemm <peter@FreeBSD.org>

Argh. Fix another >2GB savecore problem.

Reported by: mki@mozone.net


# c97e08fb 13-Sep-2001 Andrew Gallatin <gallatin@FreeBSD.org>

fix savecore so that it works on the alpha after the size change
of dumpmag from an int to a u_long in rev 1.41 -- without this
change, savecore will always fail like this:

#savecore -v /var/crash
dumplo = 874356736 (1707728 * 512)
savecore: magic number mismatch (8fca0101 != 8fca0101)
savecore: no core dump


# dff462c3 06-Sep-2001 Kris Kennaway <kris@FreeBSD.org>

* Switch from doing compress(1)ed crashdumps with the -z flag to using
gzip(1). gdb doesn't understand these, but then again it didn't
understand compressed crashdumps either.
* Change a stray lseek() into a Lseek()
* Remove the extraneous prototype for log() which has apparently never
existed in FreeBSD's sources

Obtained from: NetBSD (partially)
MFC after: 2 weeks


# 241ca228 24-Aug-2001 Peter Wemm <peter@FreeBSD.org>

Banish hard-coded KERNBASE references from savecore. Dynamically
adjust to whatever kernbase is in the kernel that we are dumping.


# 5979df34 19-Aug-2001 Kris Kennaway <kris@FreeBSD.org>

Silence non-constant format string warnings by marking functions
as __printflike()/__printf0like(), adding const, or adding missing "%s"
format strings, as appropriate.

MFC after: 2 weeks


# 9b0a8ba3 08-Jun-2001 Peter Wemm <peter@FreeBSD.org>

dumpmag is 'u_long dumpmag' in the kernel, not 'int'. If this worked on
the Alpha, it was because of luck that it was little endian.

Tidy up the dumpsize/dumppages confusion and the out of date comments.


# 1c08773e 07-Jun-2001 Peter Wemm <peter@FreeBSD.org>

'int dumpsize; /* memory size in bytes */' is not good for machines
with 2GB or more of ram.


# 867dd038 05-Mar-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Restore the -c option, which was accidentally removed from the getopt
string two revisions ago.


# 4c98f36d 16-Feb-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Document the new -k option in usage message and man page.


# 532c1901 16-Feb-2001 Dag-Erling Smørgrav <des@FreeBSD.org>

Add a -k option that prevents clearing the dump after saving it.

Use sysctlbyname() instead of sysctl().

Clear up and simplify the version extraction code.

Attempt to detect stretches of zeroes in the dump and avoid writing
them to disk to save space and time.


# c74e16f9 17-Oct-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

Work much harder at obtaining a correct device node. If what devname(3)
returns doesn't exist, or doesn't match the desired device, fall back to
scanning /dev for a matching node, and as a last resort, if that fails,
try to create the node ourselves as /dev/dump.

Add comments to several variables and functions.

Clean up syslog(3) usage; use %m instead of strerror(3).

Other minor cleanup.


# c548151f 28-Sep-2000 Dag-Erling Smørgrav <des@FreeBSD.org>

Remove superfluous code:

1) use devname() instead of searching /dev for the dump device

2) use fopen() instead of open() so we don't need to differentiate
between compressing and not compressing when writing the core
file or the kernel (zopen() returns a FILE *, so we just use
fwrite() in both cases)

There should be no functional changes.


# 7365d61d 03-Sep-2000 Peter Wemm <peter@FreeBSD.org>

I'm not sure what changed to cause this, but using 'dirname' as a variable
was colliding with dirname() in libc.a and causing a Sig 10/bus error.
Just change dirname to savedir and be done with it.


# e0ab5cb5 09-May-2000 Paul Saab <ps@FreeBSD.org>

Tidy up the offset calculations.

Submitted by: bde


# 8df53a80 08-May-2000 Paul Saab <ps@FreeBSD.org>

Read the correct size into kdumplo.

Botched/Noticed by: peter


# 332dbf57 08-May-2000 Paul Saab <ps@FreeBSD.org>

Allow savecore to work on > 2GB partitions.

Submitted by: peter


# e9ae1d4b 20-Mar-2000 Bruce Evans <bde@FreeBSD.org>

Fixed style bugs in rev.1.28. Rev.1.28 was not submitted by bde.


# 2837fe55 19-Mar-2000 Paul Saab <ps@FreeBSD.org>

Only character devices exsist these days. Make savecore understand
this.


# 7c815b0d 21-Dec-1999 David E. O'Brien <obrien@FreeBSD.org>

Fix bogus initialization of using a sledge hammer to quite -Wall, bad
indention, and size issue between 32 and 64bit machines.

Submitted by: bde


# 3eb8166f 07-Dec-1999 David E. O'Brien <obrien@FreeBSD.org>

When erroring out that there is not enough space to write the corefile,
tell the user how much space is avaible for writing the corefile, and how
much space we wanted.


# 4805de87 29-Nov-1999 Andrey A. Chernov <ache@FreeBSD.org>

Allow character devices too


# c43f30e1 31-Aug-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Fix savecore so that it operates correctly on character devices with
sectorsizes up to 8k.

Pointed out by: sos


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 93fcd374 12-May-1999 Luoqi Chen <luoqi@FreeBSD.org>

Read dumpdev using sysctl(3) interface. Now savecore should work again
after the dev_t changes.


# e22d0006 12-Mar-1999 Andrew Gallatin <gallatin@FreeBSD.org>

Fix savecore so that it works on alphas
Reviewed by: Doug Rabson <dfr@nlsystems.com>


# f9b52c93 28-Jul-1998 Philippe Charnier <charnier@FreeBSD.org>

Correct use of .Nm, add rcsid, remove unused #include.


# 836b4a7f 28-Jun-1998 Bruce Evans <bde@FreeBSD.org>

Fixed printf format errors.


# 90455566 30-Mar-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Pickup _time_second instead of _time


# 25e43cba 01-Jul-1997 Bruce Evans <bde@FreeBSD.org>

Import Lite2's src/sbin, except for XNSrouted and routed. All relevant
files in src/sbin are off the vendor branch, so this doesn't change the
active versions.


# 8d64695c 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 8df9b2ce 14-Oct-1996 Joerg Wunsch <joerg@FreeBSD.org>

Fix my yesterday's brain-o: don't account for the kilobytes twice.


# 927e7941 13-Oct-1996 Joerg Wunsch <joerg@FreeBSD.org>

Yikes! Originally, i intended to apply the patch from PR # 1322,
but Bill has beaten me on this. ;-)

However, he missed the part to compute the kernelsize in kilobytes,
so the minfree consideration was now overcautious. (I've also
changed the return type of dump_size() to void since int was useless.)

Being here, the fact that `vmcore' was written world-readable was just
a plain security hole: everybody who was able to crash a kernel could
later read any confidential information out of it at his will. Create
it with umask 077 instead.


# 4731e263 13-Oct-1996 Bill Fenner <fenner@FreeBSD.org>

Make the savecore command work like the man page says:
- make minfree work by getting the dump size before checking to see
if the dump will fit on the filesystem
- also fail to dump if no minfree is specified but there are not enough
free blocks.

Fix a typo in the man page.

Fixes PR bin/1322

Submitted by: "Philippe C." <charnier@lirmm.fr>


# 0bade8bd 05-Sep-1996 David Greenman <dg@FreeBSD.org>

Cast the partial result of an expression to an off_t to fix an overflow
in the calculation of free disk space. Fixes PR#1569.

Submitted by: Tor Egge <Tor.Egge@idt.ntnu.no>


# 6127186d 20-Aug-1996 Wolfram Schneider <wosch@FreeBSD.org>

a header file for zopen.3

Pointed out by: Philippe Charnier <charnier@lirmm.fr>


# a8b878b7 02-May-1996 Poul-Henning Kamp <phk@FreeBSD.org>

NBPG -> getpagesize()


# 65219883 13-Dec-1995 Peter Wemm <peter@FreeBSD.org>

Add #include <vm/pmap.h> in order to make savecore compile again after the
last round of <vm/*.h> include file changes.


# 656dcd43 07-Aug-1995 Garrett Wollman <wollman@FreeBSD.org>

Delete bogus referneces to timezone code internal header file `tzfile.h',
which is no longer bogusly installed in /usr/include.


# 5eae614b 30-Jul-1995 Joerg Wunsch <joerg@FreeBSD.org>

Remove a newline from the output of savecore(8), so the bogus number
1024 that used to remain on a line of its own after savecore completed
its job will be overwritten later in the /etc/rc process.

Reviewed by:
Submitted by: graichen@sirius.physik.fu-berlin.de (Thomas Graichen)
Obtained from:


# 50e2fb80 11-Jul-1995 Bruce Evans <bde@FreeBSD.org>

Remove a bogus fclose. Normally the "w" stream for /var/crash/bounds was
fclosed twice and this didn't seem to cause any problems, but when
/var/crash was on an an unwritable nfs-mounted partition, fclose(NULL)
caused a core dump.


# 5ebc7e62 30-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# 08e9e074 01-Jan-1995 Joerg Wunsch <joerg@FreeBSD.org>

The -N option takes one argument, hence the getopt control string
needs to have a colon for it. Looks like nobody has tested this
so far.


# 4be4929c 23-Sep-1994 Garrett Wollman <wollman@FreeBSD.org>

Get rid of _PATH_UNIX completely; use getbootfile(3) instead.

DANGER WILL ROBINSON!
_PATH_UNIX is currently defined as the literal string "don't use this".
I am of two minds about this myself, but wanted to get something into the
tree as quickly as possible.


# b3bfc719 05-Aug-1994 David Greenman <dg@FreeBSD.org>

Converted 'vmunix' to 'kernel'.


# 9f5cdc15 28-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

I know better than to edit files on freefall, next time take a patch file.
Change vm_paramh. to vm_param.h


# c33d4167 27-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

Must now include vm/vm.h and vm/vm_param.h due to the way we define KERNBASE.
Reviewed by: David Greenman


# 8fae3551 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite sbin Sources

Note: XNSrouted and routed NOT imported here, they shall be imported with
usr.sbin.