mirror of
https://github.com/containers/podman.git
synced 2025-12-08 14:48:48 +08:00
use libnetwork/slirp4netns from c/common
Most of the code moved there so if from there and remove it here. Some extra changes are required here. This is a bit of a mess. The pipe handling makes this a bit more difficult. [NO NEW TESTS NEEDED] This is just a rework, existing tests must pass. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
65
vendor/github.com/containers/common/pkg/servicereaper/service.go
generated
vendored
Normal file
65
vendor/github.com/containers/common/pkg/servicereaper/service.go
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package servicereaper
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
pidMap map[int]bool
|
||||
mutex *sync.Mutex
|
||||
}
|
||||
|
||||
var s = service{
|
||||
pidMap: map[int]bool{},
|
||||
mutex: &sync.Mutex{},
|
||||
}
|
||||
|
||||
func AddPID(pid int) {
|
||||
s.mutex.Lock()
|
||||
s.pidMap[pid] = true
|
||||
s.mutex.Unlock()
|
||||
}
|
||||
|
||||
func Start() {
|
||||
// create signal channel and only wait for SIGCHLD
|
||||
sigc := make(chan os.Signal, 1)
|
||||
signal.Notify(sigc, syscall.SIGCHLD)
|
||||
// wait and reap in an extra goroutine
|
||||
go reaper(sigc)
|
||||
}
|
||||
|
||||
func reaper(sigc chan os.Signal) {
|
||||
for {
|
||||
// block until we receive SIGCHLD
|
||||
<-sigc
|
||||
s.mutex.Lock()
|
||||
for pid := range s.pidMap {
|
||||
var status syscall.WaitStatus
|
||||
waitpid, err := syscall.Wait4(pid, &status, syscall.WNOHANG, nil)
|
||||
if err != nil {
|
||||
// do not log error for ECHILD
|
||||
if err != syscall.ECHILD {
|
||||
logrus.Warnf("Wait for pid %d failed: %v ", pid, err)
|
||||
}
|
||||
delete(s.pidMap, pid)
|
||||
continue
|
||||
}
|
||||
// if pid == 0 nothing happened
|
||||
if waitpid == 0 {
|
||||
continue
|
||||
}
|
||||
if status.Exited() || status.Signaled() {
|
||||
delete(s.pidMap, pid)
|
||||
}
|
||||
}
|
||||
s.mutex.Unlock()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user