c - 当程序在 getpass 上中断时,如何不将提供的字符写入 bash stdout?

标签 c linux unix

我有通过 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/

相关文章:

c - 了解 SIMD 随机播放控制掩码

c - 为什么编译器同时询问加入的日、月、年?

linux - 在 crontab 文件中重命名文件名

html - 搜索替换字符串模式将 px 添加到数值

linux - 绕过 Linux 集群网关 - 从桌面直接进入节点

c++ - 从 main 调用 C++ 源文件中的函数

c - c中的栈分配空间

php - 在主机上上传项目后禁止访问

git - Git 的提交日期或作者日期时间戳的分辨率是多少?

regex - 用注释替换字符串的特定出现