From f699dbac1e25edefe942b59996225b6d3af30c06 Mon Sep 17 00:00:00 2001
From: Clayton Craft <clayton@craftyguy.net>
Date: Thu, 23 Jan 2025 08:01:57 -0800
Subject: [PATCH] Support logging to stdout for running under systemd

If bootmac is running under systemd, sending output to `logger` usually
means that the output is not sent to journald, and is lost. This can
make debug more difficult. The var tested here is one that systemd sets
when running a daemon (see `man systemd.exec`.)
---
 bootmac | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/bootmac b/bootmac
index eda09a7..d865336 100755
--- a/bootmac
+++ b/bootmac
@@ -19,8 +19,15 @@ MAC_PREFIX="0200"
 BT_TIMEOUT=${BT_TIMEOUT:-5} # seconds
 WLAN_TIMEOUT=${WLAN_TIMEOUT:-5} # seconds
 
+USE_LOGGER=true
+[ -n "$SYSTEMD_EXEC_PID" ] && USE_LOGGER=false
+
 log() {
-    echo "$@" | logger -t "bootmac"
+    if "$USE_LOGGER"; then
+        echo "$@" | logger -t "bootmac"
+    else
+        echo "$@"
+    fi
 }
 
 help_info() {
-- 
GitLab