aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2015-05-19 11:57:54 -0400
committerMike Frysinger <vapier@gentoo.org>2015-05-19 11:57:54 -0400
commitc6bd6041822a9f968c068757722858f6e481c341 (patch)
tree9ec1b46e725fdfe26332118b2cdc083f1e7bc214
parentqglsa: update code to latest APIs (diff)
downloadportage-utils-c6bd6041822a9f968c068757722858f6e481c341.tar.gz
portage-utils-c6bd6041822a9f968c068757722858f6e481c341.tar.bz2
portage-utils-c6bd6041822a9f968c068757722858f6e481c341.zip
quse: use the cache file given and avoid cwd assumptions
This allows us to rework the internals of the cache funcs and not need any specific chdir configuration by switching to the *at style funcs.
-rw-r--r--quse.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/quse.c b/quse.c
index 534cf41b..dddbf5b0 100644
--- a/quse.c
+++ b/quse.c
@@ -214,6 +214,7 @@ quse_describe_flag(unsigned int ind, unsigned int argc, char **argv)
int quse_main(int argc, char **argv)
{
FILE *fp;
+ const char *cache_file;
char *p;
char buf0[_Q_PATH_MAX];
@@ -251,19 +252,31 @@ int quse_main(int argc, char **argv)
return quse_describe_flag(optind, argc, argv);
if (quse_all) optind = argc;
- initialize_ebuild_flat(); /* sets our pwd to $PORTDIR */
+ cache_file = initialize_ebuild_flat();
search_len = strlen(search_vars[idx]);
assert(search_len < sizeof(buf0));
- if ((fp = fopen(CACHE_EBUILD_FILE, "r")) == NULL)
+ if ((fp = fopen(cache_file, "r")) == NULL) {
+ warnp("could not read cache: %s", cache_file);
return 1;
+ }
+
+ int portdir_fd = open(portdir, O_RDONLY|O_CLOEXEC|O_PATH);
+
ebuild = NULL;
while (getline(&ebuild, &ebuildlen, fp) != -1) {
FILE *newfp;
+ int fd;
+
if ((p = strchr(ebuild, '\n')) != NULL)
*p = 0;
- if ((newfp = fopen(ebuild, "r")) != NULL) {
+
+ fd = openat(portdir_fd, ebuild, O_RDONLY|O_CLOEXEC);
+ if (fd < 0)
+ continue;
+ newfp = fdopen(fd, "r");
+ if (newfp != NULL) {
unsigned int lineno = 0;
char revision[sizeof(buf0)];
char date[sizeof(buf0)];
@@ -408,6 +421,7 @@ int quse_main(int argc, char **argv)
}
}
fclose(fp);
+ close(portdir_fd);
return EXIT_SUCCESS;
}