shutdownhook_establish, shutdownhook_disestablish - add or
remove a shutdown
shutdownhook_establish(void (*fn)(void *), void *arg);
The shutdownhook_establish() function adds fn to the list of
by doshutdownhooks(9) at shutdown. When invoked, the
fn will be passed arg as its only argument.
The shutdownhook_disestablish() function removes the hook
the opaque pointer cookie from the list of hooks to be invoked at shutdown.
If cookie is invalid, the result of
Shutdown hooks should be used to perform one-time activities
happen immediately before the kernel exits. Because of the
in which they are run, shutdown hooks cannot rely on many
(including file systems, timeouts, and other interrupt-driven services)
or even basic system integrity (because the system could be
Shutdown hooks are, like startup hooks, implemented via the
If successful, shutdownhook_establish() returns an opaque
the newly established shutdown hook. Otherwise, it
It may be appropriate to use a shutdown hook to disable a
does direct memory access, so that the device will not try
to access memory
while the system is rebooting.
It may be appropriate to use a shutdown hook to inform
hardware that the operating system is no longer running.
dohooks(9), doshutdownhooks(9), dostartuphooks(9)
Shutdown hooks should only be used to do what's strictly
necessary to do
to ensure a correct reboot. Since shutdown hooks are run
even after a
panic, a panic caused by a shutdown hook will automatically
shutdown hook to be run again causing an endless loop. An
things that need to be done in a shutdown hook could be
stopping DMA engines
that might corrupt memory when rebooting. An example
that shouldn't be done in a shutdown hook is syncing the
Once again, since the system could be rebooting because of
inconsistency, writing down anything to permanent storage or
internal state of the system is a very bad idea.
The names are clumsy, at best.
OpenBSD 3.6 November 13, 1995
[ Back ]