This source file includes following definitions.
- watchdog_fire
- softdog_open
- softdog_release
- softdog_write
- watchdog_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <linux/config.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/fs.h>
25 #include <linux/mm.h>
26 #include <linux/miscdevice.h>
27
28 #define WATCHDOG_MINOR 130
29 #define TIMER_MARGIN (60*HZ)
30
31
32
33
34
35 struct timer_list watchdog_ticktock;
36 static int timer_alive = 0;
37
38
39
40
41
42
43 static void watchdog_fire(unsigned long data)
44 {
45 extern void hard_reset_now(void);
46 hard_reset_now();
47 printk("WATCHDOG: Reboot didn't ?????\n");
48 }
49
50
51
52
53
54 static int softdog_open(struct inode *inode, struct file *file)
55 {
56 if(timer_alive)
57 return -EBUSY;
58
59
60
61 watchdog_ticktock.expires=jiffies+TIMER_MARGIN;
62 add_timer(&watchdog_ticktock);
63 timer_alive++;
64 return 0;
65 }
66
67 static void softdog_release(struct inode *inode, struct file *file)
68 {
69
70
71
72 #ifndef CONFIG_WATCHDOG_NOWAYOUT
73 del_timer(&watchdog_ticktock);
74 #endif
75 timer_alive=0;
76 }
77
78 static int softdog_write(struct inode *inode, struct file *file, const char *data, int len)
79 {
80
81
82
83 del_timer(&watchdog_ticktock);
84 watchdog_ticktock.expires=jiffies+TIMER_MARGIN;
85 add_timer(&watchdog_ticktock);
86 return 1;
87 }
88
89
90
91
92
93 void watchdog_init(void)
94 {
95 static struct file_operations softdog_fops=
96 {
97 NULL,
98 NULL,
99 softdog_write,
100 NULL,
101 NULL,
102 NULL,
103 NULL,
104 softdog_open,
105 softdog_release,
106 NULL,
107 NULL
108 };
109 static struct miscdevice softdog_mouse={
110 WATCHDOG_MINOR,
111 "softdog",
112 &softdog_fops
113 };
114
115 misc_register(&softdog_mouse);
116 init_timer(&watchdog_ticktock);
117 watchdog_ticktock.function=watchdog_fire;
118 printk("Software Watchdog Timer: 0.03\n");
119 }