MCPcopy
hub / github.com/containerd/containerd / initPanicFile

Function initPanicFile

cmd/containerd/command/service_windows.go:331–364  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

329}
330
331func initPanicFile(path string) error {
332 var err error
333 panicFile, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
334 if err != nil {
335 return err
336 }
337
338 st, err := panicFile.Stat()
339 if err != nil {
340 return err
341 }
342
343 // If there are contents in the file already, move the file out of the way
344 // and replace it.
345 if st.Size() > 0 {
346 panicFile.Close()
347 os.Rename(path, path+".old")
348 panicFile, err = os.Create(path)
349 if err != nil {
350 return err
351 }
352 }
353
354 // Update STD_ERROR_HANDLE to point to the panic file so that Go writes to
355 // it when it panics. Remember the old stderr to restore it before removing
356 // the panic file.
357 h, err := windows.GetStdHandle(windows.STD_ERROR_HANDLE)
358 if err != nil {
359 return err
360 }
361 oldStderr = h
362
363 return windows.SetStdHandle(windows.STD_ERROR_HANDLE, windows.Handle(panicFile.Fd()))
364}
365
366func removePanicFile() {
367 if st, err := panicFile.Stat(); err == nil {

Callers 1

Calls 5

StatMethod · 0.65
SizeMethod · 0.65
CloseMethod · 0.65
CreateMethod · 0.65
HandleMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…