Skip to content
Advertisement

How do not write provided characters to bash stdout when program interrupted on getpass?

I have the simple code witch get password by getpass:

if (!(pass = getpass("Enter password:n"))) {
    perror("getpass failed");
    return -1;
}

Also I have a signal handler witch exit program.

If signal was caught at the time of getting password from terminal, program stops, but all provided by user characters appears on bash prompt.

Code of signal handler:

void handle (int sig) {
    printf("Time for password entering expired!n");
    /* Enable echo on terminal after aborted getpass*/
    system("stty echo");
    exit(-1);
}

How can I make bash prompt clear after interrupt program by signal?

Advertisement

Answer

Using of termios resolved problem.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement