2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 * Copyright (C) 2009 Jo-Philipp Wich <jow@openwrt.org>
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
36 #include <linux/types.h>
37 #include <linux/watchdog.h>
40 #include "wireless.22.h"
43 /* Watchdog poll interval */
44 #define BASE_INTERVAL 5
46 /* Action interval (N * BASE_INTERVAL) */
47 #define ACTION_INTERVAL 6
52 /* How to call myself in the logs */
53 #define SYSLOG_IDENT "Freifunk Watchdog"
55 /* Process error action */
56 #define PROC_ACTION curr_proc->initscript, curr_proc->initscript, "restart"
58 /* Wifi error action */
59 #define WIFI_ACTION "/sbin/wifi", "/sbin/wifi"
62 #define WATCH_DEVICE "/dev/watchdog"
63 #define WATCH_SHUTDOWN 'V'
64 #define WATCH_KEEPALIVE '\0'
66 /* System load error action and treshold */
67 #define LOAD_TRESHOLD 15.00
68 #define LOAD_ACTION "/sbin/reboot", "/sbin/reboot"
70 /* Fallback binary name (passed by makefile) */
72 #define BINARY "ffwatchd"
76 /* ifname/bssid/channel tuples */
81 struct wifi_tuple *next;
84 /* structure to hold tuple-list and uci context during iteration */
85 struct uci_wifi_iface_itr_ctx {
86 struct wifi_tuple *list;
87 struct uci_context *ctx;
90 typedef struct wifi_tuple wifi_tuple_t;
93 /* process name/exec tuples */
94 struct process_tuple {
95 char process[PATH_MAX + 1];
96 char initscript[PATH_MAX + 1];
98 struct process_tuple *next;
101 /* structure to hold tuple-list and uci context during iteration */
102 struct uci_process_itr_ctx {
103 struct process_tuple *list;
104 struct uci_context *ctx;
107 typedef struct process_tuple process_tuple_t;
110 /* ioctl() helper (stolen from iwlib) */
112 iw_ioctl(int skfd, /* Socket to the kernel */
113 const char * ifname, /* Device name */
114 int request, /* WE ID */
115 struct iwreq * pwrq) /* Fixed part of the request */
117 /* Set device name */
118 strncpy(pwrq->ifr_ifrn.ifrn_name, ifname, 16);
121 return(ioctl(skfd, request, pwrq));
124 /* fork() & execl() helper */
130 syslog(LOG_CRIT, "Unable to fork child: %s", \
136 syslog(LOG_CRIT, "Unable to execute action: %s", \