forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugtrap.go
33 lines (28 loc) · 870 Bytes
/
debugtrap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package daemon
import (
"fmt"
"os"
"path/filepath"
"strings"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
)
const dataStructuresLogNameTemplate = "daemon-data-%s.log"
// dumpDaemon appends the daemon datastructures into file in dir and returns full path
// to that file.
func (d *Daemon) dumpDaemon(dir string) (string, error) {
// Ensure we recover from a panic as we are doing this without any locking
defer func() {
recover()
}()
path := filepath.Join(dir, fmt.Sprintf(dataStructuresLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1)))
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
return "", errors.Wrap(err, "failed to open file to write the daemon datastructure dump")
}
defer f.Close()
spew.Fdump(f, d) // Does not return an error
f.Sync()
return path, nil
}