index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Dave Reisner <d@falconindy.com> | 2010-11-04 16:05:28 -0400 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-11-04 21:10:32 -0500 |
commit | 4fb3cfc48f626f84329c78351d6a8710255a35e3 (patch) | |
tree | 565967136382130ddc850ceac030c7543c635909 /src/pacman | |
parent | 0f3957ab48f34df8e151ec026dfac0d9d2df5aec (diff) |
-rw-r--r-- | src/pacman/pacman.c | 33 |
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 15abecc5..e078aaba 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -26,6 +26,7 @@ #define PACKAGE_VERSION GIT_VERSION #endif +#include <ctype.h> /* isspace */ #include <stdlib.h> /* atoi */ #include <stdio.h> #include <limits.h> @@ -1305,6 +1306,38 @@ int main(int argc, char *argv[]) cleanup(ret); } + /* read package arguments from stdin if we have none yet */ + if(!pm_targets && !isatty(fileno(stdin))) { + char line[PATH_MAX]; + int i = 0; + while(i < PATH_MAX && (line[i] = fgetc(stdin)) != EOF) { + if(isspace((unsigned char)line[i])) { + line[i] = '\0'; + /* avoid adding zero length arg when multiple spaces separate args */ + if(i > 0) { + pm_targets = alpm_list_add(pm_targets, strdup(line)); + i = 0; + } + } else { + i++; + } + } + /* check for buffer overflow */ + if (i >= PATH_MAX) { + pm_printf(PM_LOG_ERROR, _("buffer overflow detected in arg parsing\n")); + cleanup(EXIT_FAILURE); + } + + /* end of stream -- check for data still in line buffer */ + if(i > 0) { + pm_targets = alpm_list_add(pm_targets, strdup(line)); + } + if (!freopen(ctermid(NULL), "r", stdin)) { + pm_printf(PM_LOG_ERROR, _("failed to reopen stdin for reading: (%s)\n"), + strerror(errno)); + } + } + /* parse the config file */ ret = parseconfig(config->configfile); if(ret != 0) { |