feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,63 @@
|
||||
//go:build linux
|
||||
|
||||
package isolation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func pureFTPDaemonPIDs(binaryPath string) ([]int, error) {
|
||||
expected, err := filepath.EvalSymlinks(binaryPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
entries, err := os.ReadDir("/proc")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pids := make([]int, 0, 2)
|
||||
for _, entry := range entries {
|
||||
pid, parseErr := strconv.Atoi(entry.Name())
|
||||
if parseErr != nil || pid <= 1 || pid == os.Getpid() {
|
||||
continue
|
||||
}
|
||||
executable, readErr := os.Readlink("/proc/" + entry.Name() + "/exe")
|
||||
if readErr == nil && filepath.Clean(executable) == filepath.Clean(expected) {
|
||||
pids = append(pids, pid)
|
||||
}
|
||||
}
|
||||
return pids, nil
|
||||
}
|
||||
|
||||
func terminatePureFTPDaemons(ctx context.Context, binaryPath string) error {
|
||||
pids, err := pureFTPDaemonPIDs(binaryPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, pid := range pids {
|
||||
_ = syscall.Kill(pid, syscall.SIGTERM)
|
||||
}
|
||||
if len(pids) > 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-time.After(750 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
pids, err = pureFTPDaemonPIDs(binaryPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, pid := range pids {
|
||||
if killErr := syscall.Kill(pid, syscall.SIGKILL); killErr != nil && !errors.Is(killErr, syscall.ESRCH) {
|
||||
return killErr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user