0

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?

Shadasviar
  • 466
  • 5
  • 15
  • Will [flushing `stdin`](https://stackoverflow.com/questions/7898215/how-to-clear-input-buffer-in-c) in the handler (before turning echo on) work? – Eugene Sh. Nov 30 '17 at 17:08
  • @EugeneSh. Using of different types of getting char or reading from stdin cause that program do not stop in handle but waits for the next line ending character on stdin. Functions like fpurge has no effect for me. – Shadasviar Nov 30 '17 at 19:21

1 Answers1

0

Using of termios resolved problem.

Shadasviar
  • 466
  • 5
  • 15