summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-07-24 20:48:06 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-08-09 07:13:02 +0200
commit206a4bc31fb518fadfd10e857cf7492442b54b59 (patch)
tree1460002adebf542e17131b06d6f95e0a28bda311 /common
parent9f2a25821ec81bded78ddea833b543a96f4639f3 (diff)
downloadbarebox-206a4bc31fb518fadfd10e857cf7492442b54b59.tar.gz
barebox-206a4bc31fb518fadfd10e857cf7492442b54b59.tar.xz
blspec: iterate over entries in lexical order
We already iterate over boot scripts in lexical order, so it makes sense to do the same for bootspec entries. This way, it's stable which boot entry will be taken, when multiple match. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220724184807.2123459-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/blspec.c43
1 files changed, 10 insertions, 33 deletions
diff --git a/common/blspec.c b/common/blspec.c
index 079f9757ec..b7cf2193dd 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -15,6 +15,7 @@
#include <libbb.h>
#include <init.h>
#include <bootm.h>
+#include <glob.h>
#include <net.h>
#include <fs.h>
#include <of.h>
@@ -570,54 +571,30 @@ int blspec_scan_file(struct bootentries *bootentries, const char *root,
*/
int blspec_scan_directory(struct bootentries *bootentries, const char *root)
{
- DIR *dir;
- struct dirent *d;
+ glob_t globb;
char *abspath;
int ret, found = 0;
const char *dirname = "loader/entries";
+ int i;
pr_debug("%s: %s %s\n", __func__, root, dirname);
- abspath = basprintf("%s/%s", root, dirname);
+ abspath = basprintf("%s/%s/*.conf", root, dirname);
- dir = opendir(abspath);
- if (!dir) {
+ ret = glob(abspath, 0, NULL, &globb);
+ if (ret) {
pr_debug("%s: %s: %s\n", __func__, abspath, strerror(errno));
ret = -errno;
goto err_out;
}
- while ((d = readdir(dir))) {
- char *configname;
+ for (i = 0; i < globb.gl_pathc; i++) {
+ const char *configname = globb.gl_pathv[i];
struct stat s;
- char *dot;
-
- if (*d->d_name == '.')
- continue;
-
- configname = basprintf("%s/%s", abspath, d->d_name);
-
- dot = strrchr(configname, '.');
- if (!dot) {
- free(configname);
- continue;
- }
-
- if (strcmp(dot, ".conf")) {
- free(configname);
- continue;
- }
ret = stat(configname, &s);
- if (ret) {
- free(configname);
+ if (ret || !S_ISREG(s.st_mode))
continue;
- }
-
- if (!S_ISREG(s.st_mode)) {
- free(configname);
- continue;
- }
ret = blspec_scan_file(bootentries, root, configname);
if (ret > 0)
@@ -626,7 +603,7 @@ int blspec_scan_directory(struct bootentries *bootentries, const char *root)
ret = found;
- closedir(dir);
+ globfree(&globb);
err_out:
free(abspath);