svn commit: r242449 - user/alfred/9-alfred/sbin/dumpon
Alfred Perlstein
alfred at FreeBSD.org
Thu Nov 1 18:51:12 UTC 2012
Author: alfred
Date: Thu Nov 1 18:51:11 2012
New Revision: 242449
URL: http://svn.freebsd.org/changeset/base/242449
Log:
Add -l option to dumpon(8). Show which dumpdev is currently enabled.
When dumps are disabled show _PATH_DEVNULL ("/dev/null").
Modified:
user/alfred/9-alfred/sbin/dumpon/dumpon.c
Modified: user/alfred/9-alfred/sbin/dumpon/dumpon.c
==============================================================================
--- user/alfred/9-alfred/sbin/dumpon/dumpon.c Thu Nov 1 17:38:04 2012 (r242448)
+++ user/alfred/9-alfred/sbin/dumpon/dumpon.c Thu Nov 1 18:51:11 2012 (r242449)
@@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <stdint.h>
@@ -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();
More information about the svn-src-user
mailing list