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 <xm@subsignal.org>
33 #include <sys/ioctl.h>
34 #include <sys/socket.h>
35 #include <linux/types.h>
36 #include <linux/watchdog.h>
39 #include "wireless.22.h"
48 /* How to call myself in the logs */
49 #define SYSLOG_IDENT "Freifunk Watchdog"
51 /* Wifi error action */
52 #define WIFI_ACTION "/sbin/wifi", "/sbin/wifi"
54 /* Crond error action */
55 #define CRON_ACTION "/etc/init.d/cron", "/etc/init.d/cron", "restart"
57 /* SSHd error action */
58 #define SSHD_ACTION "/etc/init.d/dropbear", "/etc/init.d/dropbear", "restart"
61 #define WATCH_DEVICE "/dev/watchdog"
62 #define WATCH_SHUTDOWN 'V'
63 #define WATCH_KEEPALIVE '\0'
65 /* System load error action and treshold */
66 #define LOAD_TRESHOLD 5.00
67 #define LOAD_ACTION "/sbin/reboot"
69 /* Fallback binary name (passed by makefile) */
71 #define BINARY "ffwatchd"
75 /* ifname/bssid/channel tuples */
80 struct wifi_tuple *next;
83 /* structure to hold tuple-list and uci context during iteration */
85 struct wifi_tuple *list;
86 struct uci_context *ctx;
89 typedef struct wifi_tuple wifi_tuple_t;
92 /* ioctl() helper (stolen from iwlib) */
94 iw_ioctl(int skfd, /* Socket to the kernel */
95 const char * ifname, /* Device name */
96 int request, /* WE ID */
97 struct iwreq * pwrq) /* Fixed part of the request */
100 strncpy(pwrq->ifr_ifrn.ifrn_name, ifname, 16);
103 return(ioctl(skfd, request, pwrq));
106 /* fork() & execl() helper */
112 syslog(LOG_CRIT, "Unable to fork child: %s", \
119 syslog(LOG_CRIT, "Unable to execute action: %s", \