1 /* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #if 0 31 #ifndef lint 32 static const char copyright[] = 33 "@(#) Copyright (c) 1980, 1993\n\ 34 The Regents of the University of California. All rights reserved.\n"; 35 #endif /* not lint */ 36 37 #ifndef lint 38 static char sccsid[] = "From: @(#)swapon.c 8.1 (Berkeley) 6/5/93"; 39 #endif /* not lint */ 40 #endif 41 #include <sys/cdefs.h> 42 __FBSDID("$FreeBSD$"); 43 44 #include <err.h> 45 #include <stdio.h> 46 #include <stdlib.h> 47 #include <fcntl.h> 48 #include <paths.h> 49 #include <string.h> 50 #include <unistd.h> 51 #include <sys/param.h> 52 #include <sys/disk.h> 53 #include <sysexits.h> 54 55 void usage(void) __dead2; 56 57 int 58 main(int argc, char *argv[]) 59 { 60 int ch, verbose, rv; 61 int i, fd; 62 u_int u; 63 64 verbose = rv = 0; 65 while ((ch = getopt(argc, argv, "v")) != -1) 66 switch((char)ch) { 67 case 'v': 68 verbose = 1; 69 break; 70 case '?': 71 default: 72 usage(); 73 } 74 argv += optind; 75 76 if (!argv[0] || argv[1]) 77 usage(); 78 79 if (strcmp(argv[0], "off")) { 80 fd = open(argv[0], O_RDONLY); 81 if (fd < 0) 82 err(EX_OSFILE, "%s", argv[0]); 83 u = 0; 84 i = ioctl(fd, DIOCSKERNELDUMP, &u); 85 u = 1; 86 i = ioctl(fd, DIOCSKERNELDUMP, &u); 87 if (i == 0 && verbose) 88 printf("kernel dumps on %s\n", argv[0]); 89 90 } else { 91 fd = open(_PATH_DEVNULL, O_RDONLY); 92 if (fd < 0) 93 err(EX_OSFILE, "%s", _PATH_DEVNULL); 94 u = 0; 95 i = ioctl(fd, DIOCSKERNELDUMP, &u); 96 if (i == 0 && verbose) 97 printf("kernel dumps disabled\n"); 98 } 99 if (i < 0) 100 err(EX_OSERR, "ioctl(DIOCSKERNELDUMP)"); 101 102 exit (0); 103 } 104 105 void 106 usage(void) 107 { 108 fprintf(stderr, 109 "usage: dumpon [-v] special_file\n" 110 " dumpon [-v] off\n"); 111 exit(EX_USAGE); 112 } 113