Handle Ctrl+C and Ctrl+Z in gpass_cli
This commit is contained in:
parent
35f49d24b3
commit
0caa8a66e1
16
cli/main.c
16
cli/main.c
|
@ -21,6 +21,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <openssl/opensslv.h>
|
||||
|
@ -71,12 +72,18 @@ static EVP_MD_CTX ss_md_ctx;
|
|||
static const EVP_MD * s_md_256;
|
||||
|
||||
static EVP_CIPHER_CTX * s_cipher_ctx;
|
||||
static int s_stop_display = 0;
|
||||
|
||||
static void signal_handler(int signum)
|
||||
{
|
||||
s_stop_display = 1;
|
||||
}
|
||||
|
||||
static void display_password(char* password, int time)
|
||||
{
|
||||
int length;
|
||||
|
||||
for (; time; time--)
|
||||
for (; time && !s_stop_display; time--)
|
||||
{
|
||||
printf("\r(%02d) Password found: %s", time, password);
|
||||
fflush(stdout);
|
||||
|
@ -85,7 +92,7 @@ static void display_password(char* password, int time)
|
|||
|
||||
// Clear line
|
||||
printf("\r");
|
||||
length = 4 + 17 + strlen(password) + 1;
|
||||
length = 4 + 17 + strlen(password) + 1 + 1 /* For Ctrl+Z/C */;
|
||||
while (length--)
|
||||
printf(" ");
|
||||
printf("\n");
|
||||
|
@ -695,6 +702,11 @@ int main(int argc, char** argv)
|
|||
params.orig_master_key = strdup(tmp);
|
||||
derive_master_key(¶ms);
|
||||
|
||||
// Ctrl+C
|
||||
signal(SIGINT, signal_handler);
|
||||
// Ctrl+Z
|
||||
signal(SIGTSTP, signal_handler);
|
||||
|
||||
ret = ask_server(¶ms);
|
||||
|
||||
// try again with new parameters
|
||||
|
|
Loading…
Reference in New Issue
Block a user