From c1fd48a14bc83e237e1de8cb44e833ac6ff3584e Mon Sep 17 00:00:00 2001 From: Phi Date: Mon, 21 Aug 2023 09:10:47 +0200 Subject: [PATCH 1/2] Make `lotus wallet import` respect sigint Make `lotus wallet import` respect sigint --- cli/wallet.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cli/wallet.go b/cli/wallet.go index 61946a463..8d44d3ef2 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -7,7 +7,9 @@ import ( "encoding/json" "fmt" "os" + "os/signal" "strings" + "syscall" "github.com/urfave/cli/v2" "golang.org/x/term" @@ -335,6 +337,20 @@ var walletImport = &cli.Command{ if !cctx.Args().Present() || cctx.Args().First() == "-" { if term.IsTerminal(int(os.Stdin.Fd())) { fmt.Print("Enter private key(not display in the terminal): ") + + // Create a channel to receive OS signals + sigCh := make(chan os.Signal, 1) + // Notify the channel when SIGINT is received + signal.Notify(sigCh, syscall.SIGINT) + + go func() { + // Wait for SIGINT signal + <-sigCh + // Perform cleanup or other actions as needed + fmt.Println("\nInterrupt signal received. Exiting...") + os.Exit(1) + }() + inpdata, err = term.ReadPassword(int(os.Stdin.Fd())) if err != nil { return err From 5edc7dcdb3b6796ee4f3c3b21ec69340efffbd2e Mon Sep 17 00:00:00 2001 From: Phi Date: Mon, 21 Aug 2023 10:37:42 +0200 Subject: [PATCH 2/2] Consider SIGTERM as well Consider SIGTERM as well --- cli/wallet.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cli/wallet.go b/cli/wallet.go index 8d44d3ef2..628d6841d 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -338,15 +338,12 @@ var walletImport = &cli.Command{ if term.IsTerminal(int(os.Stdin.Fd())) { fmt.Print("Enter private key(not display in the terminal): ") - // Create a channel to receive OS signals sigCh := make(chan os.Signal, 1) // Notify the channel when SIGINT is received - signal.Notify(sigCh, syscall.SIGINT) + signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) go func() { - // Wait for SIGINT signal <-sigCh - // Perform cleanup or other actions as needed fmt.Println("\nInterrupt signal received. Exiting...") os.Exit(1) }()