annotate vd_watchdog/vd_watchdog.c @ 9:b4f4a69ea86a v20080708

clear error after event handler for watchdog(9)
author Thinker K.F. Li <thinker@branda.to>
date Tue, 08 Jul 2008 20:29:07 +0800
parents 5fa5e5199d1a
children
rev   line source
3
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
1 /*-
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
2 * Copyright (c) 2008 Kueifong Li <thinker@branda.to>.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
3 * All rights reserved.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
4 *
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
5 * Redistribution and use in source and binary forms, with or without
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
6 * modification, are permitted provided that the following conditions
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
7 * are met:
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
9 * notice, this list of conditions and the following disclaimer.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
12 * documentation and/or other materials provided with the distribution.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
13 *
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
15 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
16 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
24 * POSSIBILITY OF SUCH DAMAGE.
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
25 */
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 #include <stdio.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 #include <stdlib.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 #include <unistd.h>
4
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
29 #include <string.h>
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 #include <fcntl.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 #include <sys/ioctl.h>
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
32 #include <sys/types.h>
4
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
33 #include <libgen.h>
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 #include "vordog.h"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 #define DEVNAME "/dev/vordog0"
4
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
37 #define PROG prog
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
39 static int unit_factors[] = {0, 1, 60, 3600};
4
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
40 static const char *prog = NULL;
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
41
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 static void
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
43 watchdog(int timeout, int unit) {
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 struct vordog_cfg cfg;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 int intval;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 int r;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 int fd;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 fd = open(DEVNAME, O_RDWR);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 if(fd == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 }
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
54
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
55 cfg.init_val = timeout;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
56 cfg.unit = unit;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 r = ioctl(fd, VDCTL_ENABLE, &cfg);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 if(r == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 }
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
62
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
63 /* reset timer periodically */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
64 intval = timeout * unit_factors[unit];
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 while(1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 sleep(intval);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 r = ioctl(fd, VDCTL_RESET);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 if(r == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 }
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
72 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
73 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
74
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
75 static void
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
76 daemonize(void) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
77 pid_t pid;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
78
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
79 pid = fork();
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
80 if(pid == -1) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
81 perror("fork");
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
82 exit(1);
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 }
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
84
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
85 if(pid != 0)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
86 exit(0); /* parent */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
87
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
88 /* child process */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
89 pid = setsid();
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
90 if(pid == -1) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
91 perror("setsid");
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
92 exit(1);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
93 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
94
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
95 close(STDOUT_FILENO);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
96 close(STDOUT_FILENO);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
97 /* close(STDERR_FILENO); */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
98 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
99
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
100 static void
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
101 usage(const char *prog) {
2
89e9d591748d Fix bug of usage for vd_watchdog, and add Makefile
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
102 fprintf(stderr, "Usage: %s [-msMH] <timeout>\n", prog);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
103 fprintf(stderr, "\t-s\tcount in seconds.\n");
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
104 fprintf(stderr, "\t-M\tcount in minutes.\n");
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
105 fprintf(stderr, "\t-m\tcount in hours.\n");
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
106 fprintf(stderr,
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
107 "\t<timeout> is interval between periodically reset of\n"
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
108 "\t\twatchdog timer, or the system would be reseted without\n"
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
109 "\t\treseting timer for 4 times. (default: 30s)\n"
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
110 "\t\t(note: 1~255)\n");
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
114 static char *unit_names[] = {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
115 "* 4ms",
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
116 "seconds",
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
117 "minutes",
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
118 "hours"
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
119 };
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
120
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 int
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
122 main(int argc, char * const argv[]) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
123 int timeout, unit;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
124 int ch;
4
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
125
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
126 prog = basename(argv[0]); /* name of binary file. */
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
127 prog = strdup(prog);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
128
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
129 timeout = 30; /* default: 30s */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
130 unit = VDT_1S;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
131
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
132 while((ch = getopt(argc, argv, "")) != -1) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
133 switch(ch) {
3
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
134 /* 4ms unit is not used for too short to sleep. */
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
135 case 's':
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
136 unit = VDT_1S;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
137 break;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
138 case 'M':
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
139 unit = VDT_1M;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
140 break;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
141 case 'H':
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
142 unit = VDT_1H;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
143 break;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
144 case '?':
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
145 default:
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
146 usage(prog);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
147 exit(1);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
148 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
149 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
150 argc -= optind;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
151 argv += optind;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
152
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
153 if(argc != 1 && argc != 0) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
154 usage(prog);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
155 return 1;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
156 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
157
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
158 if(argc == 1)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
159 timeout = atoi(argv[0]);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
160 if(timeout < 1 || timeout > 255) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
161 usage(prog);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
162 return 1;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
163 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
164
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
165 printf("Reset watchdog timer every %d %s\n",
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
166 timeout, unit_names[unit]);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
167
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
168 daemonize();
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
169 watchdog(timeout, unit);
4
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
170
5fa5e5199d1a use basename of binary file in messages.
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
171 free((void *)prog);
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 }