From a834db5dc933a4b48c8323ae3e490448a86b448f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 4 Jul 2018 13:59:24 +0200 Subject: use private bind mounts for pacserve, remove pacdbserve We want just one service to serve database files and package archives. Private bind mounts make both available to pacserve. This alse removes some complexity in pacredir. --- pacredir.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pacredir.h') diff --git a/pacredir.h b/pacredir.h index fa26dbd..bddab74 100644 --- a/pacredir.h +++ b/pacredir.h @@ -66,7 +66,6 @@ struct hosts { char address[AVAHI_ADDRESS_STR_MAX]; /* online status and bad time for services */ struct services pacserve; - struct services pacdbserve; /* pointer to next struct element */ struct hosts * next; }; @@ -100,7 +99,7 @@ int write_log(FILE *stream, const char *format, ...); /* get_fqdn */ char * get_fqdn(const char * hostname, const char * domainname); /* get_url */ -char * get_url(const char * hostname, AvahiProtocol proto, const char * address, const uint16_t port, const char * uri); +char * get_url(const char * hostname, AvahiProtocol proto, const char * address, const uint16_t port, const uint8_t dbfile, const char * uri); /* add_host */ int add_host(const char * host, AvahiProtocol proto, const char * address, const uint16_t port, const char * type); -- cgit v1.2.3-54-g00ecf From b8aeafb0377321d8443fc36a7a1ae660f407cfd2 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 5 Jul 2018 11:58:24 +0200 Subject: drop 'struct services' Now that we have just one service this can be merged with 'struct hosts'. --- pacredir.c | 50 ++++++++++++++++++++++++-------------------------- pacredir.h | 28 ++++++++++------------------ 2 files changed, 34 insertions(+), 44 deletions(-) (limited to 'pacredir.h') diff --git a/pacredir.c b/pacredir.c index 76dc52d..05caf1d 100644 --- a/pacredir.c +++ b/pacredir.c @@ -95,10 +95,10 @@ int add_host(const char * host, AvahiProtocol proto, const char * address, const tmphosts->proto = AVAHI_PROTO_UNSPEC; *tmphosts->address = 0; - tmphosts->pacserve.port = 0; - tmphosts->pacserve.online = 0; - tmphosts->pacserve.badtime = 0; - tmphosts->pacserve.badcount = 0; + tmphosts->port = 0; + tmphosts->online = 0; + tmphosts->badtime = 0; + tmphosts->badcount = 0; tmphosts->next = malloc(sizeof(struct hosts)); tmphosts->next->host = NULL; @@ -109,13 +109,12 @@ update: if (address != NULL) memcpy(tmphosts->address, address, AVAHI_ADDRESS_STR_MAX); - tmphosts->pacserve.online = 1; - tmphosts->pacserve.port = port; - request.service = &tmphosts->pacserve; + tmphosts->online = 1; + tmphosts->port = port; /* do a first request and let get_http_code() set the bad status */ - request.host = tmphosts->host; - request.url = get_url(request.host, tmphosts->proto, tmphosts->address, request.service->port, 0, ""); + request.host = tmphosts; + request.url = get_url(request.host->host, request.host->proto, request.host->address, request.host->port, 0, ""); request.http_code = 0; request.last_modified = 0; get_http_code(&request); @@ -133,7 +132,7 @@ int remove_host(const char * host, AvahiProtocol proto, const char * type) { if (verbose > 0) write_log(stdout, "Marking service %s on host %s (%s) offline\n", type, host, avahi_proto_to_string(proto)); - tmphosts->pacserve.online = 0; + tmphosts->online = 0; break; } tmphosts = tmphosts->next; @@ -303,16 +302,16 @@ static void * get_http_code(void * data) { /* perform the request */ if ((res = curl_easy_perform(curl)) != CURLE_OK) { write_log(stderr, "Could not connect to server %s on port %d: %s\n", - request->host, request->service->port, + request->host->host, request->host->port, *errbuf != 0 ? errbuf : curl_easy_strerror(res)); request->http_code = 0; request->last_modified = 0; - request->service->badtime = tv.tv_sec; - request->service->badcount++; + request->host->badtime = tv.tv_sec; + request->host->badcount++; return NULL; } else { - request->service->badtime = 0; - request->service->badcount = 0; + request->host->badtime = 0; + request->host->badcount = 0; } /* get http status code */ @@ -426,11 +425,11 @@ static int ahc_echo(void * cls, /* try to find a server with most recent file */ while (tmphosts->host != NULL) { - struct services *service = &tmphosts->pacserve; - time_t badtime = service->badtime + service->badcount * BADTIME; + struct hosts * host = tmphosts; + time_t badtime = host->badtime + host->badcount * BADTIME; /* skip host if offline or had a bad request within last BADTIME seconds */ - if (service->online == 0) { + if (host->online == 0) { if (verbose > 0) write_log(stdout, "Service %s on host %s is offline, skipping\n", PACSERVE, tmphosts->host); @@ -472,9 +471,8 @@ static int ahc_echo(void * cls, request = requests[req_count]; /* prepare request struct */ - request->host = tmphosts->host; - request->service = &(tmphosts->pacserve); - request->url = get_url(tmphosts->host, tmphosts->proto, tmphosts->address, request->service->port, dbfile, basename); + request->host = tmphosts; + request->url = get_url(request->host->host, request->host->proto, request->host->address, request->host->port, dbfile, basename); request->http_code = 0; request->last_modified = 0; @@ -521,7 +519,7 @@ static int ahc_echo(void * cls, if (url != NULL) free(url); url = request->url; - host = request->host; + host = request->host->host; http_code = MHD_HTTP_OK; last_modified = request->last_modified; time_total = request->time_total; @@ -592,8 +590,8 @@ void sighup_callback(int signal) { write_log(stdout, "Received SIGHUP, resetting bad status for hosts.\n"); while (tmphosts->host != NULL) { - tmphosts->pacserve.badtime = 0; - tmphosts->pacserve.badcount = 0; + tmphosts->badtime = 0; + tmphosts->badcount = 0; tmphosts = tmphosts->next; } } @@ -655,8 +653,8 @@ int main(int argc, char ** argv) { /* allocate first struct element as dummy */ hosts = malloc(sizeof(struct hosts)); hosts->host = NULL; - hosts->pacserve.online = 0; - hosts->pacserve.badtime = 0; + hosts->online = 0; + hosts->badtime = 0; hosts->next = NULL; ignore_interfaces = malloc(sizeof(struct ignore_interfaces)); diff --git a/pacredir.h b/pacredir.h index bddab74..75017b7 100644 --- a/pacredir.h +++ b/pacredir.h @@ -44,18 +44,6 @@ #define PROGNAME "pacredir" -/* services */ -struct services { - /* network port */ - uint16_t port; - /* true if host/service is online */ - uint8_t online; - /* unix timestamp of last bad request */ - __time_t badtime; - /* count the number of bad requests */ - unsigned int badcount; -}; - /* hosts */ struct hosts { /* host name */ @@ -64,8 +52,14 @@ struct hosts { AvahiProtocol proto; /* resolved address */ char address[AVAHI_ADDRESS_STR_MAX]; - /* online status and bad time for services */ - struct services pacserve; + /* network port */ + uint16_t port; + /* true if host/service is online */ + uint8_t online; + /* unix timestamp of last bad request */ + __time_t badtime; + /* count the number of bad requests */ + unsigned int badcount; /* pointer to next struct element */ struct hosts * next; }; @@ -80,10 +74,8 @@ struct ignore_interfaces { /* request */ struct request { - /* host name */ - const char * host; - /* pointer to service */ - struct services * service; + /* host infos */ + struct hosts * host; /* url */ char * url; /* HTTP status code */ -- cgit v1.2.3-54-g00ecf