@cryptotaxi247 / netdata-1 / commits / e91ea1745

go.d: use lib function to check if stderr connected to journal (#18718)

Ilya Mashchenko committed Oct 8, 2024 at 14:58 UTC e91ea174586f2f9789a40379b8e2587ca7a17792
1 file changed +3 -22
src/go/logger/journal_linux.go
+3 -22
@@ -5,29 +5,10 @@
5 package logger
6
7 import (
8 - "os"
9 - "strconv"
10 - "strings"
11 - "syscall"
8 + "github.com/coreos/go-systemd/v22/journal"
9 )
10
11 func isStderrConnectedToJournal() bool {
15 - stream := os.Getenv("JOURNAL_STREAM")
16 - if stream == "" {
17 - return false
18 - }
19 -
20 - idx := strings.IndexByte(stream, ':')
21 - if idx <= 0 {
22 - return false
23 - }
24 -
25 - dev, ino := stream[:idx], stream[idx+1:]
26 -
27 - var stat syscall.Stat_t
28 - if err := syscall.Fstat(int(os.Stderr.Fd()), &stat); err != nil {
29 - return false
30 - }
31 -
32 - return dev == strconv.Itoa(int(stat.Dev)) && ino == strconv.FormatUint(stat.Ino, 10)
12 + ok, _ := journal.StderrIsJournalStream()
13 + return ok
14 }