unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 11/9] extsearchidx: improve missing machine-id fallback
@ 2020-12-17 19:40 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-12-17 19:40 UTC (permalink / raw)
  To: meta

It's likely most GNU/Linux systems have /etc/machine-id these
days, so anything missing it is likely a *BSD, most of which
support and favor "sysctl -n kern.hostid".  We'll also support
"ghostid" since GNU utils are commonly prefixed with 'g' on
non-GNU platforms.

In any case, we'll suppress stderr from missing commands and
fall back to hard coding an $OSNAME-based identifier as a last
resort and hope the hostname is unique.
---
 lib/PublicInbox/ExtSearchIdx.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index f492734a..e196e7ab 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -534,8 +534,10 @@ sub host_ident () {
 	state $retval = hostname . '-' . do {
 		my $m; # machine-id(5) is systemd
 		if (open(my $fh, '<', '/etc/machine-id')) { $m = <$fh> }
-		# hostid(1) is in GNU coreutils, kern.hostid is FreeBSD
-		chomp($m ||= `hostid` || `sysctl -n kern.hostid`);
+		# (g)hostid(1) is in GNU coreutils, kern.hostid is most BSDs
+		chomp($m ||= `{ sysctl -n kern.hostid ||
+				hostid || ghostid; } 2>/dev/null`
+			|| "no-machine-id-or-hostid-on-$^O");
 		$m;
 	};
 }

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-17 19:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 19:40 [PATCH 11/9] extsearchidx: improve missing machine-id fallback Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).