xref: /freebsd/share/man/man4/watchdog.4 (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1.\" Copyright (c) 2004 Poul-Henning Kamp <phk@FreeBSD.org>
2.\" Copyright (c) 2003, 2004 Sean M. Kelly <smkelly@FreeBSD.org>
3.\" 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd December 21, 2009
29.Dt WATCHDOG 4
30.Os
31.Sh NAME
32.Nm watchdog
33.Nd "hardware and software watchdog"
34.Sh SYNOPSIS
35.In sys/watchdog.h
36.Sh DESCRIPTION
37The
38.Nm
39facility is used for controlling hardware and software watchdogs.
40.Pp
41The device
42.Pa /dev/fido
43responds to a single
44.Xr ioctl 2
45call,
46.Dv WDIOCPATPAT .
47It takes a single argument which represents a timeout value specified as a
48power of two nanoseconds, or-ed with a flag selecting active or passive control
49of the watchdog.
50.Pp
51.Dv WD_ACTIVE
52indicates that the
53.Nm
54will be kept from timing out from userland, for instance by the
55.Xr watchdogd 8
56daemon.
57.Dv WD_PASSIVE
58indicates that the
59.Nm
60will be kept from timing out from the kernel.
61.Pp
62The
63.Xr ioctl 2
64call will return success if just one of the available
65.Xr watchdog 9
66implementations supports setting the timeout to the specified timeout.
67This
68means that at least one watchdog is armed.
69If the call fails, for instance if
70none of
71.Xr watchdog 9
72implementations support the timeout length, all watchdogs are disabled and must
73be explicitly re-enabled.
74.Pp
75To disable the watchdogs pass
76.Dv WD_TO_NEVER .
77If disarming the watchdog(s) failed an error is returned.
78The watchdog might
79still be armed!
80.Sh RETURN VALUES
81The ioctl returns zero on success and non-zero on failure.
82.Bl -tag -width Er
83.It Bq Er EOPNOTSUPP
84No watchdog present in the kernel or
85none of the watchdogs supports the requested timeout value
86(timeout value other than 0).
87.It Bq Er EOPNOTSUPP
88Watchdog could not be disabled (timeout value of 0).
89.It Bq Er EINVAL
90Invalid flag combination passed.
91.El
92.Sh EXAMPLES
93.Bd -literal -offset indent
94#include <paths.h>
95#include <sys/watchdog.h>
96
97#define WDPATH	"/dev/" _PATH_WATCHDOG
98int wdfd = -1;
99
100static void
101wd_init(void)
102{
103	wdfd = open(WDPATH, O_RDWR);
104	if (wdfd == -1)
105		err(1, WDPATH);
106}
107static void
108wd_reset(u_int timeout)
109{
110	if (ioctl(wdfd, WDIOCPATPAT, &timeout) == -1)
111		err(1, "WDIOCPATPAT");
112}
113
114/* in main() */
115wd_init();
116wd_reset(WD_ACTIVE|WD_TO_8SEC);
117/* potential freeze point */
118wd_reset(WD_TO_NEVER);
119.Ed
120.Pp
121Enables a watchdog to recover from a potentially freezing piece of code.
122.Pp
123.Dl "options SW_WATCHDOG"
124.Pp
125in your kernel config adds a software watchdog in the kernel, dropping to KDB
126or panic-ing when firing.
127.Sh SEE ALSO
128.Xr watchdogd 8 ,
129.Xr watchdog 9
130.Sh HISTORY
131The
132.Nm
133code first appeared in
134.Fx 5.1 .
135.Sh AUTHORS
136.An -nosplit
137The
138.Nm
139facility was written by
140.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org .
141The software watchdog code and this manual page were written by
142.An Sean Kelly Aq Mt smkelly@FreeBSD.org .
143Some contributions were made by
144.An Jeff Roberson Aq Mt jeff@FreeBSD.org .
145.Sh BUGS
146The
147.Dv WD_PASSIVE
148option has not yet been implemented.
149