annotate vd_watchdog/vd_watchdog.c @ 3:60a234c9c03f

Add 2-clause BSD license
author Thinker K.F. Li <thinker@branda.to>
date Tue, 08 Jul 2008 12:13:58 +0800
parents 89e9d591748d
children 5fa5e5199d1a
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>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 #include <fcntl.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 #include <sys/ioctl.h>
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
31 #include <sys/types.h>
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 #include "vordog.h"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 #define DEVNAME "/dev/vordog0"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 #define PROG "vd_watchdog"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
37 static int unit_factors[] = {0, 1, 60, 3600};
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
38
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 static void
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
40 watchdog(int timeout, int unit) {
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 struct vordog_cfg cfg;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 int intval;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 int r;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 int fd;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 fd = open(DEVNAME, O_RDWR);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 if(fd == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 }
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
51
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
52 cfg.init_val = timeout;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
53 cfg.unit = unit;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 r = ioctl(fd, VDCTL_ENABLE, &cfg);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 if(r == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 }
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
59
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
60 /* reset timer periodically */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
61 intval = timeout * unit_factors[unit];
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 while(1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 sleep(intval);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 r = ioctl(fd, VDCTL_RESET);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 if(r == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 }
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
69 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
70 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
71
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
72 static void
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
73 daemonize(void) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
74 pid_t pid;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
75
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
76 pid = fork();
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
77 if(pid == -1) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
78 perror("fork");
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
79 exit(1);
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 }
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
81
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
82 if(pid != 0)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
83 exit(0); /* parent */
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 /* child process */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
86 pid = setsid();
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
87 if(pid == -1) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
88 perror("setsid");
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
89 exit(1);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
90 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
91
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
92 close(STDOUT_FILENO);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
93 close(STDOUT_FILENO);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
94 /* close(STDERR_FILENO); */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
95 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
96
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
97 static void
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
98 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
99 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
100 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
101 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
102 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
103 fprintf(stderr,
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
104 "\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
105 "\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
106 "\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
107 "\t\t(note: 1~255)\n");
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
111 static char *unit_names[] = {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
112 "* 4ms",
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
113 "seconds",
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
114 "minutes",
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
115 "hours"
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
116 };
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
117
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 int
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
119 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
120 int timeout, unit;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
121 int ch;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
122 const char *prog = argv[0];
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
123
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
124 timeout = 30; /* default: 30s */
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
125 unit = VDT_1S;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
126
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
127 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
128 switch(ch) {
3
60a234c9c03f Add 2-clause BSD license
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
129 /* 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
130 case 's':
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
131 unit = VDT_1S;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
132 break;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
133 case 'M':
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
134 unit = VDT_1M;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
135 break;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
136 case 'H':
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
137 unit = VDT_1H;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
138 break;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
139 case '?':
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
140 default:
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
141 usage(prog);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
142 exit(1);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
143 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
144 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
145 argc -= optind;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
146 argv += optind;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
147
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
148 if(argc != 1 && argc != 0) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
149 usage(prog);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
150 return 1;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
151 }
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)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
154 timeout = atoi(argv[0]);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
155 if(timeout < 1 || timeout > 255) {
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
156 usage(prog);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
157 return 1;
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
158 }
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
159
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
160 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
161 timeout, unit_names[unit]);
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
162
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
163 daemonize();
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
164 watchdog(timeout, unit);
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 }