From 9e9c1cad4c956a52a2ef4c6e69d7e687a275d200 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Sun, 31 Mar 2002 22:24:24 +0000 Subject: [PATCH] Here follows the new kernel dumping infrastructure. Caveats: The new savecore program is not complete in the sense that it emulates enough of the old savecores features to do the job, but implements none of the options yet. I would appreciate if a userland hacker could help me out getting savecore to do what we want it to do from a users point of view, compression, email-notification, space reservation etc etc. (send me email if you are interested). Currently, savecore will scan all devices marked as "swap" or "dump" in /etc/fstab _or_ any devices specified on the command-line. All architectures but i386 lack an implementation of dumpsys(), but looking at the i386 version it should be trivial for anybody familiar with the platform(s) to provide this function. Documentation is quite sparse at this time, more to come. Sponsored by: DARPA, NAI Labs Details: Dumpon now opens the device and uses ioctl(DIOCGKERNELDUMP) to set it to be the dumpdevice. When "off" is set, /dev/null is used. --- sbin/dumpon/Makefile | 2 +- sbin/dumpon/dumpon.c | 60 ++++++++++++++++++-------------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/sbin/dumpon/Makefile b/sbin/dumpon/Makefile index 5a703820812a..12fced525c5f 100644 --- a/sbin/dumpon/Makefile +++ b/sbin/dumpon/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ PROG= dumpon -WARNS= 0 +WARNS= 4 MAN= dumpon.8 .include diff --git a/sbin/dumpon/dumpon.c b/sbin/dumpon/dumpon.c index 8f93d524155c..2c4d4a459b42 100644 --- a/sbin/dumpon/dumpon.c +++ b/sbin/dumpon/dumpon.c @@ -48,11 +48,11 @@ static const char rcsid[] = #include #include #include -#include +#include +#include #include #include -#include -#include +#include #include void usage(void) __dead2; @@ -61,8 +61,8 @@ int main(int argc, char *argv[]) { int ch, verbose, rv; - struct stat stab; - int mib[2]; + int i, fd; + u_int u; verbose = rv = 0; while ((ch = getopt(argc, argv, "v")) != -1) @@ -80,41 +80,29 @@ main(int argc, char *argv[]) usage(); if (strcmp(argv[0], "off")) { - rv = stat(argv[0], &stab); - if (rv) { + fd = open(argv[0], O_RDONLY); + if (fd < 0) err(EX_OSFILE, "%s", argv[0]); - } - - if (!S_ISCHR(stab.st_mode)) { - errx(EX_USAGE, - "%s: must specify a character disk device", - argv[0]); - } + u = 0; + i = ioctl(fd, DIOCGKERNELDUMP, &u); + u = 1; + i = ioctl(fd, DIOCGKERNELDUMP, &u); + if (i == 0 && verbose) + printf("kernel dumps on %s\n", argv[0]); + } else { - stab.st_rdev = NODEV; + fd = open(_PATH_DEVNULL, O_RDONLY); + if (fd < 0) + err(EX_OSFILE, "%s", _PATH_DEVNULL); + u = 0; + i = ioctl(fd, DIOCGKERNELDUMP, &u); + if (i == 0 && verbose) + printf("kernel dumps disabled\n"); } + if (i < 0) + err(EX_OSERR, "ioctl(DIOCGKERNELDUMP)"); - mib[0] = CTL_KERN; - mib[1] = KERN_DUMPDEV; - - rv = sysctl(mib, 2, (void *)0, (size_t *)0, &stab.st_rdev, - sizeof stab.st_rdev); - if (rv) { - err(EX_OSERR, "sysctl: kern.dumpdev"); - } - - if (verbose) { - if (stab.st_rdev == NODEV) { - printf("dumpon: crash dumps disabled\n"); - } else { - printf("dumpon: crash dumps to %s (%lu, %lu)\n", - argv[0], - (unsigned long)major(stab.st_rdev), - (unsigned long)minor(stab.st_rdev)); - } - } - - return (0); + exit (0); } void