db_usrreq.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* $OpenBSD: db_usrreq.c,v 1.17 2015/03/14 03:38:46 jsg Exp $ */
  2. /*
  3. * Copyright (c) 1996 Michael Shalayeff. 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. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include <sys/param.h>
  26. #include <sys/types.h>
  27. #include <sys/systm.h>
  28. #include <sys/proc.h>
  29. #include <sys/tty.h>
  30. #include <sys/sysctl.h>
  31. #include <dev/cons.h>
  32. #include <ddb/db_var.h>
  33. int db_log = 1;
  34. int
  35. ddb_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
  36. size_t newlen, struct proc *p)
  37. {
  38. int error, ctlval;
  39. /* All sysctl names at this level are terminal. */
  40. if (namelen != 1)
  41. return (ENOTDIR);
  42. switch (name[0]) {
  43. case DBCTL_RADIX:
  44. return sysctl_int(oldp, oldlenp, newp, newlen, &db_radix);
  45. case DBCTL_MAXWIDTH:
  46. return sysctl_int(oldp, oldlenp, newp, newlen, &db_max_width);
  47. case DBCTL_TABSTOP:
  48. return sysctl_int(oldp, oldlenp, newp, newlen, &db_tab_stop_width);
  49. case DBCTL_MAXLINE:
  50. return sysctl_int(oldp, oldlenp, newp, newlen, &db_max_line);
  51. case DBCTL_PANIC:
  52. if (securelevel > 0)
  53. return (sysctl_int_lower(oldp, oldlenp, newp, newlen,
  54. &db_panic));
  55. else {
  56. ctlval = db_panic;
  57. if ((error = sysctl_int(oldp, oldlenp, newp, newlen,
  58. &ctlval)) || newp == NULL)
  59. return (error);
  60. if (ctlval != 1 && ctlval != 0)
  61. return (EINVAL);
  62. db_panic = ctlval;
  63. return (0);
  64. }
  65. break;
  66. case DBCTL_CONSOLE:
  67. if (securelevel > 0)
  68. return (sysctl_int_lower(oldp, oldlenp, newp, newlen,
  69. &db_console));
  70. else {
  71. ctlval = db_console;
  72. if ((error = sysctl_int(oldp, oldlenp, newp, newlen,
  73. &ctlval)) || newp == NULL)
  74. return (error);
  75. if (ctlval != 1 && ctlval != 0)
  76. return (EINVAL);
  77. db_console = ctlval;
  78. return (0);
  79. }
  80. break;
  81. case DBCTL_LOG:
  82. return (sysctl_int(oldp, oldlenp, newp, newlen, &db_log));
  83. case DBCTL_TRIGGER:
  84. if (newp && db_console) {
  85. struct process *pr = curproc->p_p;
  86. if (securelevel < 1 ||
  87. (pr->ps_flags & PS_CONTROLT && cn_tab &&
  88. cn_tab->cn_dev == pr->ps_session->s_ttyp->t_dev)) {
  89. Debugger();
  90. newp = NULL;
  91. } else
  92. return (ENODEV);
  93. }
  94. return (sysctl_rdint(oldp, oldlenp, newp, 0));
  95. default:
  96. return (EOPNOTSUPP);
  97. }
  98. /* NOTREACHED */
  99. }