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
@@ -259,15 +261,14 @@ func WritePidFile(path string, pid int) error {
259261 if err != nil {
260262 return err
261263 }
262- tempPath := filepath .Join (filepath .Dir (path ), fmt .Sprintf (".%s" , filepath .Base (path )))
263- f , err := os .OpenFile (tempPath , os .O_RDWR | os .O_CREATE | os .O_EXCL | os .O_SYNC , 0666 )
264+ f , err := atomicfile .New (path , 0o666 )
264265 if err != nil {
265266 return err
266267 }
267268 _ , err = fmt .Fprintf (f , "%d" , pid )
268- f .Close ()
269269 if err != nil {
270+ f .Cancel ()
270271 return err
271272 }
272- return os . Rename ( tempPath , path )
273+ return f . Close ( )
273274}
You can’t perform that action at this time.
0 commit comments