Просмотр исходного кода

portlist: wait for lsof cmd to exit

We were leaking processes otherwise.

Co-authored-by: Mihai Parparita <[email protected]>
Signed-off-by: Maisem Ali <[email protected]>
Maisem Ali 3 лет назад
Родитель
Сommit
b5299d7d0e
1 измененных файлов с 9 добавлено и 0 удалено
  1. 9 0
      portlist/portlist_macos.go

+ 9 - 0
portlist/portlist_macos.go

@@ -159,6 +159,15 @@ func (im *macOSImpl) addProcesses() error {
 		}
 		return nil
 	}
+	defer func() {
+		ps, err := lsofCmd.Process.Wait()
+		if err != nil || ps.ExitCode() != 0 {
+			log.Printf("portlist: can't run lsof in Mac sandbox; omitting process names from service list. Error: %v, exit code %d", err, ps.ExitCode())
+			lsofFailed.Store(true)
+		}
+	}()
+	defer lsofCmd.Process.Kill()
+
 	im.br.Reset(outPipe)
 
 	var cmd, proto string