diff options
Diffstat (limited to 'contrib/package/freifunk-watchdog/src/watchdog.h')
-rw-r--r-- | contrib/package/freifunk-watchdog/src/watchdog.h | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/contrib/package/freifunk-watchdog/src/watchdog.h b/contrib/package/freifunk-watchdog/src/watchdog.h new file mode 100644 index 0000000000..d11396f807 --- /dev/null +++ b/contrib/package/freifunk-watchdog/src/watchdog.h @@ -0,0 +1,107 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org> + */ + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdint.h> +#include <stdlib.h> +#include <syslog.h> +#include <ctype.h> +#include <errno.h> +#include <dirent.h> +#include <fcntl.h> +#include <math.h> +#include <time.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <sys/socket.h> + +#include "ucix.h" +#include "wireless.22.h" + + +/* Check interval */ +#define INTERVAL 30 + +/* How to call myself in the logs */ +#define SYSLOG_IDENT "Freifunk Watchdog" + +/* Wifi error action */ +#define WIFI_ACTION "/sbin/wifi", "/sbin/wifi" + +/* Crond error action */ +#define CRON_ACTION "/etc/init.d/cron", "/etc/init.d/cron", "restart" + +/* Fallback binary name (passed by makefile) */ +#ifndef BINARY +#define BINARY "ffwatchd" +#endif + + +/* ifname/bssid/channel tuples */ +struct wifi_tuple { + char ifname[16]; + char bssid[18]; + int channel; + struct wifi_tuple *next; +}; + +/* structure to hold tuple-list and uci context during iteration */ +struct uci_itr_ctx { + struct wifi_tuple *list; + struct uci_context *ctx; +}; + +typedef struct wifi_tuple wifi_tuple_t; + + +/* ioctl() helper (stolen from iwlib) */ +static inline int +iw_ioctl(int skfd, /* Socket to the kernel */ + const char * ifname, /* Device name */ + int request, /* WE ID */ + struct iwreq * pwrq) /* Fixed part of the request */ +{ + /* Set device name */ + strncpy(pwrq->ifr_ifrn.ifrn_name, ifname, 16); + + /* Do the request */ + return(ioctl(skfd, request, pwrq)); +} + +/* fork() & execl() helper */ +#define EXEC(x) \ + do { \ + switch(fork()) \ + { \ + case -1: \ + syslog(LOG_CRIT, "Unable to fork child: %s", \ + strerror(errno)); \ + \ + break; \ + \ + case 0: \ + execl(x, NULL); \ + syslog(LOG_CRIT, "Unable to execute action: %s", \ + strerror(errno)); \ + \ + return 1; \ + } \ + } while(0) + |