github.com/toplink-cn/moby@v0.0.0-20240305205811-460b4aebdf81/daemon/debugtrap_unix.go (about)

     1  //go:build !windows
     2  
     3  package daemon // import "github.com/docker/docker/daemon"
     4  
     5  import (
     6  	"context"
     7  	"os"
     8  	"os/signal"
     9  
    10  	"github.com/containerd/log"
    11  	"github.com/docker/docker/pkg/stack"
    12  	"golang.org/x/sys/unix"
    13  )
    14  
    15  func (daemon *Daemon) setupDumpStackTrap(root string) {
    16  	c := make(chan os.Signal, 1)
    17  	signal.Notify(c, unix.SIGUSR1)
    18  	go func() {
    19  		for range c {
    20  			path, err := stack.DumpToFile(root)
    21  			if err != nil {
    22  				log.G(context.TODO()).WithError(err).Error("failed to write goroutines dump")
    23  			} else {
    24  				log.G(context.TODO()).Infof("goroutine stacks written to %s", path)
    25  			}
    26  		}
    27  	}()
    28  }