From 1f8210957744095c7daec10b8fcfbce7d48e4046 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Mon, 8 Aug 2022 09:56:25 +0100 Subject: [PATCH 01/12] Use printf in place of echo for portability to Mac OS. Update author --- Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index e5674d2b..48653ac2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,11 +36,11 @@ endif if USE_GIT_VERSION common.c: gitversion.h gitversion.h: .git/index - echo "// Do not edit!" > gitversion.h - echo "// This file is automatically generated by 'git describe --dirty', if available." >> gitversion.h - echo -n " char git_version_string[] = \"" >> gitversion.h + printf "// Do not edit!\n" > gitversion.h + printf "// This file is automatically generated by 'git describe --dirty', if available.\n" >> gitversion.h + printf " char git_version_string[] = \"" >> gitversion.h git describe --dirty | tr -d '[[:space:]]' >> gitversion.h - echo "\";" >> gitversion.h + printf "\";\n" >> gitversion.h CLEANFILES += gitversion.h endif From bc7d122a9ed3a8e53d764d734753e0463192893d Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 8 Aug 2022 09:58:16 +0100 Subject: [PATCH 02/12] Clean us a few compilation errors. --- common.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/common.c b/common.c index f8b7ae1a..c4f9ac81 100644 --- a/common.c +++ b/common.c @@ -62,6 +62,9 @@ #endif #ifdef COMPILE_FOR_OSX +#include +#include +#include #include #include #include @@ -1220,7 +1223,6 @@ uint64_t get_monotonic_time_in_ns() { #ifdef COMPILE_FOR_OSX uint64_t time_now_mach; - uint64_t elapsedNano; static mach_timebase_info_data_t sTimebaseInfo = {0, 0}; // this actually give you a monotonic clock @@ -1238,7 +1240,7 @@ uint64_t get_monotonic_time_in_ns() { } if (sTimebaseInfo.denom == 0) - die("could not initialise Mac timebase info in get_monotonic_time_in_ns().") + die("could not initialise Mac timebase info in get_monotonic_time_in_ns()."); // Do the maths. We hope that the multiplication doesn't // overflow; the price you pay for working in fixed point. @@ -1283,7 +1285,6 @@ uint64_t get_absolute_time_in_ns() { #ifdef COMPILE_FOR_OSX uint64_t time_now_mach; - uint64_t elapsedNano; static mach_timebase_info_data_t sTimebaseInfo = {0, 0}; // this actually give you a monotonic clock @@ -1303,7 +1304,7 @@ uint64_t get_absolute_time_in_ns() { // overflow; the price you pay for working in fixed point. if (sTimebaseInfo.denom == 0) - die("could not initialise Mac timebase info in get_absolute_time_in_ns().") + die("could not initialise Mac timebase info in get_absolute_time_in_ns()."); // this gives us nanoseconds time_now_ns = time_now_mach * sTimebaseInfo.numer / sTimebaseInfo.denom; @@ -1953,7 +1954,6 @@ int get_device_id(uint8_t *id, int int_length) { response = -1; } else { t = id; - int found = 0; for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { #ifdef AF_PACKET if ((ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET)) { @@ -1962,7 +1962,6 @@ int get_device_id(uint8_t *id, int int_length) { for (i = 0; ((i < s->sll_halen) && (i < int_length)); i++) { *t++ = s->sll_addr[i]; } - found = 1; } } #else @@ -1975,7 +1974,6 @@ int get_device_id(uint8_t *id, int int_length) { debug(1, "char %d: \"%c\".", i, *s); *t++ = (uint8_t)*s++; } - found = 1; } } #endif From c458114c4ca1a016bbf2fcf4660846f848a3955a Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 8 Aug 2022 12:16:40 +0100 Subject: [PATCH 03/12] Add distinct flags for Darwin -- turn off deprecation warnings. --- Makefile.am | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile.am b/Makefile.am index 48653ac2..f16ae1d7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,10 @@ noinst_LIBRARIES = shairport_sync_SOURCES = shairport.c rtsp.c mdns.c common.c rtp.c player.c alac.c audio.c loudness.c activity_monitor.c +if BUILD_FOR_DARWIN + AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -Wno-deprecated-declarations -pthread -DSYSCONFDIR=\"$(sysconfdir)\" + AM_CFLAGS = -Wno-multichar -Wall -Wextra -Wno-deprecated-declarations -pthread -DSYSCONFDIR=\"$(sysconfdir)\" +else if BUILD_FOR_FREEBSD AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -pthread -DSYSCONFDIR=\"$(sysconfdir)\" AM_CFLAGS = -Wno-multichar -Wall -Wextra -pthread -DSYSCONFDIR=\"$(sysconfdir)\" @@ -31,6 +35,7 @@ else AM_CFLAGS = -fno-common -Wno-multichar -Wall -Wextra -Wno-clobbered -Wno-psabi -pthread -DSYSCONFDIR=\"$(sysconfdir)\" endif endif +endif # include information generated by 'git describe --dirty' if requested if USE_GIT_VERSION From 074457c8574897bea04ba896d8c6a62bd13f2b58 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 8 Aug 2022 12:17:20 +0100 Subject: [PATCH 04/12] Add conditional test for Darwin. --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 356d3d4c..333f186f 100644 --- a/configure.ac +++ b/configure.ac @@ -50,6 +50,7 @@ fi AM_CONDITIONAL([BUILD_FOR_LINUX], [test "x${with_os}" = xlinux ]) AM_CONDITIONAL([BUILD_FOR_FREEBSD], [test "x${with_os}" = xfreebsd ]) AM_CONDITIONAL([BUILD_FOR_OPENBSD], [test "x${with_os}" = xopenbsd ]) +AM_CONDITIONAL([BUILD_FOR_DARWIN], [test "x${with_os}" = xdarwin ]) ##### Some build systems are not fully using pkg-config, so we can use the flag ${with_pkg_config} on a case-by-case basis ##### to control how to deal with them From 54e228cbec988f1dfc3c785b0d69c0eb8c55de0c Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 8 Aug 2022 12:18:36 +0100 Subject: [PATCH 05/12] Accommodate but do not use extra texts and name for a secondary boujour message. --- mdns_dns_sd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mdns_dns_sd.c b/mdns_dns_sd.c index 4952a9f0..01be15a1 100644 --- a/mdns_dns_sd.c +++ b/mdns_dns_sd.c @@ -33,8 +33,9 @@ static DNSServiceRef service; -static int mdns_dns_sd_register(char *apname, int port, - __attribute__((unused)) char **txt_records) { +static int mdns_dns_sd_register(char *ap1name, __attribute__((unused)) char *ap2name, int port, + __attribute__((unused)) char **txt_records, + __attribute__((unused)) char **secondary_txt_records) { char *recordwithoutmetadata[] = {MDNS_RECORD_WITHOUT_METADATA, NULL}; #ifdef CONFIG_METADATA char *recordwithmetadata[] = {MDNS_RECORD_WITH_METADATA, NULL}; @@ -71,7 +72,7 @@ static int mdns_dns_sd_register(char *apname, int port, } DNSServiceErrorType error; - error = DNSServiceRegister(&service, 0, kDNSServiceInterfaceIndexAny, apname, config.regtype, "", + error = DNSServiceRegister(&service, 0, kDNSServiceInterfaceIndexAny, ap1name, config.regtype, "", NULL, htons((uint16_t)port), length, buf, NULL, NULL); free(buf); From de8df93471e70fc585670879b12a9539517c3ea0 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 8 Aug 2022 12:19:04 +0100 Subject: [PATCH 06/12] Comment out an unused variable. --- rtp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rtp.c b/rtp.c index 169a5f38..844f55fe 100644 --- a/rtp.c +++ b/rtp.c @@ -723,7 +723,7 @@ void *rtp_timing_receiver(void *arg) { // for getting mean and sd of return times int32_t stat_n = 0; double stat_mean = 0.0; - double stat_M2 = 0.0; + // double stat_M2 = 0.0; while (1) { nread = recv(conn->timing_socket, packet, sizeof(packet), 0); @@ -813,7 +813,7 @@ void *rtp_timing_receiver(void *arg) { stat_n += 1; double stat_delta = return_time - stat_mean; stat_mean += stat_delta / stat_n; - stat_M2 += stat_delta * (return_time - stat_mean); + // stat_M2 += stat_delta * (return_time - stat_mean); // debug(1, "Timing packet return time stats: current, mean and standard deviation over // %d packets: %.1f, %.1f, %.1f (nanoseconds).", // stat_n,return_time,stat_mean, sqrtf(stat_M2 / (stat_n - 1))); From 882d6c5b680e68ee35b17e891dc4c11905cf4732 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 9 Aug 2022 12:34:17 +0100 Subject: [PATCH 07/12] Fix get_device_id to work property when using AF_LINK rather than AF_PACKET. Ensure only int_length bytes are copied to the device ID --- common.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common.c b/common.c index c4f9ac81..2e582f63 100644 --- a/common.c +++ b/common.c @@ -1950,15 +1950,17 @@ int get_device_id(uint8_t *id, int int_length) { } if (getifaddrs(&ifaddr) == -1) { - debug(1, "getifaddrs"); response = -1; } else { t = id; - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + int found = 0; + + for (ifa = ifaddr; ((ifa != NULL) && (found == 0)); ifa = ifa->ifa_next) { #ifdef AF_PACKET if ((ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET)) { struct sockaddr_ll *s = (struct sockaddr_ll *)ifa->ifa_addr; - if ((strcmp(ifa->ifa_name, "lo") != 0) && (found == 0)) { + if ((strcmp(ifa->ifa_name, "lo") != 0)) { + found = 1; for (i = 0; ((i < s->sll_halen) && (i < int_length)); i++) { *t++ = s->sll_addr[i]; } @@ -1969,15 +1971,16 @@ int get_device_id(uint8_t *id, int int_length) { struct sockaddr_dl *sdl = (struct sockaddr_dl *)ifa->ifa_addr; if ((sdl) && (sdl->sdl_family == AF_LINK)) { if (sdl->sdl_type == IFT_ETHER) { - char *s = LLADDR(sdl); - for (i = 0; i < sdl->sdl_alen; i++) { - debug(1, "char %d: \"%c\".", i, *s); - *t++ = (uint8_t)*s++; + found = 1; + uint8_t *s = (uint8_t *)LLADDR(sdl); + for (i = 0; ((i < sdl->sdl_alen) && (i < int_length)); i++) { + *t++ = *s++; } } } #endif #endif + } freeifaddrs(ifaddr); } From 919c4a41311de4c119325dd99cd362add7d66272 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 9 Aug 2022 12:38:52 +0100 Subject: [PATCH 08/12] Clear the config record at the very very start, and not a little later. --- shairport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shairport.c b/shairport.c index bbecc558..91bc4416 100644 --- a/shairport.c +++ b/shairport.c @@ -1693,6 +1693,7 @@ void termHandler(__attribute__((unused)) int k) { } int main(int argc, char **argv) { + memset(&config, 0, sizeof(config)); // also clears all strings, BTW /* Check if we are called with -V or --version parameter */ if (argc >= 2 && ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0))) { print_version(); @@ -1726,7 +1727,6 @@ int main(int argc, char **argv) { config.log_fd = -1; conns = NULL; // no connections active memset((void *)&main_thread_id, 0, sizeof(main_thread_id)); - memset(&config, 0, sizeof(config)); // also clears all strings, BTW ns_time_at_startup = get_absolute_time_in_ns(); ns_time_at_last_debug_message = ns_time_at_startup; // this is a bit weird, but necessary -- basename() may modify the argument passed in From f61278278a0933c2498af86530c3122b944ef003 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 9 Aug 2022 12:39:23 +0100 Subject: [PATCH 09/12] Quieten a noisy debug message. --- player.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/player.c b/player.c index 7b2ce500..76f5a3a1 100644 --- a/player.c +++ b/player.c @@ -2414,7 +2414,7 @@ void *player_thread_func(void *arg) { double moving_average_correction = 0.0; double moving_average_insertions_plus_deletions = 0.0; if (number_of_statistics == 0) { - debug(1, "number_of_statistics is zero!"); + debug(2, "number_of_statistics is zero!"); } else { moving_average_sync_error = (1.0 * tsum_of_sync_errors) / number_of_statistics; moving_average_correction = (1.0 * tsum_of_corrections) / number_of_statistics; From a774a6fcb0bf7daa550efbc9d9e2f1f2d7898731 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 9 Aug 2022 13:00:55 +0100 Subject: [PATCH 10/12] Strip off the last dot and everything to the right of it in the hostname when automatically generating a service name. --- shairport.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shairport.c b/shairport.c index 91bc4416..b4ad115b 100644 --- a/shairport.c +++ b/shairport.c @@ -1454,6 +1454,11 @@ int parse_options(int argc, char **argv) { // now, do the substitutions in the service name char hostname[100]; gethostname(hostname, 100); + + // strip off a terminating ., e.g. .local from the hostname + char *last_dot = strrchr(hostname,'.'); + if (last_dot != NULL) + *last_dot = '\0'; char *i0; if (raw_service_name == NULL) From dd197162f6224948b7657d6a43dcab5955fc6694 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 9 Aug 2022 13:59:54 +0100 Subject: [PATCH 11/12] Update RELEASENOTES-DEVELOPMENT.md --- RELEASENOTES-DEVELOPMENT.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/RELEASENOTES-DEVELOPMENT.md b/RELEASENOTES-DEVELOPMENT.md index e0a21b67..634df2bb 100644 --- a/RELEASENOTES-DEVELOPMENT.md +++ b/RELEASENOTES-DEVELOPMENT.md @@ -1,3 +1,11 @@ +Version 4.1-dev-454-ga774a6fc +==== +**Enhancement** +* Strip the trailing dot and everything after it in the hostname when using it as the basis for a service name. E.g. `freebsd.local` becomes `freebsd`. + +**Bug Fixes** +* Fix a few compilation bugs and portability issues, and turn off deprecation warnings when compiling for Mac OS. + Version 4.1-dev-439-gb7a11cae ==== Documentation update. Comments, corrections and suggestions welcome. From 77c9ff5de4cc9267a3236bb6883b78742569d7f2 Mon Sep 17 00:00:00 2001 From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:02:14 +0100 Subject: [PATCH 12/12] Update RELEASENOTES-DEVELOPMENT.md --- RELEASENOTES-DEVELOPMENT.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASENOTES-DEVELOPMENT.md b/RELEASENOTES-DEVELOPMENT.md index 634df2bb..666071a8 100644 --- a/RELEASENOTES-DEVELOPMENT.md +++ b/RELEASENOTES-DEVELOPMENT.md @@ -6,6 +6,8 @@ Version 4.1-dev-454-ga774a6fc **Bug Fixes** * Fix a few compilation bugs and portability issues, and turn off deprecation warnings when compiling for Mac OS. +**Note:** After this update, you'll need to run `autoreconf -fi` and the `./configure...` steps again. + Version 4.1-dev-439-gb7a11cae ==== Documentation update. Comments, corrections and suggestions welcome.