From c1fd48a14bc83e237e1de8cb44e833ac6ff3584e Mon Sep 17 00:00:00 2001 From: Phi Date: Mon, 21 Aug 2023 09:10:47 +0200 Subject: [PATCH] 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