NetBSD/share/man/man9/powerhook_establish.9

97 lines
3.7 KiB
Groff

.\" $NetBSD: powerhook_establish.9,v 1.1 1999/12/06 14:50:02 augustss Exp $
.\"
.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Lennart Augustsson.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd December 3, 1999
.Dt POWERHOOK_ESTABLISH 9
.Os
.Sh NAME
.Nm powerhook_establish ,
.Nm powerhook_disestablish
.Nd add or remove a power change hook
.Sh SYNOPSIS
.Ft void *
.Fn powerhook_establish "void (*fn)(int why, void *a)" "void *arg"
.Ft void
.Fn powerhook_disestablish "void *cookie"
.Sh DESCRIPTION
The
.Fn powerhook_establish
function adds
.Fa fn
of the list of hooks invoked by
.Xr dopowerhooks 9
at power change. When invoked, the hook function
.Fa fn
will be passed the new power state as the first argument and
.Fa arg
as its second argument.
.Pp
The
.Fn powerhook_disestablish
function removes the hook described by the opaque pointer
.Fa cookie
from the list of hooks to be invoked at power change. If
.Fa cookie
is invalid, the result of
.Fn powerhook_disestablish
is undefined.
.Pp
Power hooks should be used to perform activities
that must happen when the power situation to the computer changes. Because
of the environment in which they are run, shutdown hooks cannot
rely on many system services (including file systems, and timeouts
and other interrupt-driven services).
The power hooks are typically executed from an interrut context.
.Pp
The different reasons for calling the power hooks are: suspend, standby, and
resume. The reason is reflected in the
.Fa why
argument and the values
.Dv PWR_SUSPEND ,
.Dv PWR_STANDBY ,
and
.Dv PWR_RESUME .
At suspend the system is going to lose (almost) all power, standby retains
some power (e.g., minimal power to USB devices), and at resume power is
back to normal.
.Sh RETURN VALUES
If successful,
.Fn powerhook_establish
returns an opaque pointer describing the newly-established
shutdown hook. Otherwise, it returns NULL.
.Sh SEE ALSO
.Xr dopowerhooks 9