# HG changeset patch # User Mychaela Falconia # Date 1665127897 28800 # Node ID 2b03d2584f88136aa52343af83be3d1063492af2 # Parent 765991f42d86ffe97f29a7b6cd2baf1a8c951f79 liboutrt: implement refresh diff -r 765991f42d86 -r 2b03d2584f88 liboutrt/Makefile --- a/liboutrt/Makefile Thu Oct 06 23:15:26 2022 -0800 +++ b/liboutrt/Makefile Thu Oct 06 23:31:37 2022 -0800 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= readbin.o +OBJS= readbin.o refresh.o LIB= liboutrt.a all: ${LIB} diff -r 765991f42d86 -r 2b03d2584f88 liboutrt/refresh.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboutrt/refresh.c Thu Oct 06 23:31:37 2022 -0800 @@ -0,0 +1,57 @@ +/* + * themwi-sip-out and possibly other similar long-running processes in + * the future need to be able to pick up updates to the outbound call + * routing database without being restarted. Whenever they need to + * consult the route db when handling a new call setup, they will call + * refresh_out_routes_db(), which does a stat on the file, followed by + * a re-read if the file has changed. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "../include/out_routes.h" + +extern char outrt_pathname[]; +extern struct stat outrt_file_stat; +extern struct sip_out_dest *outrt_dest_array; +extern struct inn_route *outrt_inn_array; +extern struct special_num_route *outrt_spec_array; + +refresh_out_routes_db() +{ + int rc; + struct stat st; + + rc = stat(outrt_pathname, &st); + if (rc < 0) { + syslog(LOG_CRIT, "unable to stat %s for refresh: %m", + outrt_pathname); + return(-1); + } + if (st.st_mtime == outrt_file_stat.st_mtime && + st.st_ctime == outrt_file_stat.st_ctime && + st.st_size == outrt_file_stat.st_size) + return(0); + free(outrt_dest_array); + if (outrt_inn_array) { + free(outrt_inn_array); + outrt_inn_array = 0; + } + if (outrt_spec_array) { + free(outrt_spec_array); + outrt_spec_array = 0; + } + rc = read_out_routes_db(); + if (rc < 0) { + syslog(LOG_CRIT, "error reading %s on refresh!", + outrt_pathname); + exit(1); + } + return(1); +}