Skip to content

Commit

Permalink
fix: get pid of container directly
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Dec 27, 2024
1 parent c113b9f commit 33d4f39
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions container/container_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import (
"fmt"
"os"
"path/filepath"
"syscall"

"github.com/nixpig/brownie/cgroups"
"golang.org/x/sys/unix"
)

func (c *Container) Delete(force bool) error {
if !force && !c.CanBeDeleted() {
return fmt.Errorf("container cannot be deleted in current state (%s)", c.Status())
}

if err := c.Kill(unix.SIGKILL); err != nil {
return fmt.Errorf("send sigkill to container: %w", err)
process, err := os.FindProcess(c.PID())
if err != nil {
return fmt.Errorf("find container process (%d): %w", c.PID(), err)
}
if process != nil {
process.Signal(syscall.Signal(9))
}

if err := cgroups.DeleteV1(c.Spec.Linux.CgroupsPath); err != nil {
Expand Down

0 comments on commit 33d4f39

Please sign in to comment.