summaryrefslogtreecommitdiffstats
path: root/src/go/logger/journal_linux.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-26 08:15:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-26 08:15:35 +0000
commitf09848204fa5283d21ea43e262ee41aa578e1808 (patch)
treec62385d7adf209fa6a798635954d887f718fb3fb /src/go/logger/journal_linux.go
parentReleasing debian version 1.46.3-2. (diff)
downloadnetdata-f09848204fa5283d21ea43e262ee41aa578e1808.tar.xz
netdata-f09848204fa5283d21ea43e262ee41aa578e1808.zip
Merging upstream version 1.47.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/go/logger/journal_linux.go')
-rw-r--r--src/go/logger/journal_linux.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/go/logger/journal_linux.go b/src/go/logger/journal_linux.go
new file mode 100644
index 000000000..00f335075
--- /dev/null
+++ b/src/go/logger/journal_linux.go
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+//go:build linux
+
+package logger
+
+import (
+ "os"
+ "strconv"
+ "strings"
+ "syscall"
+)
+
+func isStderrConnectedToJournal() bool {
+ stream := os.Getenv("JOURNAL_STREAM")
+ if stream == "" {
+ return false
+ }
+
+ idx := strings.IndexByte(stream, ':')
+ if idx <= 0 {
+ return false
+ }
+
+ dev, ino := stream[:idx], stream[idx+1:]
+
+ var stat syscall.Stat_t
+ if err := syscall.Fstat(int(os.Stderr.Fd()), &stat); err != nil {
+ return false
+ }
+
+ return dev == strconv.Itoa(int(stat.Dev)) && ino == strconv.FormatUint(stat.Ino, 10)
+}