Welcome to the Pacman bug tracker. Please search the current bugs and feature requests before filing a new one! Use advanced search and select "Search in Comments".

* Please select the correct category and version.
* Write a descriptive summary, background info, and provide a reproducible test case whenever possible.

FS#20538 - Do not buffer input from keyboard

Attached to Project: Pacman
Opened by Mario Figueiredo (marfig) - Friday, 20 August 2010, 14:56 GMT
Last edited by Dave Reisner (falconindy) - Tuesday, 07 June 2011, 20:55 GMT
Task Type Feature Request
Category Output
Status Closed
Assigned To No-one
Architecture All
Severity Low
Priority Normal
Reported Version 3.4.0
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No


Summary and Info:
Could pacman not collect input from the keyboard until it requests for it?
If accidentally hit the enter key twice (to perform a -Syu for instance), or if I hit it during the time it is synchronizing or resolving dependencies, the key gets buffered and sent immediately on next input request. This may result in an unwanted action.

Steps to Reproduce:
Pacman -S <package>
Pacman -Syu
Perform above commands by tapping twice on the enter key
This task depends upon

Closed by  Dave Reisner (falconindy)
Tuesday, 07 June 2011, 20:55 GMT
Reason for closing:  Implemented
Additional comments about closing:  Commit: /commit/?id=9477abc3591905a20acbfe7b8ce7 832617d72701
Comment by Mario Figueiredo (marfig) - Friday, 20 August 2010, 14:59 GMT
It also results in better accessibility.
Comment by Dan McGee (toofishes) - Monday, 23 August 2010, 23:01 GMT
Any examples of a C program "protecting" against this out there that we might be able to get an idea from? I'm no expert in this area and it would be a timesink for me without an example.
Comment by Mario Figueiredo (marfig) - Monday, 23 August 2010, 23:33 GMT
#include <stdio.h>

Should work, if you place it before your getc. It will flush out any characters in the input buffer. Your getc will then wait for input.
Comment by Dan McGee (toofishes) - Friday, 08 October 2010, 13:09 GMT
I tried putting an fflush(stdin); into question() in src/pacman/util.c, and it was a no-go- the read call immediately after still picked up the characters I typed before the prompt appeared during the -Syu operation.

I'm cool with this idea, but I'm going to need a working patch to make it happen as the obvious didn't work here.
Comment by Dave Reisner (falconindy) - Friday, 18 March 2011, 14:55 GMT
Flushing the stdin stream is actually the wrong approach, and results in undefined behavior according to C99. The correct approach seems to be to flush the terminal's input buffer of data that hasn't yet been handled by the application.

Seems to work for me. I'm dubious as to the portability of such a feature, but it does appear to be specified by POSIX.

update: setup cygwin on my work machine and it compiles. tcflush even returns success. Someone in #archlinux compiled and ran for me on FreeBSD and they report the same.