UPSTREAM: 43762: refactor getPidsForProcess and change error handling
@@ -43,7 +43,6 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/util/oom"
"k8s.io/kubernetes/pkg/util/procfs"
- "k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/util/sets"
utilsysctl "k8s.io/kubernetes/pkg/util/sysctl"
utilversion "k8s.io/kubernetes/pkg/util/version"
@@ -617,15 +616,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 {
+ if len(pidFile) == 0 {
+ return procfs.PidOf(name)
+ }
+
+ pid, err := getPidFromPidFile(pidFile)
+ if err == nil {
return []int{pid}, nil
- } else {
- // log the error and fall back to pidof
- runtime.HandleError(err)
}
+
+ // Try to lookup pid by process name
+ pids, err2 := procfs.PidOf(name)
+ if err2 == nil {
+ return pids, nil
}
- return procfs.PidOf(name)
+
+ // 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.
