MCPcopy Create free account
hub / github.com/linuxkit/linuxkit / Path

Method Path

pkg/init/cmd/service/logging.go:101–128  ·  view source on GitHub ↗

Path returns the name of a FIFO connected to the logging daemon.

(n string)

Source from the content-addressed store, hash-verified

99
100// Path returns the name of a FIFO connected to the logging daemon.
101func (r *remoteLog) Path(n string) string {
102 path := filepath.Join(r.fifoDir, n+".log")
103 // replicate behavior of os.Create(path) for a fileLog.
104 // if a file exists at the given path, os.Create will truncate it.
105 // syscall.Mkfifo on the other hand fails when a file exists at the given path.
106 if _, err := os.Stat(path); err == nil {
107 os.Remove(path)
108 }
109 if err := syscall.Mkfifo(path, 0600); err != nil {
110 log.Printf("failed to create fifo %s: %s", path, err)
111 return "/dev/null"
112 }
113 go func() {
114 // In a goroutine because Open of the FIFO will block until
115 // containerd opens it when the task is started.
116 fd, err := syscall.Open(path, syscall.O_RDONLY, 0)
117 if err != nil {
118 // Should never happen: we just created the fifo
119 log.Printf("failed to open fifo %s: %s", path, err)
120 }
121 defer syscall.Close(fd)
122 if err := sendToLogger(n, fd); err != nil {
123 // Should never happen: logging is enabled
124 log.Printf("failed to send fifo %s to logger: %s", path, err)
125 }
126 }()
127 return path
128}
129
130// Open a log file for the named service.
131func (r *remoteLog) Open(n string) (io.WriteCloser, error) {

Callers

nothing calls this directly

Calls 4

sendToLoggerFunction · 0.85
RemoveMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected