mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Change process group when sending kill signal
Otherwise when the target process is running sudo it ignores the signal.
This commit is contained in:
parent
6456d67bd0
commit
ba17bac843
@ -372,7 +372,20 @@ func (k *killCmd) Kill() error {
|
||||
const timeout = 10 * time.Second
|
||||
for _, signal := range []string{"-TERM", "-KILL"} {
|
||||
glog.V(2).Infof("Killing process %d (%s) with %s", pid, name, signal)
|
||||
_, err := exec.Command("sudo", "kill", signal, strconv.Itoa(pid)).Output()
|
||||
cmd := exec.Command("sudo", "kill", signal, strconv.Itoa(pid))
|
||||
|
||||
// Run the 'kill' command in a separate process group so sudo doesn't ignore it
|
||||
attrs := &syscall.SysProcAttr{}
|
||||
// Hack to set unix-only field without build tags.
|
||||
setpgidField := reflect.ValueOf(attrs).Elem().FieldByName("Setpgid")
|
||||
if setpgidField.IsValid() {
|
||||
setpgidField.Set(reflect.ValueOf(true))
|
||||
} else {
|
||||
return fmt.Errorf("Failed to set Setpgid field (non-unix build)")
|
||||
}
|
||||
cmd.SysProcAttr = attrs
|
||||
|
||||
_, err := cmd.Output()
|
||||
if err != nil {
|
||||
glog.Errorf("Error signaling process %d (%s) with %s: %v", pid, name, signal, err)
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user