Home | History | Annotate | Line # | Download | only in wdogctl
wdogctl.c revision 1.20
      1  1.20     joerg /*	$NetBSD: wdogctl.c,v 1.20 2011/08/27 19:00:35 joerg Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*-
      4   1.1   thorpej  * Copyright (c) 2000 Zembu Labs, Inc.
      5   1.1   thorpej  * All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * Author: Jason R. Thorpe <thorpej (at) zembu.com>
      8   1.1   thorpej  *
      9   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     10   1.1   thorpej  * modification, are permitted provided that the following conditions
     11   1.1   thorpej  * are met:
     12   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     13   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     14   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     16   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     17   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     18   1.1   thorpej  *    must display the following acknowledgement:
     19   1.1   thorpej  *	This product includes software developed by Zembu Labs, Inc.
     20   1.1   thorpej  * 4. Neither the name of Zembu Labs nor the names of its employees may
     21   1.1   thorpej  *    be used to endorse or promote products derived from this software
     22   1.1   thorpej  *    without specific prior written permission.
     23   1.1   thorpej  *
     24   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY ZEMBU LABS, INC. ``AS IS'' AND ANY EXPRESS
     25   1.1   thorpej  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAR-
     26   1.1   thorpej  * RANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DIS-
     27   1.1   thorpej  * CLAIMED.  IN NO EVENT SHALL ZEMBU LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
     28   1.1   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29   1.1   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30   1.1   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31   1.1   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32   1.1   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33   1.1   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34   1.1   thorpej  */
     35   1.8       agc #include <sys/cdefs.h>
     36   1.8       agc 
     37   1.8       agc #ifndef lint
     38  1.20     joerg __RCSID("$NetBSD: wdogctl.c,v 1.20 2011/08/27 19:00:35 joerg Exp $");
     39   1.8       agc #endif
     40   1.8       agc 
     41   1.1   thorpej 
     42   1.1   thorpej #include <sys/param.h>
     43   1.1   thorpej #include <sys/ioctl.h>
     44   1.1   thorpej #include <sys/wdog.h>
     45   1.1   thorpej 
     46   1.1   thorpej #include <err.h>
     47   1.1   thorpej #include <errno.h>
     48   1.1   thorpej #include <fcntl.h>
     49   1.1   thorpej #include <stdio.h>
     50   1.1   thorpej #include <stdlib.h>
     51   1.1   thorpej #include <time.h>
     52   1.1   thorpej #include <signal.h>
     53   1.1   thorpej #include <syslog.h>
     54   1.1   thorpej #include <unistd.h>
     55   1.2   minoura #include <string.h>
     56   1.1   thorpej 
     57   1.1   thorpej #define	_PATH_WATCHDOG		"/dev/watchdog"
     58   1.1   thorpej 
     59  1.20     joerg static void	enable_kernel(const char *, u_int);
     60  1.20     joerg static void	enable_user(const char *, u_int, int);
     61  1.20     joerg static void	enable_ext(const char *, u_int);
     62  1.20     joerg static void	tickle_ext(void);
     63  1.20     joerg static void	disable(void);
     64  1.20     joerg static void	prep_wmode(struct wdog_mode *, int,  const char *, u_int);
     65  1.20     joerg static void	list_timers(void);
     66  1.20     joerg __dead static void	usage(void);
     67   1.1   thorpej 
     68  1.20     joerg static int	Aflag;
     69   1.1   thorpej 
     70  1.11       smb /* Caution -- ordered list; entries >= CMD_EXT_TICKLE set timers */
     71  1.11       smb enum	cmd {
     72  1.11       smb 	CMD_NONE,	/* No verb given */
     73  1.11       smb 	CMD_DISABLE,
     74  1.11       smb 	CMD_DOTICKLE,
     75  1.11       smb 	CMD_EXT_TICKLE,
     76  1.11       smb 	CMD_KERN_TICKLE,
     77  1.16    dyoung 	CMD_NOCANCEL_TICKLE,
     78  1.11       smb 	CMD_USER_TICKLE
     79  1.11       smb };
     80  1.11       smb 
     81   1.1   thorpej int
     82   1.1   thorpej main(int argc, char *argv[])
     83   1.1   thorpej {
     84  1.11       smb 	enum cmd command = CMD_NONE;
     85  1.11       smb 	int period_flag = 0;
     86  1.18     lukem 	int ch, tmp;
     87   1.1   thorpej 	u_int period = WDOG_PERIOD_DEFAULT;
     88   1.1   thorpej 
     89  1.16    dyoung 	while ((ch = getopt(argc, argv, "Adekp:utx")) != -1) {
     90   1.1   thorpej 		switch (ch) {
     91   1.1   thorpej 		case 'A':
     92   1.1   thorpej 			Aflag = 1;
     93   1.1   thorpej 			break;
     94   1.1   thorpej 
     95   1.1   thorpej 		case 'd':
     96  1.11       smb 			if (command != CMD_NONE)
     97  1.11       smb 				usage();
     98  1.11       smb 			command = CMD_DISABLE;
     99  1.11       smb 			break;
    100  1.11       smb 
    101  1.11       smb 		case 'e':
    102  1.11       smb 			if (command != CMD_NONE)
    103  1.11       smb 				usage();
    104  1.11       smb 			command = CMD_EXT_TICKLE;
    105   1.1   thorpej 			break;
    106   1.1   thorpej 
    107   1.1   thorpej 		case 'k':
    108  1.11       smb 			if (command != CMD_NONE)
    109  1.11       smb 				usage();
    110  1.11       smb 			command = CMD_KERN_TICKLE;
    111  1.11       smb 			break;
    112  1.11       smb 
    113  1.11       smb 		case 't':
    114  1.11       smb 			if (command != CMD_NONE)
    115  1.11       smb 				usage();
    116  1.11       smb 			command = CMD_DOTICKLE;
    117   1.1   thorpej 			break;
    118   1.1   thorpej 
    119   1.1   thorpej 		case 'p':
    120  1.11       smb 			period_flag = 1;
    121  1.18     lukem 			tmp = atoi(optarg);
    122  1.18     lukem 			if (tmp < 0)
    123   1.1   thorpej 				usage();
    124  1.18     lukem 			period = (unsigned int)tmp;
    125   1.1   thorpej 			break;
    126   1.1   thorpej 
    127  1.16    dyoung 		case 'x':
    128   1.1   thorpej 		case 'u':
    129  1.11       smb 			if (command != CMD_NONE)
    130  1.11       smb 				usage();
    131  1.16    dyoung 			command =
    132  1.16    dyoung 			    (ch == 'u') ? CMD_USER_TICKLE : CMD_NOCANCEL_TICKLE;
    133   1.1   thorpej 			break;
    134   1.1   thorpej 
    135   1.1   thorpej 		default:
    136   1.1   thorpej 			usage();
    137   1.1   thorpej 		}
    138   1.1   thorpej 	}
    139   1.1   thorpej 
    140   1.1   thorpej 	argc -= optind;
    141   1.1   thorpej 	argv += optind;
    142   1.1   thorpej 
    143  1.11       smb 	if (command < CMD_EXT_TICKLE) {
    144  1.11       smb 		if (Aflag || period_flag)
    145  1.11       smb 			usage();
    146  1.11       smb 		if (argc != 0)
    147   1.1   thorpej 			usage();
    148  1.14    dyoung 	} else if (argc != 1)
    149  1.14    dyoung 		usage();
    150   1.1   thorpej 
    151  1.11       smb 	switch (command) {
    152  1.14    dyoung 	case CMD_NONE:
    153  1.14    dyoung 		list_timers();
    154  1.14    dyoung 		break;
    155  1.14    dyoung 	case CMD_DISABLE:
    156  1.14    dyoung 		disable();
    157  1.14    dyoung 		break;
    158  1.14    dyoung 	case CMD_DOTICKLE:
    159  1.14    dyoung 		tickle_ext();
    160  1.14    dyoung 		break;
    161  1.14    dyoung 	case CMD_EXT_TICKLE:
    162  1.14    dyoung 		enable_ext(argv[0], period);
    163  1.14    dyoung 		break;
    164  1.14    dyoung 	case CMD_KERN_TICKLE:
    165  1.14    dyoung 		enable_kernel(argv[0], period);
    166  1.14    dyoung 		break;
    167  1.16    dyoung 	case CMD_NOCANCEL_TICKLE:
    168  1.14    dyoung 	case CMD_USER_TICKLE:
    169  1.16    dyoung 		enable_user(argv[0], period, command == CMD_USER_TICKLE);
    170  1.14    dyoung 		break;
    171  1.11       smb 	}
    172  1.14    dyoung 	exit(EXIT_SUCCESS);
    173   1.1   thorpej }
    174   1.1   thorpej 
    175  1.20     joerg static void
    176  1.11       smb prep_wmode(struct wdog_mode *wp, int mode,  const char *name, u_int period)
    177  1.11       smb {
    178  1.11       smb 	if (strlen(name) >= WDOG_NAMESIZE)
    179  1.14    dyoung 		errx(EXIT_FAILURE, "invalid watchdog timer name: %s", name);
    180  1.11       smb 
    181  1.11       smb 	strlcpy(wp->wm_name, name, sizeof(wp->wm_name));
    182  1.11       smb 	wp->wm_mode = mode;
    183  1.11       smb 	wp->wm_period = period;
    184  1.11       smb 	if (Aflag)
    185  1.11       smb 		wp->wm_mode |= WDOG_FEATURE_ALARM;
    186  1.11       smb }
    187  1.11       smb 
    188  1.20     joerg static void
    189   1.1   thorpej enable_kernel(const char *name, u_int period)
    190   1.1   thorpej {
    191   1.1   thorpej 	struct wdog_mode wm;
    192   1.1   thorpej 	int fd;
    193   1.1   thorpej 
    194  1.11       smb 	prep_wmode(&wm, WDOG_MODE_KTICKLE, name, period);
    195   1.1   thorpej 
    196   1.1   thorpej 	fd = open(_PATH_WATCHDOG, O_RDWR, 0644);
    197   1.1   thorpej 	if (fd == -1)
    198  1.14    dyoung 		err(EXIT_FAILURE, "open %s", _PATH_WATCHDOG);
    199   1.1   thorpej 
    200   1.1   thorpej 	if (ioctl(fd, WDOGIOC_SMODE, &wm) == -1)
    201  1.14    dyoung 		err(EXIT_FAILURE, "WDOGIOC_SMODE");
    202  1.19       wiz 
    203  1.19       wiz 	(void)close(fd);
    204   1.1   thorpej }
    205   1.1   thorpej 
    206  1.20     joerg static void
    207  1.11       smb enable_ext(const char *name, u_int period)
    208  1.11       smb {
    209  1.11       smb 	struct wdog_mode wm;
    210  1.11       smb 	int fd;
    211  1.11       smb 
    212  1.11       smb 	prep_wmode(&wm, WDOG_MODE_ETICKLE, name, period);
    213  1.11       smb 
    214  1.11       smb 	fd = open(_PATH_WATCHDOG, O_RDWR, 0644);
    215  1.11       smb 	if (fd == -1)
    216  1.14    dyoung 		err(EXIT_FAILURE, "open %s", _PATH_WATCHDOG);
    217  1.11       smb 	if (ioctl(fd, WDOGIOC_SMODE, &wm) == -1) {
    218  1.14    dyoung 		err(EXIT_FAILURE, "WDOGIOC_SMODE");
    219  1.11       smb 	}
    220  1.11       smb 	if (ioctl(fd, WDOGIOC_TICKLE) == -1)
    221  1.11       smb 		syslog(LOG_EMERG, "unable to tickle watchdog timer %s: %m",
    222  1.11       smb 		    wm.wm_name);
    223  1.19       wiz 
    224  1.19       wiz 	(void)close(fd);
    225  1.11       smb 	return;
    226  1.11       smb }
    227  1.11       smb 
    228  1.20     joerg static void
    229  1.16    dyoung enable_user(const char *name, u_int period, int cancel_on_close)
    230   1.1   thorpej {
    231   1.1   thorpej 	struct wdog_mode wm;
    232   1.1   thorpej 	struct timespec ts;
    233   1.1   thorpej 	pid_t tickler;
    234   1.1   thorpej 	int fd, rv;
    235   1.1   thorpej 
    236  1.16    dyoung 	prep_wmode(&wm,
    237  1.16    dyoung 	    (cancel_on_close) ? WDOG_MODE_UTICKLE : WDOG_MODE_ETICKLE, name,
    238  1.16    dyoung 	    period);
    239   1.1   thorpej 
    240   1.1   thorpej 	fd = open(_PATH_WATCHDOG, O_RDWR, 0644);
    241   1.1   thorpej 	if (fd == -1)
    242  1.14    dyoung 		err(EXIT_FAILURE, "open %s", _PATH_WATCHDOG);
    243   1.1   thorpej 
    244   1.1   thorpej 	/* ...so we can log failures to tickle the timer. */
    245   1.4     lukem 	openlog("wdogctl", LOG_PERROR|LOG_PID, LOG_DAEMON);
    246   1.1   thorpej 
    247   1.1   thorpej 	/*
    248   1.1   thorpej 	 * We fork a child process which detaches from the controlling
    249   1.1   thorpej 	 * terminal once the timer is armed, and tickles the timer
    250   1.1   thorpej 	 * until we send it a SIGTERM.
    251   1.1   thorpej 	 */
    252   1.1   thorpej 	tickler = fork();
    253   1.1   thorpej 	if (tickler == -1)
    254  1.14    dyoung 		err(EXIT_FAILURE, "unable to fork tickler process");
    255   1.1   thorpej 	else if (tickler != 0) {
    256   1.1   thorpej 		if (ioctl(fd, WDOGIOC_SMODE, &wm) == -1) {
    257  1.15    dyoung 			(void)kill(tickler, SIGTERM);
    258  1.14    dyoung 			err(EXIT_FAILURE, "WDOGIOC_SMODE");
    259   1.1   thorpej 		}
    260  1.14    dyoung 		(void)close(fd);
    261   1.1   thorpej 		return;
    262   1.1   thorpej 	}
    263   1.1   thorpej 
    264   1.1   thorpej 
    265   1.1   thorpej 	/*
    266   1.1   thorpej 	 * Wait for the watchdog to be armed.  When it is, loop,
    267   1.1   thorpej 	 * tickling the timer, then waiting 1/2 the period before
    268   1.1   thorpej 	 * doing it again.
    269   1.1   thorpej 	 *
    270   1.1   thorpej 	 * If the parent fails to enable the watchdog, it will kill
    271   1.1   thorpej 	 * us.
    272   1.1   thorpej 	 */
    273   1.1   thorpej 	do {
    274   1.1   thorpej 		rv = ioctl(fd, WDOGIOC_WHICH, &wm);
    275   1.1   thorpej 	} while (rv == -1);
    276   1.1   thorpej 
    277   1.1   thorpej 	if (ioctl(fd, WDOGIOC_TICKLE) == -1)
    278   1.1   thorpej 		syslog(LOG_EMERG, "unable to tickle watchdog timer %s: %m",
    279   1.1   thorpej 		    wm.wm_name);
    280   1.1   thorpej 
    281   1.1   thorpej 	/*
    282   1.1   thorpej 	 * Now detach from the controlling terminal, and just run
    283   1.1   thorpej 	 * in the background.  The kernel will keep track of who
    284   1.1   thorpej 	 * we are, each time we tickle the timer.
    285   1.1   thorpej 	 */
    286   1.1   thorpej 	if (daemon(0, 0) == -1) {
    287   1.1   thorpej 		/*
    288   1.1   thorpej 		 * We weren't able to go into the background.  When
    289   1.1   thorpej 		 * we exit, the kernel will disable the watchdog so
    290   1.1   thorpej 		 * that the system won't die.
    291   1.1   thorpej 		 */
    292  1.14    dyoung 		err(EXIT_FAILURE, "unable to detach from terminal");
    293   1.1   thorpej 	}
    294   1.1   thorpej 
    295   1.1   thorpej 	if (ioctl(fd, WDOGIOC_TICKLE) == -1)
    296   1.1   thorpej 		syslog(LOG_EMERG, "unable to tickle watchdog timer %s: %m",
    297   1.1   thorpej 		    wm.wm_name);
    298   1.1   thorpej 
    299   1.1   thorpej 	for (;;) {
    300   1.1   thorpej 		ts.tv_sec = wm.wm_period / 2;
    301   1.1   thorpej 		ts.tv_nsec = 0;
    302  1.14    dyoung 		(void)nanosleep(&ts, NULL);
    303   1.1   thorpej 
    304   1.1   thorpej 		if (ioctl(fd, WDOGIOC_TICKLE) == -1)
    305   1.1   thorpej 			syslog(LOG_EMERG,
    306   1.1   thorpej 			    "unable to tickle watchdog timer %s: %m",
    307   1.1   thorpej 			    wm.wm_name);
    308   1.1   thorpej 	}
    309   1.1   thorpej 	/* NOTREACHED */
    310   1.1   thorpej }
    311   1.1   thorpej 
    312  1.20     joerg static void
    313  1.20     joerg tickle_ext(void)
    314  1.11       smb {
    315  1.11       smb 	int fd;
    316  1.11       smb 
    317  1.11       smb 	fd = open(_PATH_WATCHDOG, O_RDWR, 0644);
    318  1.11       smb 	if (fd == -1)
    319  1.14    dyoung 		err(EXIT_FAILURE, "open %s", _PATH_WATCHDOG);
    320  1.11       smb 	if (ioctl(fd, WDOGIOC_TICKLE) == -1)
    321  1.11       smb 		fprintf(stderr, "Cannot tickle timer\n");
    322  1.19       wiz 
    323  1.19       wiz 	(void)close(fd);
    324  1.11       smb }
    325  1.11       smb 
    326  1.20     joerg static void
    327   1.1   thorpej disable(void)
    328   1.1   thorpej {
    329   1.1   thorpej 	struct wdog_mode wm;
    330   1.1   thorpej 	pid_t tickler;
    331  1.13  drochner 	int fd, mode;
    332   1.1   thorpej 
    333   1.1   thorpej 	fd = open(_PATH_WATCHDOG, O_RDWR, 0644);
    334   1.1   thorpej 	if (fd == -1)
    335  1.14    dyoung 		err(EXIT_FAILURE, "open %s", _PATH_WATCHDOG);
    336   1.1   thorpej 
    337   1.1   thorpej 	if (ioctl(fd, WDOGIOC_WHICH, &wm) == -1) {
    338   1.1   thorpej 		printf("No watchdog timer running.\n");
    339  1.19       wiz 		(void)close(fd);
    340   1.1   thorpej 		return;
    341   1.1   thorpej 	}
    342  1.13  drochner 	mode = wm.wm_mode & WDOG_MODE_MASK;
    343   1.1   thorpej 
    344   1.1   thorpej 	/*
    345   1.1   thorpej 	 * If the timer is running in UTICKLE mode, we need
    346   1.1   thorpej 	 * to kill the wdogctl(8) process that is tickling
    347   1.1   thorpej 	 * the timer.
    348   1.1   thorpej 	 */
    349  1.13  drochner 	if (mode == WDOG_MODE_UTICKLE) {
    350   1.1   thorpej 		if (ioctl(fd, WDOGIOC_GTICKLER, &tickler) == -1)
    351  1.14    dyoung 			err(EXIT_FAILURE, "WDOGIOC_GTICKLER");
    352  1.14    dyoung 		(void)close(fd);
    353  1.14    dyoung 		(void)kill(tickler, SIGTERM);
    354   1.1   thorpej 	} else {
    355   1.1   thorpej 		wm.wm_mode = WDOG_MODE_DISARMED;
    356  1.14    dyoung 		if (ioctl(fd, WDOGIOC_SMODE, &wm) == -1) {
    357  1.14    dyoung 			err(EXIT_FAILURE, "unable to disarm watchdog %s",
    358  1.14    dyoung 			    wm.wm_name);
    359  1.14    dyoung 		}
    360  1.14    dyoung 		(void)close(fd);
    361   1.1   thorpej 	}
    362   1.1   thorpej }
    363   1.1   thorpej 
    364  1.20     joerg static void
    365   1.1   thorpej list_timers(void)
    366   1.1   thorpej {
    367   1.1   thorpej 	struct wdog_conf wc;
    368   1.1   thorpej 	struct wdog_mode wm;
    369   1.1   thorpej 	char *buf, *cp;
    370  1.13  drochner 	int fd, count, i, mode;
    371   1.1   thorpej 	pid_t tickler;
    372   1.1   thorpej 
    373   1.1   thorpej 	fd = open(_PATH_WATCHDOG, O_RDONLY, 0644);
    374   1.1   thorpej 	if (fd == -1)
    375  1.14    dyoung 		err(EXIT_FAILURE, "open %s", _PATH_WATCHDOG);
    376   1.1   thorpej 
    377   1.1   thorpej 	wc.wc_names = NULL;
    378   1.1   thorpej 	wc.wc_count = 0;
    379   1.1   thorpej 
    380   1.1   thorpej 	if (ioctl(fd, WDOGIOC_GWDOGS, &wc) == -1)
    381  1.14    dyoung 		err(EXIT_FAILURE, "ioctl WDOGIOC_GWDOGS for count");
    382   1.1   thorpej 
    383   1.1   thorpej 	count = wc.wc_count;
    384   1.1   thorpej 	if (count == 0) {
    385   1.1   thorpej 		printf("No watchdog timers present.\n");
    386   1.1   thorpej 		goto out;
    387   1.1   thorpej 	}
    388   1.1   thorpej 
    389   1.1   thorpej 	buf = malloc(count * WDOG_NAMESIZE);
    390   1.1   thorpej 	if (buf == NULL)
    391  1.14    dyoung 		err(EXIT_FAILURE, "malloc %d byte for watchdog names",
    392   1.1   thorpej 		    count * WDOG_NAMESIZE);
    393   1.1   thorpej 
    394   1.1   thorpej 	wc.wc_names = buf;
    395   1.1   thorpej 	if (ioctl(fd, WDOGIOC_GWDOGS, &wc) == -1)
    396  1.14    dyoung 		err(EXIT_FAILURE, "ioctl WDOGIOC_GWDOGS for names");
    397   1.1   thorpej 
    398   1.1   thorpej 	count = wc.wc_count;
    399   1.1   thorpej 	if (count == 0) {
    400   1.1   thorpej 		printf("No watchdog timers present.\n");
    401   1.1   thorpej 		free(buf);
    402   1.1   thorpej 		goto out;
    403   1.1   thorpej 	}
    404   1.1   thorpej 
    405   1.1   thorpej 	printf("Available watchdog timers:\n");
    406   1.1   thorpej 	for (i = 0, cp = buf; i < count; i++, cp += WDOG_NAMESIZE) {
    407   1.1   thorpej 		cp[WDOG_NAMESIZE - 1] = '\0';
    408   1.9    itojun 		strlcpy(wm.wm_name, cp, sizeof(wm.wm_name));
    409   1.1   thorpej 
    410   1.1   thorpej 		if (ioctl(fd, WDOGIOC_GMODE, &wm) == -1)
    411  1.13  drochner 			continue;
    412  1.13  drochner 		mode = wm.wm_mode & WDOG_MODE_MASK;
    413  1.13  drochner 		if (mode == WDOG_MODE_UTICKLE) {
    414   1.1   thorpej 			if (ioctl(fd, WDOGIOC_GTICKLER, &tickler) == -1)
    415   1.1   thorpej 				tickler = (pid_t) -1;
    416   1.1   thorpej 		}
    417   1.1   thorpej 
    418   1.1   thorpej 		printf("\t%s, %u second period", cp, wm.wm_period);
    419  1.13  drochner 		if (mode != WDOG_MODE_DISARMED) {
    420  1.13  drochner 			switch(mode) {
    421  1.14    dyoung 			case WDOG_MODE_KTICKLE:
    422  1.14    dyoung 				printf(" [armed, kernel tickle");
    423  1.14    dyoung 				break;
    424  1.14    dyoung 			case WDOG_MODE_UTICKLE:
    425  1.14    dyoung 				printf(" [armed, user tickle");
    426  1.14    dyoung 				if (tickler != (pid_t) -1)
    427  1.14    dyoung 					printf(", pid %d", tickler);
    428  1.14    dyoung 				break;
    429  1.14    dyoung 			case WDOG_MODE_ETICKLE:
    430  1.14    dyoung 				printf(" [armed, external tickle");
    431  1.14    dyoung 				break;
    432  1.11       smb 			}
    433   1.1   thorpej 			printf("]");
    434   1.1   thorpej 		}
    435   1.1   thorpej 		printf("\n");
    436   1.1   thorpej 	}
    437   1.1   thorpej  out:
    438  1.14    dyoung 	(void)close(fd);
    439   1.1   thorpej }
    440   1.1   thorpej 
    441  1.20     joerg static void
    442   1.1   thorpej usage(void)
    443   1.1   thorpej {
    444  1.12       wiz 
    445  1.10      jmmv 	fprintf(stderr, "usage: %s\n", getprogname());
    446  1.12       wiz 	fprintf(stderr, "       %s -d\n", getprogname());
    447  1.11       smb 	fprintf(stderr, "       %s -e [-A] [-p seconds] timer\n",
    448  1.11       smb 	    getprogname());
    449   1.7       cgd 	fprintf(stderr, "       %s -k [-A] [-p seconds] timer\n",
    450   1.7       cgd 	    getprogname());
    451  1.12       wiz 	fprintf(stderr, "       %s -t\n", getprogname());
    452   1.7       cgd 	fprintf(stderr, "       %s -u [-A] [-p seconds] timer\n",
    453   1.7       cgd 	    getprogname());
    454  1.17       wiz 	fprintf(stderr, "       %s -x [-A] [-p seconds] timer\n",
    455  1.17       wiz 	    getprogname());
    456   1.1   thorpej 
    457   1.1   thorpej 	exit(1);
    458   1.1   thorpej }
    459