From ae2edb2af1f05163eadd3ad1998af8adb22001a9 Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Wed, 5 Mar 2008 18:32:58 +0000 Subject: [PATCH] Use the new command file feature of ddb(8) to support setting ddb(4) scripts at boot. This is currently disabled by default. /etc/ddb.conf contains some potentially reasonable default scripts. PR: conf/119995 Submitted by: Scot Hetzel (Earlier version) X-MFC after: textdumps --- etc/Makefile | 2 +- etc/ddb.conf | 15 +++++++++++++++ etc/defaults/rc.conf | 2 ++ etc/rc.d/Makefile | 2 +- etc/rc.d/ddb | 32 ++++++++++++++++++++++++++++++++ share/man/man5/rc.conf.5 | 13 +++++++++++++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 etc/ddb.conf create mode 100644 etc/rc.d/ddb diff --git a/etc/Makefile b/etc/Makefile index 9745a1574f4..1fef1ff5243 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -9,7 +9,7 @@ SUBDIR= sendmail BIN1= amd.map apmd.conf auth.conf \ crontab csh.cshrc csh.login csh.logout devd.conf devfs.conf \ - dhclient.conf disktab fbtab freebsd-update.conf \ + ddb.conf dhclient.conf disktab fbtab freebsd-update.conf \ ftpusers gettytab group \ hosts hosts.allow hosts.equiv hosts.lpd \ inetd.conf libalias.conf login.access login.conf mac.conf motd \ diff --git a/etc/ddb.conf b/etc/ddb.conf new file mode 100644 index 00000000000..a793705c658 --- /dev/null +++ b/etc/ddb.conf @@ -0,0 +1,15 @@ +# $FreeBSD$ +# +# This file is read when going to multi-user and its contents piped thru +# ``ddb'' to define debugging scripts. +# +# see ``man 4 ddb'' and ``man 8 ddb'' for details. +# + +script lockinfo=show locks; show alllocks; show lockedvnods + +# kdb.enter.panic panic(9) was called. +script kdb.enter.panic=textdump set; capture on; run lockinfo; show pcpu; bt; ps; alltrace; capture off; call doadump; reset + +# kdb.enter.witness witness(4) detected a locking error. +script kdb.enter.witness=run lockinfo diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index 195facdcc39..1fc03682d7e 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -33,6 +33,8 @@ swapfile="NO" # Set to name of swapfile if aux swapfile desired. apm_enable="NO" # Set to YES to enable APM BIOS functions (or NO). apmd_enable="NO" # Run apmd to handle APM event from userland. apmd_flags="" # Flags to apmd (if enabled). +ddb_enable="NO" # Set to YES to load ddb scripts at boot. +ddb_config="/etc/ddb.conf" # ddb(8) config file. devd_enable="YES" # Run devd, to trigger programs on device tree changes. devd_flags="" # Additional flags for devd(8). kldxref_enable="NO" # Build linker.hints files with kldxref(8). diff --git a/etc/rc.d/Makefile b/etc/rc.d/Makefile index 36269159ff5..aa094f68363 100755 --- a/etc/rc.d/Makefile +++ b/etc/rc.d/Makefile @@ -7,7 +7,7 @@ FILES= DAEMON FILESYSTEMS LOGIN NETWORKING SERVERS \ apm apmd archdep atm1 atm2 atm3 auditd auto_linklocal \ bgfsck bluetooth bootparams bridge bsnmpd bthidd \ ccd cleanvar cleartmp cron \ - devd devfs dhclient \ + ddb devd devfs dhclient \ dmesg dumpon \ early.sh encswap \ fsck ftp-proxy ftpd \ diff --git a/etc/rc.d/ddb b/etc/rc.d/ddb new file mode 100644 index 00000000000..f4d34b198b4 --- /dev/null +++ b/etc/rc.d/ddb @@ -0,0 +1,32 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: ddb +# REQUIRE: dumpon +# BEFORE: disks savecore initrandom +# KEYWORD: nojail + +. /etc/rc.subr + +name="ddb" +rcvar=`set_rcvar` +command="/sbin/${name}" +start_precmd="ddb_prestart" +stop_cmd=":" + +ddb_prestart() +{ + # Silently exit if ddb is not enabled + if [ -z "`sysctl -Nq debug.ddb.scripting.scripts`" ]; then + return 1 + fi +} + +load_rc_config $name + +required_files="${ddb_config}" +command_args="${ddb_config}" + +run_rc_command "$1" diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index af6506bdc13..3c7b67af897 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -164,6 +164,19 @@ daemon. Run .Xr devd 8 to handle device added, removed or unknown events from the kernel. +.It Va ddb_enable +.Pq Vt bool +Run +.Xr ddb 8 +to install +.Xr ddb 4 +scripts at boot time. +.It Va ddb_config +.Pq Vt str +Configuration file for +.Xr ddb 8 . +Default +.Pa /etc/ddb.conf . .It Va kldxref_enable .Pq Vt bool Set to