File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ import (
2424 "strings"
2525
2626 "github.com/containerd/containerd/defaults"
27+ "github.com/containerd/containerd/pkg/atomicfile"
28+
2729 "github.com/urfave/cli"
2830)
2931
@@ -272,15 +274,14 @@ func WritePidFile(path string, pid int) error {
272274 if err != nil {
273275 return err
274276 }
275- tempPath := filepath .Join (filepath .Dir (path ), fmt .Sprintf (".%s" , filepath .Base (path )))
276- f , err := os .OpenFile (tempPath , os .O_RDWR | os .O_CREATE | os .O_EXCL | os .O_SYNC , 0666 )
277+ f , err := atomicfile .New (path , 0o666 )
277278 if err != nil {
278279 return err
279280 }
280281 _ , err = fmt .Fprintf (f , "%d" , pid )
281- f .Close ()
282282 if err != nil {
283+ f .Cancel ()
283284 return err
284285 }
285- return os . Rename ( tempPath , path )
286+ return f . Close ( )
286287}
You can’t perform that action at this time.
0 commit comments