From 03f2fdd26fee309abfe7c8bdf799f8d35a4e18bf Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 22 Sep 2018 20:57:52 +0800 Subject: [PATCH] dumpon(8): Add "dumpoff" variant to be "dumpon off" "dumpon off" doesn't seem to be a good command, so let's add the "dumpoff" variant that just acts as "dumpon off", similar to "swapoff". Thanks to swildner for the initial patch. See also: https://bugs.dragonflybsd.org/issues/3092#note-2 --- sbin/dumpon/Makefile | 4 +++- sbin/dumpon/dumpon.8 | 14 +++++++++++--- sbin/dumpon/dumpon.c | 27 ++++++++++++++++++--------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/sbin/dumpon/Makefile b/sbin/dumpon/Makefile index 4496071891..ec51b32306 100644 --- a/sbin/dumpon/Makefile +++ b/sbin/dumpon/Makefile @@ -1,7 +1,9 @@ # $FreeBSD: src/sbin/dumpon/Makefile,v 1.4.2.1 2001/04/25 10:58:16 ru Exp $ -# $DragonFly: src/sbin/dumpon/Makefile,v 1.4 2006/10/17 00:55:40 pavalos Exp $ PROG= dumpon MAN= dumpon.8 +LINKS= ${BINDIR}/dumpon ${BINDIR}/dumpoff +MLINKS= dumpon.8 dumpoff.8 + .include diff --git a/sbin/dumpon/dumpon.8 b/sbin/dumpon/dumpon.8 index 6d41b18957..ab13f279f8 100644 --- a/sbin/dumpon/dumpon.8 +++ b/sbin/dumpon/dumpon.8 @@ -28,11 +28,11 @@ .\" From: @(#)swapon.8 8.1 (Berkeley) 6/5/93 .\" $FreeBSD: src/sbin/dumpon/dumpon.8,v 1.11.2.12 2003/01/26 03:12:04 keramida Exp $ .\" -.Dd September 29, 2016 +.Dd September 22, 2018 .Dt DUMPON 8 .Os .Sh NAME -.Nm dumpon +.Nm dumpon , dumpoff .Nd "specify a device for crash dumps" .Sh SYNOPSIS .Nm @@ -41,6 +41,8 @@ .Nm .Op Fl v .Cm off +.Nm dumpoff +.Op Fl v .Sh DESCRIPTION The .Nm @@ -90,7 +92,9 @@ to the device number of the designated .Ar special_file or to .Dv NODEV -(meaning that no dumps are to be taken) if +(meaning that no dumps are to be taken) if the utility is invoked as +.Nm dumpoff +or if .Ar special_file is the text string: .Dq Li off . @@ -126,6 +130,10 @@ The .Nm utility appeared in .Fx 2.0.5 . +The +.Nm dumpoff +utility first appeared in +.Dx 5.3 . .Sh BUGS Because the file system layer is already dead by the time a crash dump is taken, it is not possible to send crash dumps directly to a file. diff --git a/sbin/dumpon/dumpon.c b/sbin/dumpon/dumpon.c index 54aa9ec3a0..ea0915e432 100644 --- a/sbin/dumpon/dumpon.c +++ b/sbin/dumpon/dumpon.c @@ -26,15 +26,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved. * @(#)swapon.c 8.1 (Berkeley) 6/5/93 * $FreeBSD: src/sbin/dumpon/dumpon.c,v 1.10.2.2 2001/07/30 10:30:05 dd Exp $ - * $DragonFly: src/sbin/dumpon/dumpon.c,v 1.5 2006/03/25 07:44:14 dillon Exp $ */ #include #include #include +#include #include #include #include @@ -43,7 +42,7 @@ #include #include -void usage(void) __dead2; +static void usage(void) __dead2; int main(int argc, char **argv) @@ -51,11 +50,19 @@ main(int argc, char **argv) int ch, verbose, rv; struct stat stab; int mib[2]; - char *path; + char *path, *p; + bool is_dumpoff; + + if (strstr((p = strrchr(argv[0], '/')) ? p+1 : argv[0], + "dumpoff") != 0) { + is_dumpoff = true; + } else { + is_dumpoff = false; + } verbose = rv = 0; while ((ch = getopt(argc, argv, "v")) != -1) { - switch((char)ch) { + switch (ch) { case 'v': verbose = 1; break; @@ -64,13 +71,14 @@ main(int argc, char **argv) usage(); } } + argc -= optind; argv += optind; - if (argv[0] == NULL || argv[1]) + if ((is_dumpoff && argc != 0) || (!is_dumpoff && argc != 1)) usage(); path = argv[0]; - if (strcmp(path, "off") == 0) { + if (is_dumpoff || strcmp(path, "off") == 0) { stab.st_rdev = NODEV; } else { path = getdevpath(path, 0); @@ -107,11 +115,12 @@ main(int argc, char **argv) return 0; } -void +static void usage(void) { fprintf(stderr, "usage: dumpon [-v] special_file\n" - " dumpon [-v] off\n"); + " dumpon [-v] off\n" + " dumpoff [-v]\n"); exit(EX_USAGE); } -- 2.41.0