github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/pkg/dmesg/dmesg_linux.go (about)

     1  package dmesg // import "github.com/Prakhar-Agarwal-byte/moby/pkg/dmesg"
     2  
     3  import (
     4  	"golang.org/x/sys/unix"
     5  )
     6  
     7  // Dmesg returns last messages from the kernel log, up to size bytes
     8  func Dmesg(size int) []byte {
     9  	t := 3 // SYSLOG_ACTION_READ_ALL
    10  	b := make([]byte, size)
    11  	amt, err := unix.Klogctl(t, b)
    12  	if err != nil {
    13  		return []byte{}
    14  	}
    15  	return b[:amt]
    16  }