Browse code

pkg/dmesg: deprecate, and use internal utility instead

This package was originally added in 46833ee1c353c247e3ef817a08d5a35a2a43bdf3
for use in the devicemapper graphdriver. The devicemapper graphdriver was
deprecated and has been removed. The only remaining consumer is an integration
test.

Deprecate the package and mark it for removal in the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/06/16 19:41:25
Showing 2 changed files
... ...
@@ -8,7 +8,7 @@ import (
8 8
 	containertypes "github.com/docker/docker/api/types/container"
9 9
 	"github.com/docker/docker/integration/internal/container"
10 10
 	"github.com/docker/docker/pkg/archive"
11
-	"github.com/docker/docker/pkg/dmesg"
11
+	"golang.org/x/sys/unix"
12 12
 	"gotest.tools/v3/assert"
13 13
 	"gotest.tools/v3/skip"
14 14
 )
... ...
@@ -81,9 +81,15 @@ func TestNoOverlayfsWarningsAboutUndefinedBehaviors(t *testing.T) {
81 81
 	}
82 82
 }
83 83
 
84
-func dmesgLines(bytes int) []string {
85
-	data := dmesg.Dmesg(bytes)
86
-	return strings.Split(strings.TrimSpace(string(data)), "\n")
84
+// dmesgLines returns last messages from the kernel log, up to size bytes,
85
+// and splits the output by newlines.
86
+func dmesgLines(size int) []string {
87
+	data := make([]byte, size)
88
+	amt, err := unix.Klogctl(unix.SYSLOG_ACTION_READ_ALL, data)
89
+	if err != nil {
90
+		return []string{}
91
+	}
92
+	return strings.Split(strings.TrimSpace(string(data[:amt])), "\n")
87 93
 }
88 94
 
89 95
 func diffDmesg(prev, next []string) []string {
... ...
@@ -4,7 +4,9 @@ import (
4 4
 	"golang.org/x/sys/unix"
5 5
 )
6 6
 
7
-// Dmesg returns last messages from the kernel log, up to size bytes
7
+// Dmesg returns last messages from the kernel log, up to size bytes.
8
+//
9
+// Deprecated: the dmesg package is no longer used, and will be removed in the next release.
8 10
 func Dmesg(size int) []byte {
9 11
 	b := make([]byte, size)
10 12
 	amt, err := unix.Klogctl(unix.SYSLOG_ACTION_READ_ALL, b)