Fix system shutdown timeout handling by again supporting longer running shutdown procedures (which have a duration of more than 120 seconds). We have two user-space affecting shutdown timeouts: a "soft" one in /etc/rc.shutdown and a "hard" one in init(8). The first one can be configured via /etc/rc.conf variable "rcshutdown_timeout" and defaults to 30 seconds. The second one was originally (in 1998) intended to be configured via sysctl(8) variable "kern.shutdown_timeout" and defaults to 120 seconds. Unfortunately, the "kern.shutdown_timeout" was declared "unused" in 1999 (as it obviously is actually not used within the kernel itself) and hence was intentionally but misleadingly removed in revision 1.107 from init_main.c. Kernel sysctl(8) variables are certainly a wrong way to control user-space processes in general, but in this particular case the sysctl(8) variable should have remained as it supports init(8), which isn't passed command line flags (which in turn could have been set via /etc/rc.conf), etc. As there is already a similar "kern.init_path" sysctl(8) variable which directly affects init(8), resurrect the init(8) shutdown timeout under sysctl(8) variable "kern.init_shutdown_timeout". But this time document it as being intentionally unused within the kernel and used by init(8). Also document it in the manpages init(8) and rc.conf(5). Index: share/man/man5/rc.conf.5 =================================================================== RCS file: /v/freebsd/cvs/src/share/man/man5/rc.conf.5,v retrieving revision 1.263 diff -u -d -r1.263 rc.conf.5 --- share/man/man5/rc.conf.5 8 Sep 2005 09:22:21 -0000 1.263 +++ share/man/man5/rc.conf.5 14 Sep 2005 14:56:21 -0000 @@ -3170,6 +3170,21 @@ if .Xr shutdown 8 has not completed within the specified time (in seconds). +Notice that in addition to this soft timeout, +.Xr init 8 +also applies a hard timeout for the execution of +.Pa rc.shutdown . +This is controlled via +.Xr sysctl 8 +variable +.Va kern.init_shutdown_timeout +and defaults to 120 seconds. Setting the value of +.Va rcshutdown_timeout +to more than 120 seconds will have no effect until the +.Xr sysctl 8 +variable +.Va kern.init_shutdown_timeout +is also increased. .It Va virecover_enable .Pq Vt bool Set to Index: sbin/init/init.8 =================================================================== RCS file: /v/freebsd/cvs/src/sbin/init/init.8,v retrieving revision 1.47 diff -u -d -r1.47 init.8 --- sbin/init/init.8 3 Sep 2005 17:16:00 -0000 1.47 +++ sbin/init/init.8 14 Sep 2005 14:48:39 -0000 @@ -270,6 +270,12 @@ as .Nm innd (the InterNetNews server). +If this script does not terminate within 120 seconds, +.Nm +will terminate it. The timeout can be controlled via the +.Xr sysctl 8 +variable +.Va kern.init_shutdown_timeout . .Pp The role of .Nm Index: sbin/init/init.c =================================================================== RCS file: /v/freebsd/cvs/src/sbin/init/init.c,v retrieving revision 1.60 diff -u -d -r1.60 init.c --- sbin/init/init.c 11 Jan 2005 14:34:29 -0000 1.60 +++ sbin/init/init.c 14 Sep 2005 14:36:55 -0000 @@ -1520,7 +1520,7 @@ } len = sizeof(shutdowntimeout); - if (sysctlbyname("kern.shutdown_timeout", + if (sysctlbyname("kern.init_shutdown_timeout", &shutdowntimeout, &len, NULL, 0) == -1 || shutdowntimeout < 2) shutdowntimeout = DEATH_SCRIPT; Index: sys/kern/init_main.c =================================================================== RCS file: /v/freebsd/cvs/src/sys/kern/init_main.c,v retrieving revision 1.256 diff -u -d -r1.256 init_main.c --- sys/kern/init_main.c 1 Jul 2005 16:28:30 -0000 1.256 +++ sys/kern/init_main.c 14 Sep 2005 14:36:12 -0000 @@ -499,6 +499,17 @@ "Path used to search the init process"); /* + * Shutdown timeout of init(8). + * Unused within kernel, but used to control init(8), hence do not remove. + */ +#ifndef INIT_SHUTDOWN_TIMEOUT +#define INIT_SHUTDOWN_TIMEOUT 120 +#endif +static int init_shutdown_timeout = INIT_SHUTDOWN_TIMEOUT; +SYSCTL_INT(_kern, OID_AUTO, init_shutdown_timeout, + CTLFLAG_RW, &init_shutdown_timeout, 0, ""); + +/* * Start the initial user process; try exec'ing each pathname in init_path. * The program is invoked with one argument containing the boot flags. */