Skip to content

Commit

Permalink
Merge pull request moby#47999 from thaJeztah/deprecate_pkg_dmesg
Browse files Browse the repository at this point in the history
pkg/dmesg: deprecate, and use internal utility instead
  • Loading branch information
AkihiroSuda authored Jun 16, 2024
2 parents ff652c8 + 805ccd2 commit ec4bac4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions integration/container/overlayfs_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/dmesg"
"golang.org/x/sys/unix"
"gotest.tools/v3/assert"
"gotest.tools/v3/skip"
)
Expand Down Expand Up @@ -81,9 +81,15 @@ func TestNoOverlayfsWarningsAboutUndefinedBehaviors(t *testing.T) {
}
}

func dmesgLines(bytes int) []string {
data := dmesg.Dmesg(bytes)
return strings.Split(strings.TrimSpace(string(data)), "\n")
// dmesgLines returns last messages from the kernel log, up to size bytes,
// and splits the output by newlines.
func dmesgLines(size int) []string {
data := make([]byte, size)
amt, err := unix.Klogctl(unix.SYSLOG_ACTION_READ_ALL, data)
if err != nil {
return []string{}
}
return strings.Split(strings.TrimSpace(string(data[:amt])), "\n")
}

func diffDmesg(prev, next []string) []string {
Expand Down
7 changes: 4 additions & 3 deletions pkg/dmesg/dmesg_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"golang.org/x/sys/unix"
)

// Dmesg returns last messages from the kernel log, up to size bytes
// Dmesg returns last messages from the kernel log, up to size bytes.
//
// Deprecated: the dmesg package is no longer used, and will be removed in the next release.
func Dmesg(size int) []byte {
t := 3 // SYSLOG_ACTION_READ_ALL
b := make([]byte, size)
amt, err := unix.Klogctl(t, b)
amt, err := unix.Klogctl(unix.SYSLOG_ACTION_READ_ALL, b)
if err != nil {
return []byte{}
}
Expand Down

0 comments on commit ec4bac4

Please sign in to comment.