From b431fe4fc0344ab634eb1cfc911eac818b683ac5 Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Tue, 22 Dec 2020 21:16:46 -0800 Subject: [PATCH] freebsd: don't run shim delete in deleted dir fork/exec can fail and log a warning like this in containerd's log: failed to clean up after shim disconnected error=": fork/exec /usr/local/bin/containerd-shim-[my-shim]: no such file or directory" id=test namespace=default Passing the bundle path on the command line allows the shim delete command to run successfully. Signed-off-by: Samuel Karp --- runtime/v2/binary.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/v2/binary.go b/runtime/v2/binary.go index 51845bfee..5a62a86b6 100644 --- a/runtime/v2/binary.go +++ b/runtime/v2/binary.go @@ -133,11 +133,13 @@ func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_ func (b *binary) Delete(ctx context.Context) (*runtime.Exit, error) { log.G(ctx).Info("cleaning up dead shim") - // Windows cannot delete the current working directory while an - // executable is in use with it. For the cleanup case we invoke with the - // default work dir and forward the bundle path on the cmdline. + // On Windows and FreeBSD, the current working directory of the shim should + // not be the bundle path during the delete operation. Instead, we invoke + // with the default work dir and forward the bundle path on the cmdline. + // Windows cannot delete the current working directory while an executable + // is in use with it. On FreeBSD, fork/exec can fail. var bundlePath string - if gruntime.GOOS != "windows" { + if gruntime.GOOS != "windows" && gruntime.GOOS != "freebsd" { bundlePath = b.bundle.Path } @@ -160,6 +162,7 @@ func (b *binary) Delete(ctx context.Context) (*runtime.Exit, error) { cmd.Stdout = out cmd.Stderr = errb if err := cmd.Run(); err != nil { + log.G(ctx).WithField("cmd", cmd).WithError(err).Error("failed to delete") return nil, errors.Wrapf(err, "%s", errb.String()) } s := errb.String()