I was about to do a 'yum update' on a system I rarely use. What I normally do is this # screen # yum update but this particular system did not have the screen(1) command installed. So /usr/libexec/pk-command-not-found stepped in and offered to install it for me... but since I had already begun typing 'yum update' it intercepted the 'y' and just installed the screen package for me. I think this is a bit dangerous - you should wait for the user to press y, then enter before going ahead. Also, when screen(1) was finally installed and pk-command-not-found tried to run it, things didn't work because of this bug https://bugzilla.redhat.com/show_bug.cgi?id=682242 because of issues with handling and passing the standard streams.
(In reply to comment #0) > I think this is a bit dangerous - you should wait for the user to press y, then > enter before going ahead. Yes, agreed. I've played with getc() a bit, but this would still no do what you wanted as <y><u><m>..whatever..<enter> would still proceed. Is there any best practice for doing this kind of thing? My next option was just using fgets, but that's pretty odd in itself. Advice welcome. Thanks.
(In reply to comment #1) > (In reply to comment #0) > > I think this is a bit dangerous - you should wait for the user to press y, then > > enter before going ahead. > > Yes, agreed. I've played with getc() a bit, but this would still no do what you > wanted as <y><u><m>..whatever..<enter> would still proceed. Is there any best > practice for doing this kind of thing? My next option was just using fgets, but > that's pretty odd in itself. Advice welcome. Thanks. Yeah, see http://cgit.freedesktop.org/PolicyKit/tree/src/polkitagent/polkitagenttextlistener.c?id=0.102#n227 where listener->tty is set like this http://cgit.freedesktop.org/PolicyKit/tree/src/polkitagent/polkitagenttextlistener.c?id=0.102#n152 E.g.: just open /dev/tty, use tcsetattr() appropriately ('man tcsetattr' for details) and use getc() until '\n' is returned and then restore the terminal mode. You might want to use different flags so the output is echoed since you are not requesting a password.
commit 921d41521b481eb80fa9656f804306520586599d Author: Richard Hughes <richard@hughsie.com> Date: Wed Oct 5 12:55:41 2011 +0100 Require exactly 'y<enter>' or 'yes<enter>' before running a transaction Resolves https://bugs.freedesktop.org/show_bug.cgi?id=41444
(In reply to comment #3) > commit 921d41521b481eb80fa9656f804306520586599d > Author: Richard Hughes <richard@hughsie.com> > Date: Wed Oct 5 12:55:41 2011 +0100 > > Require exactly 'y<enter>' or 'yes<enter>' before running a transaction > > Resolves https://bugs.freedesktop.org/show_bug.cgi?id=41444 Cool, thanks for fixing this. (And it looks like you are using /dev/tty for input which is great - so you partially resolved https://bugzilla.redhat.com/show_bug.cgi?id=682242 - the other half is to also use /dev/tty for all output).
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.