andrewgregory / pacutils

Helper library for libalpm based programs.
MIT License
107 stars 17 forks source link

Check if stdin is a tty before initializing libalpm #45

Closed CyberShadow closed 3 years ago

CyberShadow commented 3 years ago
Using the recommended pattern of invoking pacsift et al with <&-
causes the file descriptor 0 to not be valid. However, this also makes
it available for being allocated by calls to open or socket.

While this pattern worked as expected with previous versions of
pacman/libalpm, this is no longer true, as alpm_initialize now creates
a socket, which is allocated at file descriptor 0 if it is free. This
causes the isatty check to now fail with ENOTTY instead of EBADF,
causing the tools to think they were invoked with a list of packages
on their standard input.

Fix this by moving the stdin check at the top of each program, before
any other initialization. (For consistency, this was done whether or
not the program's initialization involves libalpm.)

This is blocking aconfmgr and should fix https://github.com/AladW/aurutils/issues/804.

Thanks!

CyberShadow commented 3 years ago

@andrewgregory Thanks for merging this; any chance of a new tag? This functionality is currently broken with the latest pacman version + the latest pacutils version.