aboutsummaryrefslogtreecommitdiffstats
path: root/pacredir.c
diff options
context:
space:
mode:
Diffstat (limited to 'pacredir.c')
-rw-r--r--pacredir.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/pacredir.c b/pacredir.c
index cf92b60..1cf496b 100644
--- a/pacredir.c
+++ b/pacredir.c
@@ -1,5 +1,5 @@
/*
- * (C) 2013-2024 by Christian Hesse <mail@eworm.de>
+ * (C) 2013-2025 by Christian Hesse <mail@eworm.de>
*
* 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
@@ -181,13 +181,27 @@ static void resolve_callback(AvahiServiceResolver *r,
break;
case AVAHI_RESOLVER_FOUND:
+ if (!avahi_string_list_find(txt, "id=" ID)) {
+ if (verbose > 0)
+ write_log(stderr, "Service %s (port %d) on host %s on interface %s does not match id=" ID "\n",
+ type, port, host, intname);
+ break;
+ }
+
+ if (!avahi_string_list_find(txt, "arch=" ARCH)) {
+ if (verbose > 0)
+ write_log(stderr, "Service %s (port %d) on host %s on interface %s does not match arch=" ARCH "\n",
+ type, port, host, intname);
+ break;
+ }
+
avahi_address_snprint(ipaddress, AVAHI_ADDRESS_STR_MAX, address);
if (verbose > 0)
- write_log(stdout, "Found service %s on host %s (%s) on interface %s\n",
- type, host, ipaddress, intname);
+ write_log(stdout, "Found service %s (port %d) on host %s (%s) on interface %s\n",
+ type, port, host, ipaddress, intname);
- add_host(host, protocol, ipaddress, PORT_PACSERVE, type);
+ add_host(host, protocol, ipaddress, port, type);
break;
}
@@ -487,7 +501,7 @@ static mhd_result ahc_echo(void * cls,
request->last_modified = 0;
if (verbose > 0)
- write_log(stdout, "Trying %s: %s\n", request->host, request->url);
+ write_log(stdout, "Trying %s: %s\n", request->host->host, request->url);
if ((error = pthread_create(&tid[req_count], NULL, get_http_code, (void *)request)) != 0)
write_log(stderr, "Could not run thread number %d, errno %d\n", req_count, error);
@@ -675,7 +689,9 @@ int main(int argc, char ** argv) {
/* Probing for static pacserve hosts takes some time.
* Receiving a SIGHUP at this time could kill us. So register signal
* SIGHUP here before probing. */
- signal(SIGHUP, sighup_callback);
+ struct sigaction act_hup = { 0 };
+ act_hup.sa_handler = sighup_callback;
+ sigaction(SIGHUP, &act_hup, NULL);
/* parse config file */
if ((ini = iniparser_load(CONFIGFILE)) == NULL) {
@@ -774,7 +790,7 @@ int main(int argc, char ** argv) {
/* prepare struct to make microhttpd listen on localhost only */
address.sin_family = AF_INET;
address.sin_port = htons(PORT_PACREDIR);
- address.sin_addr.s_addr = htonl(0x7f000001);
+ address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
/* start http server */
if ((mhd = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_TCP_FASTOPEN, PORT_PACREDIR,
@@ -787,9 +803,11 @@ int main(int argc, char ** argv) {
curl_global_init(CURL_GLOBAL_ALL);
/* register SIG{TERM,KILL,INT} signal callbacks */
- signal(SIGTERM, sig_callback);
- signal(SIGKILL, sig_callback);
- signal(SIGINT, sig_callback);
+ struct sigaction act = { 0 };
+ act.sa_handler = sig_callback;
+ sigaction(SIGTERM, &act, NULL);
+ sigaction(SIGKILL, &act, NULL);
+ sigaction(SIGINT, &act, NULL);
/* report ready to systemd */
sd_notify(0, "READY=1\nSTATUS=Waiting for requests to redirect...");