supoort all signal for process (#87)

Signed-off-by: xiang <xiang13225080@163.com>
This commit is contained in:
WangXiang 2021-09-15 14:38:14 +08:00 committed by GitHub
parent 2dcda95c83
commit 69a5aa40f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 10 deletions

View File

@ -14,6 +14,7 @@
package chaosd
import (
"fmt"
"strconv"
"syscall"
@ -39,18 +40,10 @@ func (processAttack) Attack(options core.AttackConfig, _ Environment) error {
for _, p := range processes {
if attack.Process == strconv.Itoa(p.Pid()) || attack.Process == p.Executable() {
notFound = false
switch attack.Signal {
case int(syscall.SIGKILL):
err = syscall.Kill(p.Pid(), syscall.SIGKILL)
case int(syscall.SIGTERM):
err = syscall.Kill(p.Pid(), syscall.SIGTERM)
case int(syscall.SIGSTOP):
err = syscall.Kill(p.Pid(), syscall.SIGSTOP)
default:
return errors.Errorf("signal %d is not supported", attack.Signal)
}
err = syscall.Kill(p.Pid(), syscall.Signal(attack.Signal))
if err != nil {
err = errors.Annotate(err, fmt.Sprintf("kill process with signal %d", attack.Signal))
return errors.WithStack(err)
}
attack.PIDs = append(attack.PIDs, p.Pid())