go.d fix compiling for windows (#18091)
Ilya Mashchenko committed
Jul 8, 2024 at 23:00 UTC
7d1bb10a476064c563ef30b2a0eac48bf4a71cdd
3 files changed
+42
-24
src/go/logger/journal_linux.go
new
+33
@@ -0,0 +1,33 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+//go:build linux
4
+
5
+package logger
6
+
7
+import (
8
+ "os"
9
+ "strconv"
10
+ "strings"
11
+ "syscall"
12
+)
13
+
14
+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)
33
+}
src/go/logger/journal_stub.go
new
+9
@@ -0,0 +1,9 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+//go:build !linux
4
+
5
+package logger
6
+
7
+func isStderrConnectedToJournal() bool {
8
+ return false
9
+}
src/go/logger/logger.go
-24
@@ -7,10 +7,7 @@ import (
7
"fmt"
8
"log/slog"
9
"os"
10
- "strconv"
11
- "strings"
10
"sync/atomic"
13
- "syscall"
11
12
"github.com/netdata/netdata/go/plugins/pkg/executable"
13
@@ -81,24 +78,3 @@ func (l *Logger) mute(v bool) {
78
func (l *Logger) isNil() bool { return l == nil || l.sl == nil }
79
80
var nilLogger = New()
84
-
85
-func isStderrConnectedToJournal() bool {
86
- stream := os.Getenv("JOURNAL_STREAM")
87
- if stream == "" {
88
- return false
89
- }
90
-
91
- idx := strings.IndexByte(stream, ':')
92
- if idx <= 0 {
93
- return false
94
- }
95
-
96
- dev, ino := stream[:idx], stream[idx+1:]
97
-
98
- var stat syscall.Stat_t
99
- if err := syscall.Fstat(int(os.Stderr.Fd()), &stat); err != nil {
100
- return false
101
- }
102
-
103
- return dev == strconv.Itoa(int(stat.Dev)) && ino == strconv.FormatUint(stat.Ino, 10)
104
-}