Mercurial > vordog
comparison vd_watchdog/vd_watchdog.c @ 4:5fa5e5199d1a
use basename of binary file in messages.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 08 Jul 2008 12:21:12 +0800 |
parents | 60a234c9c03f |
children |
comparison
equal
deleted
inserted
replaced
3:60a234c9c03f | 4:5fa5e5199d1a |
---|---|
24 * POSSIBILITY OF SUCH DAMAGE. | 24 * POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 #include <stdio.h> | 26 #include <stdio.h> |
27 #include <stdlib.h> | 27 #include <stdlib.h> |
28 #include <unistd.h> | 28 #include <unistd.h> |
29 #include <string.h> | |
29 #include <fcntl.h> | 30 #include <fcntl.h> |
30 #include <sys/ioctl.h> | 31 #include <sys/ioctl.h> |
31 #include <sys/types.h> | 32 #include <sys/types.h> |
33 #include <libgen.h> | |
32 #include "vordog.h" | 34 #include "vordog.h" |
33 | 35 |
34 #define DEVNAME "/dev/vordog0" | 36 #define DEVNAME "/dev/vordog0" |
35 #define PROG "vd_watchdog" | 37 #define PROG prog |
36 | 38 |
37 static int unit_factors[] = {0, 1, 60, 3600}; | 39 static int unit_factors[] = {0, 1, 60, 3600}; |
40 static const char *prog = NULL; | |
38 | 41 |
39 static void | 42 static void |
40 watchdog(int timeout, int unit) { | 43 watchdog(int timeout, int unit) { |
41 struct vordog_cfg cfg; | 44 struct vordog_cfg cfg; |
42 int intval; | 45 int intval; |
117 | 120 |
118 int | 121 int |
119 main(int argc, char * const argv[]) { | 122 main(int argc, char * const argv[]) { |
120 int timeout, unit; | 123 int timeout, unit; |
121 int ch; | 124 int ch; |
122 const char *prog = argv[0]; | 125 |
126 prog = basename(argv[0]); /* name of binary file. */ | |
127 prog = strdup(prog); | |
123 | 128 |
124 timeout = 30; /* default: 30s */ | 129 timeout = 30; /* default: 30s */ |
125 unit = VDT_1S; | 130 unit = VDT_1S; |
126 | 131 |
127 while((ch = getopt(argc, argv, "")) != -1) { | 132 while((ch = getopt(argc, argv, "")) != -1) { |
160 printf("Reset watchdog timer every %d %s\n", | 165 printf("Reset watchdog timer every %d %s\n", |
161 timeout, unit_names[unit]); | 166 timeout, unit_names[unit]); |
162 | 167 |
163 daemonize(); | 168 daemonize(); |
164 watchdog(timeout, unit); | 169 watchdog(timeout, unit); |
170 | |
171 free((void *)prog); | |
165 return 0; | 172 return 0; |
166 } | 173 } |