mirror of https://github.com/k3s-io/k3s
refactor getPidsForProcess and change error handling
parent
f657607d88
commit
ebb1243aba
|
@ -46,7 +46,6 @@ go_library(
|
|||
"//vendor:k8s.io/apimachinery/pkg/api/resource",
|
||||
"//vendor:k8s.io/apimachinery/pkg/types",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/errors",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/runtime",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/sets",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/wait",
|
||||
"//vendor:k8s.io/client-go/tools/record",
|
||||
|
|
|
@ -35,7 +35,6 @@ import (
|
|||
"github.com/opencontainers/runc/libcontainer/configs"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/tools/record"
|
||||
|
@ -630,15 +629,25 @@ func getPidFromPidFile(pidFile string) (int, error) {
|
|||
}
|
||||
|
||||
func getPidsForProcess(name, pidFile string) ([]int, error) {
|
||||
if len(pidFile) > 0 {
|
||||
if pid, err := getPidFromPidFile(pidFile); err == nil {
|
||||
return []int{pid}, nil
|
||||
} else {
|
||||
// log the error and fall back to pidof
|
||||
runtime.HandleError(err)
|
||||
}
|
||||
}
|
||||
if len(pidFile) == 0 {
|
||||
return procfs.PidOf(name)
|
||||
}
|
||||
|
||||
pid, err := getPidFromPidFile(pidFile)
|
||||
if err == nil {
|
||||
return []int{pid}, nil
|
||||
}
|
||||
|
||||
// Try to lookup pid by process name
|
||||
pids, err2 := procfs.PidOf(name)
|
||||
if err2 == nil {
|
||||
return pids, nil
|
||||
}
|
||||
|
||||
// Return error from getPidFromPidFile since that should have worked
|
||||
// and is the real source of the problem.
|
||||
glog.V(4).Infof("unable to get pid from %s: %v", pidFile, err)
|
||||
return []int{}, err
|
||||
}
|
||||
|
||||
// Ensures that the Docker daemon is in the desired container.
|
||||
|
|
Loading…
Reference in New Issue