From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 09/19] glob: do not unnecessarily opendir() a directory
Date: Tue, 3 Apr 2018 09:48:41 +0200 [thread overview]
Message-ID: <20180403074851.5411-10-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180403074851.5411-1-s.hauer@pengutronix.de>
opendir() can trigger automounts, so do not use it when the
pattern we examine doesn't have any wildcards.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
lib/glob.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/glob.c b/lib/glob.c
index 5a997ca092..32f7afdce8 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -313,7 +313,7 @@ static int prefix_array(const char *dirname, char **array, size_t n,
static int glob_in_dir(const char *pattern, const char *directory,
int flags, int (*errfunc) __P((const char *, int)), glob_t *pglob)
{
- __ptr_t stream;
+ __ptr_t stream = NULL;
struct globlink {
struct globlink *next;
@@ -323,7 +323,13 @@ static int glob_in_dir(const char *pattern, const char *directory,
size_t nfound = 0;
int meta;
- stream = opendir(directory);
+ meta = glob_pattern_p(pattern, !(flags & GLOB_NOESCAPE));
+
+ if (meta)
+ flags |= GLOB_MAGCHAR;
+
+ if (meta)
+ stream = opendir(directory);
if (stream == NULL) {
if ((errfunc != NULL && (*errfunc) (directory, errno)) ||
@@ -331,11 +337,6 @@ static int glob_in_dir(const char *pattern, const char *directory,
return GLOB_ABORTED;
}
- meta = glob_pattern_p(pattern, !(flags & GLOB_NOESCAPE));
-
- if (meta)
- flags |= GLOB_MAGCHAR;
-
while (1) {
const char *name;
size_t len;
--
2.16.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-04-03 7:49 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-03 7:48 [PATCH 00/19] Add Linux dcache implementation Sascha Hauer
2018-04-03 7:48 ` [PATCH 01/19] rename file_operations -> cdev_operations Sascha Hauer
2018-04-03 7:48 ` [PATCH 02/19] ubifs: remove dead code Sascha Hauer
2018-04-03 7:48 ` [PATCH 03/19] ubifs: Remove Linux struct definitions we already have Sascha Hauer
2018-04-03 7:48 ` [PATCH 04/19] ubifs: remove dead code Sascha Hauer
2018-04-03 7:48 ` [PATCH 05/19] fs: Add super_operations Sascha Hauer
2018-04-03 7:48 ` [PATCH 06/19] fs: Move mem_write/mem_read to devfs-core Sascha Hauer
2018-04-03 7:48 ` [PATCH 07/19] fs: Cleanup whitespace damage Sascha Hauer
2018-04-03 7:48 ` [PATCH 08/19] fs: Fix finding correct directory for mkdir/rmdir Sascha Hauer
2018-04-03 7:48 ` Sascha Hauer [this message]
2018-04-03 7:48 ` [PATCH 10/19] ls: Do not depend on normalise_path() Sascha Hauer
2018-04-03 7:48 ` [PATCH 11/19] loadenv: " Sascha Hauer
2018-04-03 7:48 ` [PATCH 12/19] fs: dcache implementation Sascha Hauer
2018-04-03 7:48 ` [PATCH 13/19] fs: ramfs: Switch to " Sascha Hauer
2018-04-03 7:48 ` [PATCH 14/19] fs: devfs: " Sascha Hauer
2018-04-03 7:48 ` [PATCH 15/19] fs: ext4: " Sascha Hauer
2018-04-03 7:48 ` [PATCH 16/19] fs: ubifs: " Sascha Hauer
2018-04-03 7:48 ` [PATCH 17/19] fs: nfs: " Sascha Hauer
2018-04-03 7:48 ` [PATCH 18/19] fs: tftp: " Sascha Hauer
2018-05-18 11:54 ` Philipp Zabel
2018-05-22 7:12 ` Sascha Hauer
2018-05-22 8:21 ` Philipp Zabel
2018-04-03 7:48 ` [PATCH 19/19] block: Adjust cache sizes Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180403074851.5411-10-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox