diff -urN asterisk-1.2.13.orig/res/res_watchdog.c asterisk-1.2.13/res/res_watchdog.c --- asterisk-1.2.13.orig/res/res_watchdog.c 1970-01-01 01:00:00.000000000 +0100 +++ asterisk-1.2.13/res/res_watchdog.c 2006-10-19 11:11:39.000000000 +0200 @@ -0,0 +1,149 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Resource to make watchdogs happy + * + * Copyright (C) 2005, Junghanns.NET GmbH + * + * Klaus-Peter Junghanns + * + * This program is free software, distributed under the terms of + * the GNU General Public License + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct watchdog_pvt *watchdogs = NULL; + +STANDARD_LOCAL_USER; + +LOCAL_USER_DECL; + +typedef struct watchdog_pvt { + char device[80]; + int fd; + int type; + int interval; + pthread_t watchdog_thread; + struct watchdog_pvt *next; +} watchdog_pvt; + +static void *do_watchdog_thread(void *data) { + struct watchdog_pvt *woof = (struct watchdog_pvt *)data; + for (;;) { + if (woof->fd) { + write(woof->fd, "PING\n", 1); + } + usleep(woof->interval * 1000); + } + return NULL; +} + + +int load_module(void) +{ + int res = 0; + char *cat, *utype, *udevice, *uinterval; + struct ast_config *cfg; + struct watchdog_pvt *woof = NULL; + + cfg = ast_config_load("watchdog.conf"); + if (cfg) { + cat = ast_category_browse(cfg, NULL); + while(cat) { + cat = ast_category_browse(cfg, cat); + utype = ast_variable_retrieve(cfg, cat, "type"); +/* if (utype) { + ast_log(LOG_NOTICE, "type = %s\n", utype); + } */ + udevice = ast_variable_retrieve(cfg, cat, "device"); +/* if (udevice) { + ast_log(LOG_NOTICE, "device = %s\n", udevice); + } */ + uinterval = ast_variable_retrieve(cfg, cat, "interval"); +/* if (uinterval) { + ast_log(LOG_NOTICE, "interval = %s\n", uinterval); + } */ + if (uinterval && udevice && utype) { + woof = malloc(sizeof(struct watchdog_pvt)); + if (!woof) { + ast_log(LOG_ERROR, "unable to malloc!\n"); + return -1; + } + memset(woof, 0x0, sizeof(struct watchdog_pvt)); + strncpy(woof->device, udevice, sizeof(woof->device) - 1); + + woof->interval = atoi(uinterval);; + woof->next = watchdogs; + watchdogs = woof; + woof->fd = open(woof->device, O_WRONLY | O_SYNC); + if (woof->fd) { + if (!strncmp(utype, "isdnguard", sizeof(utype))) { + woof->type = 1; + write(woof->fd, "START\n", 6); + } + ast_pthread_create(&woof->watchdog_thread, NULL, do_watchdog_thread, woof); + } else { + ast_log(LOG_WARNING, "error opening watchdog device %s !\n", woof->device); + } + } + } + ast_config_destroy(cfg); + } + return res; +} + + +int unload_module(void) +{ + struct watchdog_pvt *dogs, *woof; + STANDARD_HANGUP_LOCALUSERS; + dogs = watchdogs; + while (dogs) { + pthread_cancel(dogs->watchdog_thread); + close(dogs->fd); + woof = dogs->next; + free(dogs); + dogs = woof; + } + return 0; +} + +char *description(void) +{ + return "Watchdog Resource"; +} + +int usecount(void) +{ + return 1; +} + +char *key() +{ + return ASTERISK_GPL_KEY; +} diff -urN asterisk-1.2.13.orig/configs/watchdog.conf.sample asterisk-1.2.13/configs/watchdog.conf.sample --- asterisk-1.2.13.orig/configs/watchdog.conf.sample 1970-01-01 01:00:00.000000000 +0100 +++ asterisk-1.2.13/configs/watchdog.conf.sample 2006-10-19 11:11:39.000000000 +0200 @@ -0,0 +1,22 @@ +; +; Configuration file for res_watchdog +; +; type = isdnguard | watchdog +; device = /dev/... +; interval = interval to trigger the watchdog in ms + +;[ISDNguard-direct] +;type = isdnguard +;device = /dev/ttyS0 +;interval = 200 + +;[ISDNguard-with-daemon] +;type = isdnguard +;device = /var/run/guard.ctl +;interval = 200 + +;[kernel_watchdog] +;type = watchdog +;device = /dev/watchdog +;interval = 100 + diff -urN asterisk-1.2.13.orig/res/Makefile asterisk-1.2.13/res/Makefile --- asterisk-1.2.13.orig/res/Makefile 2005-11-29 19:24:39.000000000 +0100 +++ asterisk-1.2.13/res/Makefile 2006-10-19 11:11:39.000000000 +0200 @@ -11,7 +11,7 @@ # the GNU General Public License # -MODS=res_indications.so res_monitor.so res_adsi.so res_agi.so res_features.so +MODS=res_indications.so res_monitor.so res_adsi.so res_agi.so res_features.so res_watchdog.so ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),) ifneq (${OSARCH},FreeBSD)