From f6848434fe9620d2dd89260ea4df0e2a7470eee7 Mon Sep 17 00:00:00 2001 From: Alfred Perlstein Date: Thu, 1 Nov 2012 18:59:19 +0000 Subject: [PATCH] Add an option to display the current dump device via dumpon -l. MFC after: 2 weeks --- sbin/dumpon/dumpon.8 | 9 +++++++++ sbin/dumpon/dumpon.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/sbin/dumpon/dumpon.8 b/sbin/dumpon/dumpon.8 index ff47bcb19479..e60d5f8770c6 100644 --- a/sbin/dumpon/dumpon.8 +++ b/sbin/dumpon/dumpon.8 @@ -41,6 +41,8 @@ .Nm .Op Fl v .Cm off +.Nm +.Fl l .Sh DESCRIPTION The .Nm @@ -72,6 +74,13 @@ total amount of physical memory as reported by the variable. .Pp The +.Fl l +flag causes +.Nm +to print the current dump device or _PATH_DEVNULL ("/dev/null") if no device is +configured. +.Pp +The .Fl v flag causes .Nm diff --git a/sbin/dumpon/dumpon.c b/sbin/dumpon/dumpon.c index 73d46b00eb3c..ac73399d0540 100644 --- a/sbin/dumpon/dumpon.c +++ b/sbin/dumpon/dumpon.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -60,9 +61,10 @@ static int verbose; static void usage(void) { - fprintf(stderr, "%s\n%s\n", + fprintf(stderr, "%s\n%s\n%s\n", "usage: dumpon [-v] special_file", - " dumpon [-v] off"); + " dumpon [-v] off", + " dumpon -l"); exit(EX_USAGE); } @@ -92,15 +94,45 @@ check_size(int fd, const char *fn) } } +static void +listdumpdev(void) +{ + char dumpdev[PATH_MAX]; + size_t len; + const char *sysctlname = "kern.shutdown.dumpdevname"; + + len = sizeof(dumpdev); + if (sysctlbyname(sysctlname, &dumpdev, &len, NULL, 0) != 0) { + if (errno == ENOMEM) { + err(EX_OSERR, "Kernel returned too large of a buffer for '%s'\n", + sysctlname); + } else { + err(EX_OSERR, "Sysctl get '%s'\n", sysctlname); + } + } + if (verbose) { + printf("kernel dumps on "); + } + if (strlen(dumpdev) == 0) { + printf("%s\n", _PATH_DEVNULL); + } else { + printf("%s\n", dumpdev); + } +} + int main(int argc, char *argv[]) { int ch; int i, fd; u_int u; + int do_listdumpdev = 0; - while ((ch = getopt(argc, argv, "v")) != -1) + while ((ch = getopt(argc, argv, "lv")) != -1) switch((char)ch) { + case 'l': + do_listdumpdev = 1; + break; case 'v': verbose = 1; break; @@ -111,6 +143,11 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; + if (do_listdumpdev) { + listdumpdev(); + exit(EX_OK); + } + if (argc != 1) usage();