From 9bdc0329bac0f2a8e2ea49e55079b366db16be90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radu=20Lucu=C8=9B?= Date: Tue, 16 Dec 2025 11:53:08 +0200 Subject: [PATCH] fix: can't exit a running measurement --- cmd/auth.go | 4 ++++ cmd/ping.go | 3 +++ cmd/root.go | 4 ---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/auth.go b/cmd/auth.go index 5dcb118..53713c3 100644 --- a/cmd/auth.go +++ b/cmd/auth.go @@ -4,6 +4,7 @@ import ( "context" "errors" "math" + "os/signal" "syscall" "github.com/jsdelivr/globalping-cli/api" @@ -65,6 +66,9 @@ func (r *Root) RunAuthLogin(cmd *cobra.Command, args []string) error { } return nil } + + signal.Notify(r.cancel, syscall.SIGINT, syscall.SIGTERM) + res, err := r.client.Authorize(ctx, func(e error) { defer func() { r.cancel <- syscall.SIGINT diff --git a/cmd/ping.go b/cmd/ping.go index 125df68..eaa29a1 100644 --- a/cmd/ping.go +++ b/cmd/ping.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "os/signal" "slices" "syscall" "time" @@ -126,6 +127,8 @@ func (r *Root) pingInfinite(ctx context.Context, opts *globalping.MeasurementCre return fmt.Errorf("continuous mode is currently limited to 5 probes") } + signal.Notify(r.cancel, syscall.SIGINT, syscall.SIGTERM) + var err error go func() { err = r.ping(ctx, opts) diff --git a/cmd/root.go b/cmd/root.go index a3a72db..a1e81a6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,8 +3,6 @@ package cmd import ( "math" "os" - "os/signal" - "syscall" "time" "github.com/spf13/pflag" @@ -105,8 +103,6 @@ func NewRoot( cancel: make(chan os.Signal, 1), } - signal.Notify(root.cancel, syscall.SIGINT, syscall.SIGTERM) - // rootCmd represents the base command when called without any subcommands root.Cmd = &cobra.Command{ Use: "globalping",