From b0dd5065533378b7a4bd32789fdd7de087432e80 Mon Sep 17 00:00:00 2001 From: yanggang Date: Fri, 2 Dec 2022 17:32:21 +0800 Subject: [PATCH] fix panic when containerd-stress density --count 0 Signed-off-by: yanggang --- cmd/containerd-stress/density.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/containerd-stress/density.go b/cmd/containerd-stress/density.go index 0ca34c293..2a6fe894f 100644 --- a/cmd/containerd-stress/density.go +++ b/cmd/containerd-stress/density.go @@ -20,6 +20,7 @@ import ( "bufio" "context" "encoding/json" + "errors" "fmt" "os" "os/signal" @@ -47,6 +48,15 @@ var densityCommand = cli.Command{ }, }, Action: func(cliContext *cli.Context) error { + var ( + pids []uint32 + count = cliContext.Int("count") + ) + + if count < 1 { + return errors.New("count cannot be less than one") + } + config := config{ Address: cliContext.GlobalString("address"), Duration: cliContext.GlobalDuration("duration"), @@ -76,10 +86,6 @@ var densityCommand = cli.Command{ s := make(chan os.Signal, 1) signal.Notify(s, syscall.SIGTERM, syscall.SIGINT) - var ( - pids []uint32 - count = cliContext.Int("count") - ) loop: for i := 0; i < count+1; i++ { select {