[pacman-dev] [PATCH] die if '-' is given with empty stdin

Allan McRae allan at archlinux.org
Mon Jun 3 00:10:57 EDT 2013


On 03/06/13 13:45, Andrew Gregory wrote:
> Several operations default to all packages/repos/etc if no targets are
> provided.  If a user provides '-' they almost certainly expect there to
> be targets on stdin and will be surprised if pacman falls back to the
> default because there are none.
> 
> Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>

Signed-off-by: Me

> ---
>  src/pacman/pacman.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
> index 921331c..7aa0271 100644
> --- a/src/pacman/pacman.c
> +++ b/src/pacman/pacman.c
> @@ -826,6 +826,7 @@ int main(int argc, char *argv[])
>  	/* we support reading targets from stdin if a cmdline parameter is '-' */
>  	if(alpm_list_find_str(pm_targets, "-")) {
>  		if(!isatty(fileno(stdin))) {
> +			int target_found = 0;
>  			size_t current_size = PATH_MAX;
>  			char *vdata, *line = malloc(current_size);
>  
> @@ -840,6 +841,7 @@ int main(int argc, char *argv[])
>  					if(i > 0) {
>  						line[i] = '\0';
>  						pm_targets = alpm_list_add(pm_targets, strdup(line));
> +						target_found = 1;
>  						i = 0;
>  					}
>  				} else {
> @@ -869,12 +871,18 @@ int main(int argc, char *argv[])
>  			if(i > 0) {
>  				line[i] = '\0';
>  				pm_targets = alpm_list_add(pm_targets, strdup(line));
> +				target_found = 1;
>  			}
>  			free(line);
>  			if(!freopen(ctermid(NULL), "r", stdin)) {
>  				pm_printf(ALPM_LOG_ERROR, _("failed to reopen stdin for reading: (%s)\n"),
>  						strerror(errno));
>  			}
> +
> +			if(!target_found) {
> +				pm_printf(ALPM_LOG_ERROR, _("argument '-' specified with empty stdin\n"));
> +				cleanup(1);
> +			}
>  		} else {
>  			/* do not read stdin from terminal */
>  			pm_printf(ALPM_LOG_ERROR, _("argument '-' specified without input on stdin\n"));
> 



More information about the pacman-dev mailing list