dumpon.c revision 93491
18478Swollman/* 28478Swollman * Copyright (c) 1980, 1993 38478Swollman * The Regents of the University of California. All rights reserved. 48478Swollman * 58478Swollman * Redistribution and use in source and binary forms, with or without 68478Swollman * modification, are permitted provided that the following conditions 78478Swollman * are met: 88478Swollman * 1. Redistributions of source code must retain the above copyright 98478Swollman * notice, this list of conditions and the following disclaimer. 108478Swollman * 2. Redistributions in binary form must reproduce the above copyright 118478Swollman * notice, this list of conditions and the following disclaimer in the 128478Swollman * documentation and/or other materials provided with the distribution. 138478Swollman * 3. All advertising materials mentioning features or use of this software 148478Swollman * must display the following acknowledgement: 158478Swollman * This product includes software developed by the University of 168478Swollman * California, Berkeley and its contributors. 178478Swollman * 4. Neither the name of the University nor the names of its contributors 188478Swollman * may be used to endorse or promote products derived from this software 198478Swollman * without specific prior written permission. 208478Swollman * 218478Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 228478Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 238478Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 248478Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 258478Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 268478Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 278478Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 288478Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 298478Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 308478Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 318478Swollman * SUCH DAMAGE. 328478Swollman */ 338478Swollman 348478Swollman#ifndef lint 3536999Scharnierstatic const char copyright[] = 368478Swollman"@(#) Copyright (c) 1980, 1993\n\ 378478Swollman The Regents of the University of California. All rights reserved.\n"; 388478Swollman#endif /* not lint */ 398478Swollman 408478Swollman#ifndef lint 4136999Scharnier#if 0 4236999Scharnierstatic char sccsid[] = "From: @(#)swapon.c 8.1 (Berkeley) 6/5/93"; 4336999Scharnier#endif 448478Swollmanstatic const char rcsid[] = 4550476Speter "$FreeBSD: head/sbin/dumpon/dumpon.c 93491 2002-03-31 22:24:24Z phk $"; 468478Swollman#endif /* not lint */ 478478Swollman 4836999Scharnier#include <err.h> 498478Swollman#include <stdio.h> 5078732Sdd#include <stdlib.h> 5193491Sphk#include <fcntl.h> 5293491Sphk#include <paths.h> 538478Swollman#include <unistd.h> 548478Swollman#include <sys/param.h> 5593491Sphk#include <sys/disklabel.h> 568478Swollman#include <sysexits.h> 578478Swollman 5892542Simpvoid usage(void) __dead2; 598478Swollman 608478Swollmanint 6192542Simpmain(int argc, char *argv[]) 628478Swollman{ 638478Swollman int ch, verbose, rv; 6493491Sphk int i, fd; 6593491Sphk u_int u; 668478Swollman 678478Swollman verbose = rv = 0; 6824359Simp while ((ch = getopt(argc, argv, "v")) != -1) 698478Swollman switch((char)ch) { 708478Swollman case 'v': 718478Swollman verbose = 1; 728478Swollman break; 738478Swollman case '?': 748478Swollman default: 758478Swollman usage(); 768478Swollman } 778478Swollman argv += optind; 788478Swollman 798478Swollman if (!argv[0] || argv[1]) 808478Swollman usage(); 818478Swollman 828478Swollman if (strcmp(argv[0], "off")) { 8393491Sphk fd = open(argv[0], O_RDONLY); 8493491Sphk if (fd < 0) 858478Swollman err(EX_OSFILE, "%s", argv[0]); 8693491Sphk u = 0; 8793491Sphk i = ioctl(fd, DIOCGKERNELDUMP, &u); 8893491Sphk u = 1; 8993491Sphk i = ioctl(fd, DIOCGKERNELDUMP, &u); 9093491Sphk if (i == 0 && verbose) 9193491Sphk printf("kernel dumps on %s\n", argv[0]); 9293491Sphk 938478Swollman } else { 9493491Sphk fd = open(_PATH_DEVNULL, O_RDONLY); 9593491Sphk if (fd < 0) 9693491Sphk err(EX_OSFILE, "%s", _PATH_DEVNULL); 9793491Sphk u = 0; 9893491Sphk i = ioctl(fd, DIOCGKERNELDUMP, &u); 9993491Sphk if (i == 0 && verbose) 10093491Sphk printf("kernel dumps disabled\n"); 1018478Swollman } 10293491Sphk if (i < 0) 10393491Sphk err(EX_OSERR, "ioctl(DIOCGKERNELDUMP)"); 1048478Swollman 10593491Sphk exit (0); 1068478Swollman} 1078478Swollman 1088478Swollmanvoid 10992542Simpusage(void) 1108478Swollman{ 1118478Swollman fprintf(stderr, 11236999Scharnier "usage: dumpon [-v] special_file\n" 11336999Scharnier " dumpon [-v] off\n"); 1148478Swollman exit(EX_USAGE); 1158478Swollman} 116