From df93e790a66010a3a4cea4710dc8071cd1c76e7f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 1 Aug 2014 15:30:43 +0200 Subject: [PATCH] xbps_init: performance: do not chdir() unnecessarily for each conf file. --- lib/initend.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/initend.c b/lib/initend.c index ab97d9af..022be382 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -227,15 +227,6 @@ parse_file(struct xbps_handle *xhp, const char *cwd, const char *path, bool nest xbps_dbg_printf(xhp, "Parsing configuration file: %s\n", path); } - /* cwd to the dir containing the config file */ - strlcpy(tmppath, path, sizeof(tmppath)); - cfcwd = dirname(tmppath); - if (chdir(cfcwd) == -1) { - rv = errno; - xbps_dbg_printf(xhp, "cannot chdir to %s: %s\n", cfcwd, strerror(rv)); - return rv; - } - while ((read = getline(&line, &len, fp)) != -1) { char *p, *k, *v; @@ -283,6 +274,14 @@ parse_file(struct xbps_handle *xhp, const char *cwd, const char *path, bool nest if (strcmp(k, "include")) continue; + /* cwd to the dir containing the config file */ + strlcpy(tmppath, path, sizeof(tmppath)); + cfcwd = dirname(tmppath); + if (chdir(cfcwd) == -1) { + rv = errno; + xbps_dbg_printf(xhp, "cannot chdir to %s: %s\n", cfcwd, strerror(rv)); + return rv; + } if ((rv = parse_files_glob(xhp, cwd, v, true, false)) != 0) break;