-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Simon Josefsson wrote: > Another problem that I discovered is that gnulib's getpass.c inhibits > signals, so the user cannot press ^C/^Z. This is even more of a problem > when the user needs to type the same password twice: the process may be > stuck in a loop that can't be canceled waiting for the user to type two > identical strings.
Yes, I would have preferred to let ^C gracefully terminate the program, as well (and ^Z could perhaps result in a newline being output before suspension, with the prompt re-issued upon SIGCONT). Ideally, it would add an extra newline to its output for that condition as well. The problem with that, of course, is that a program may well wish to do other things as well, in response to a signal, and so it may not be wise to have the getpass-like facility install its own temporary signal handles. However, letting the application use its own signal handlers still leaves the problem of the app not knowing where it might want to send an extra newline (and, the bother of having to reopen /dev/tty, when it had potentially just been opened a moment ago by getpass). It seems to me then that the "find appropriate interactive file streams" logic should be split off separately, so that the app has full knowledge of what streams are being used for communication (or can even specify alternatives). This would also eliminate the need for a separate getpassword_confirmed function; it could also potentially be used for a gnupg-agent-style mechanism (I don't know: I'm not clear on how that usually works). Usage something like: FILE *in, *out; get_interactive_device (&in, &out, GID_DISABLE_SIGNALS); for (;;) { char *pass1, *pass2; pass1 = getpassword ("Password: ", in, out); /* Check pass1 against NULL here */ pass2 = getpassword ("Re-enter password: ", in, out); /* And here for pass2 */ if (! strcmp (pass1, pass2)) break; fputs ("Passwords don't match, plase try again.\n", out); } Note that, the above only works if getpassword returns newly allocated space, intended for deallocation by the app (which is IMO preferable anyway). Some folks would probably also want a version that gives them direct control over allocation/reallocation. - -- Micah J. Cowan Programmer, musician, typesetting enthusiast, gamer, and GNU Wget Project Maintainer. http://micah.cowan.name/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFIMUCe7M8hyUobTrERAlldAJ9OiImZBtM70rP4SdCrLUSNi2tfVgCeK20t 4RBZcgqn5FnauTqg/q2uEgc= =LTF0 -----END PGP SIGNATURE-----