에 새로운 프롬프트가 : 나는 SIGINT
(Ctrl+C
을 눌러 즉, 사용자)를 차단하도록 설정되어있어의 Readline : 내가 작성한 Readline 사용하여, 다음과 유사한 코드를 가지고 SIGINT
#include <errno.h>
#include <error.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <readline/readline.h>
#include <readline/history.h>
void handle_signals(int signo) {
if (signo == SIGINT) {
printf("You pressed Ctrl+C\n");
}
}
int main (int argc, char **argv)
{
//printf("path is: %s\n", path_string);
char * input;
char * shell_prompt = "i-shell> ";
if (signal(SIGINT, handle_signals) == SIG_ERR) {
printf("failed to register interrupts with kernel\n");
}
//set up custom completer and associated data strucutres
setup_readline();
while (1)
{
input = readline(shell_prompt);
if (!input)
break;
add_history(input);
//do something with the code
execute_command(input);
}
return 0;
}
를, 그래서 신호 처리기 handle_signals()
이 작동 중임을 알 수 있습니다. 그러나 제어가 readline()
으로 돌아 오면 입력하기 전에 사용했던 텍스트와 동일한 줄을 사용합니다. 내가하고 싶은 것은 readline이 현재의 텍스트 행을 취소하고 나에게 BASH 셸처럼 새로운 줄을주는 것이다. 다음과 같은 것 :
i-shell> bad_command^C
i-shell> _
이 문제가 발생할 가능성은? 내가 읽은 메일 링리스트의 어떤 것이 longjmp(2)
을 사용하여 언급되었지만 실제로는 좋은 생각처럼 보이지 않습니다.
신호 처리기에서'printf'를 안전하게 호출 할 수 없습니다. – pat