Handle SIGINT when searching in editline
This commit is contained in:
parent
51747090a8
commit
301f582002
1 changed files with 8 additions and 0 deletions
|
|
@ -257,16 +257,24 @@ static int cli_check_secret(const char *source)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cli_quitting = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get next character from stdin, or EOF if got a SIGINT signal
|
* Get next character from stdin, or EOF if got a SIGINT signal
|
||||||
*/
|
*/
|
||||||
static int interruptible_getc(void)
|
static int interruptible_getc(void)
|
||||||
{
|
{
|
||||||
|
if( cli_quitting )
|
||||||
|
return EOF;
|
||||||
|
|
||||||
int r;
|
int r;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
r = read(0, &c, 1); // read from stdin, will return -1 on SIGINT
|
r = read(0, &c, 1); // read from stdin, will return -1 on SIGINT
|
||||||
|
|
||||||
|
if( r == -1 && errno == EINTR )
|
||||||
|
cli_quitting = true;
|
||||||
|
|
||||||
return r == 1 ? c : EOF;
|
return r == 1 ? c : EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue