我有通过 getpass 获取密码的简单代码:
if (!(pass = getpass("Enter password:\n"))) {
perror("getpass failed");
return -1;
}
我还有一个信号处理女巫退出程序。
如果在从终端获取密码时捕获到信号,程序将停止,但所有由用户提供的字符都会出现在 bash 提示符上。
信号处理代码:
void handle (int sig) {
printf("Time for password entering expired!\n");
/* Enable echo on terminal after aborted getpass*/
system("stty echo");
exit(-1);
}
如何让信号中断程序后的bash提示变得清晰?
最佳答案
使用termios
已解决的问题。
关于c - 当程序在 getpass 上中断时,如何不将提供的字符写入 bash stdout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47578626/