Skip to content

Commit db02b0c

Browse files
committed
Remove unnecessary mkdir
* Check that shim dir exists when loading shim * No longer try to create shim dir when loading shim, as it must exist Signed-off-by: Plamen Petrov <[email protected]>
1 parent e3ccb40 commit db02b0c

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

firecracker-control/local.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (s *local) waitForShimToExit(ctx context.Context, vmID string, killShim boo
272272
if killShim {
273273
s.logger.Debug("Killing shim")
274274

275-
if err := syscall.Kill(int(pid), 9); err != nil {
275+
if err := syscall.Kill(int(pid), syscall.SIGKILL); err != nil {
276276
s.logger.WithError(err).Error("Failed to kill shim process")
277277
return err
278278
}
@@ -442,10 +442,6 @@ func (s *local) newShim(ns, vmID, containerdAddress string, shimSocket *net.Unix
442442
if err := fcSocketFile.Close(); err != nil {
443443
logger.WithError(err).Errorf("failed to close %q", fcSocketFile.Name())
444444
}
445-
446-
if err := os.RemoveAll(shimDir.RootPath()); err != nil {
447-
logger.WithError(err).Errorf("failed to remove %q", shimDir.RootPath())
448-
}
449445
}()
450446

451447
err = setShimOOMScore(cmd.Process.Pid)
@@ -497,11 +493,11 @@ func (s *local) loadShim(ctx context.Context, ns, vmID, containerdAddress string
497493
return nil, err
498494
}
499495

500-
// If we're here, there is no pre-existing shim for this VMID, so we spawn a new one
501496
defer shimSocket.Close()
502-
if err := os.Mkdir(s.config.ShimBaseDir, 0700); err != nil && !os.IsExist(err) {
503-
s.logger.WithError(err).Error()
504-
return nil, errors.Wrapf(err, "failed to make shim base directory: %s", s.config.ShimBaseDir)
497+
498+
// If we're here, there is no pre-existing shim for this VMID, so we spawn a new one
499+
if _, err := os.Stat(s.config.ShimBaseDir); os.IsNotExist(err) {
500+
return nil, errors.Wrapf(err, "shim base dir does not exist: %s", s.config.ShimBaseDir)
505501
}
506502

507503
shimDir, err := vm.ShimDir(s.config.ShimBaseDir, ns, vmID)
@@ -511,13 +507,6 @@ func (s *local) loadShim(ctx context.Context, ns, vmID, containerdAddress string
511507
return nil, err
512508
}
513509

514-
err = shimDir.Mkdir()
515-
if err != nil {
516-
err = errors.Wrapf(err, "failed to create VM dir %q", shimDir.RootPath())
517-
s.logger.WithError(err).Error()
518-
return nil, err
519-
}
520-
521510
fcSocketAddress, err := fcShim.FCControlSocketAddress(ctx, vmID)
522511
if err != nil {
523512
err = errors.Wrap(err, "failed to obtain shim socket address")

0 commit comments

Comments
 (0)