Bug 41444 - command-not-found should wait for return to be pressed
Summary: command-not-found should wait for return to be pressed
Status: RESOLVED FIXED
Alias: None
Product: PackageKit
Classification: Unclassified
Component: General (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Richard Hughes
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-04 04:26 UTC by David Zeuthen (not reading bugmail)
Modified: 2011-10-05 06:38 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description David Zeuthen (not reading bugmail) 2011-10-04 04:26:32 UTC
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.
Comment 1 Richard Hughes 2011-10-04 06:45:11 UTC
(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.
Comment 2 David Zeuthen (not reading bugmail) 2011-10-04 07:22:17 UTC
(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.
Comment 3 Richard Hughes 2011-10-05 05:33:45 UTC
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
Comment 4 David Zeuthen (not reading bugmail) 2011-10-05 06:38:42 UTC
(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.