summaryrefslogtreecommitdiff
path: root/internal/cli/cli.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cli/cli.go')
-rw-r--r--internal/cli/cli.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index 87ee34f..076d46b 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -179,13 +179,18 @@ func (a *App) ExecuteCommand(cfg *config.Config) error {
// Re-acquire lock for the entire cleanup sequence to ensure atomic unregister and unpin
cleanupLock, cleanupErr := namespace.AcquireProfileLock(pm, cfg.Profile)
if cleanupErr == nil {
- // Check if we are the last active process before unregistering
- last, lastErr := namespace.IsLastProcess(pm, cfg.Profile)
-
+ // 1. Unregister the process first.
if err := namespace.UnregisterProcess(pm, cfg.Profile); err != nil {
fmt.Printf("failed to unregister process: %v\n", err)
}
+ // 2. Prune and check if we are the last process.
+ if err := namespace.PruneStalePids(pm, cfg.Profile); err != nil {
+ fmt.Printf("failed to prune stale pids during cleanup: %v\n", err)
+ }
+
+ last, lastErr := namespace.IsLastProcess(pm, cfg.Profile)
+
if lastErr == nil && last {
fmt.Printf("Last process exiting. Cleaning up profile %s...\n", cfg.Profile)
if err := namespace.UnpinNamespace(pm, cfg.Profile); err != nil {