diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-02-23 23:31:26 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-02-23 23:31:26 +0200 |
commit | b42866f337ced2942eca3d02a23813536c108452 (patch) | |
tree | 94f11eded557ee16fa20b8bf359d468e10ef8b44 /src/config.c | |
parent | d9dfecfa5f1d8e217f1f8a05a261afa5b5f4d6cd (diff) | |
download | ping903-b42866f337ced2942eca3d02a23813536c108452.tar.gz ping903-b42866f337ced2942eca3d02a23813536c108452.tar.bz2 |
Save local additions in a local ip list file. Read it at startup.
* src/config.c (file_read_ip_list): New function.
* src/defs.h (LOCAL_IP_LIST_FILE): New definition.
* src/ping903.h (file_read_ip_list): New proto.
* src/pinger.c (conf_hostping_count)
(hostping_updated): New static variables.
(hostping_add,hostping_delete): Raise the hostping_updated flag.
(p903_init): Read in the local ip-list file, if it exists.
Clear hostping_updated.
(p903_scheduler): Save changes to the local ip-list file, if
hostping_updated is set.
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/config.c b/src/config.c index f2376a5..8a5028a 100644 --- a/src/config.c +++ b/src/config.c @@ -47,12 +47,8 @@ static int cf_ip_list_parse(union cf_callback_arg *arg, void *data) { FILE *fp; - char buf[1024]; - unsigned ln = 0; - int skip_to_eol = 0; - int ret = CF_RET_OK; - struct addrinfo hints; - + int rc; + fp = fopen(arg->input.val, "r"); if (!fp) { error("%s:%d: can't open file %s: %s", @@ -60,7 +56,20 @@ cf_ip_list_parse(union cf_callback_arg *arg, void *data) arg->input.val, strerror(errno)); exit(1); } - + rc = file_read_ip_list(fp, arg->input.val); + fclose(fp); + return rc; +} + +int +file_read_ip_list(FILE *fp, char const *fname) +{ + char buf[1024]; + unsigned ln = 0; + int skip_to_eol = 0; + int ret = CF_RET_OK; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_protocol = IPPROTO_TCP; @@ -84,7 +93,7 @@ cf_ip_list_parse(union cf_callback_arg *arg, void *data) if (buf[len-1] == '\n') buf[--len] = 0; else if (!feof(fp)) { - error("%s:%d: line too long", arg->input.val, ln); + error("%s:%d: line too long", fname, ln); skip_to_eol = 1; ret = CF_RET_FAIL; continue; @@ -102,14 +111,13 @@ cf_ip_list_parse(union cf_callback_arg *arg, void *data) rc = getaddrinfo(p, NULL, &hints, &res); if (rc) { - error("%s:%d: invalid IP address", arg->input.val, ln); + error("%s:%d: invalid IP address", fname, ln); ret = CF_RET_FAIL; continue; } hostping_add(p, res->ai_addr, res->ai_addrlen); freeaddrinfo(res); } - fclose(fp); return ret; } |