1 /* $OpenBSD: db_usrreq.c,v 1.13 2008/11/08 01:14:51 mpf Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Michael Shalayeff. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include <sys/param.h> 28 #include <sys/types.h> 29 #include <sys/kernel.h> 30 #include <sys/proc.h> 31 #include <sys/tty.h> 32 #include <uvm/uvm_extern.h> 33 #include <sys/sysctl.h> 34 #include <dev/cons.h> 35 36 #include <ddb/db_var.h> 37 38 int db_log = 1; 39 40 int 41 ddb_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, 42 size_t newlen, struct proc *p) 43 { 44 int error, ctlval; 45 46 /* All sysctl names at this level are terminal. */ 47 if (namelen != 1) 48 return (ENOTDIR); 49 50 switch (name[0]) { 51 52 case DBCTL_RADIX: 53 return sysctl_int(oldp, oldlenp, newp, newlen, &db_radix); 54 case DBCTL_MAXWIDTH: 55 return sysctl_int(oldp, oldlenp, newp, newlen, &db_max_width); 56 case DBCTL_TABSTOP: 57 return sysctl_int(oldp, oldlenp, newp, newlen, &db_tab_stop_width); 58 case DBCTL_MAXLINE: 59 return sysctl_int(oldp, oldlenp, newp, newlen, &db_max_line); 60 case DBCTL_PANIC: 61 if (securelevel > 0) 62 return (sysctl_int_lower(oldp, oldlenp, newp, newlen, 63 &db_panic)); 64 else { 65 ctlval = db_panic; 66 if ((error = sysctl_int(oldp, oldlenp, newp, newlen, 67 &ctlval)) || newp == NULL) 68 return (error); 69 if (ctlval != 1 && ctlval != 0) 70 return (EINVAL); 71 db_panic = ctlval; 72 return (0); 73 } 74 break; 75 case DBCTL_CONSOLE: 76 if (securelevel > 0) 77 return (sysctl_int_lower(oldp, oldlenp, newp, newlen, 78 &db_console)); 79 else { 80 ctlval = db_console; 81 if ((error = sysctl_int(oldp, oldlenp, newp, newlen, 82 &ctlval)) || newp == NULL) 83 return (error); 84 if (ctlval != 1 && ctlval != 0) 85 return (EINVAL); 86 db_console = ctlval; 87 return (0); 88 } 89 break; 90 case DBCTL_LOG: 91 return (sysctl_int(oldp, oldlenp, newp, newlen, &db_log)); 92 case DBCTL_TRIGGER: 93 if (newp && db_console) { 94 struct proc *p = curproc; 95 if (securelevel < 1 || 96 (p->p_flag & P_CONTROLT && cn_tab && 97 cn_tab->cn_dev == p->p_session->s_ttyp->t_dev)) { 98 Debugger(); 99 newp = NULL; 100 } else 101 return (EOPNOTSUPP); 102 } 103 return (sysctl_rdint(oldp, oldlenp, newp, 0)); 104 default: 105 return (EOPNOTSUPP); 106 } 107 /* NOTREACHED */ 108 } 109