mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] boot: fix multiple boot sources
@ 2014-05-13  6:23 Sascha Hauer
  2014-05-13  6:23 ` [PATCH 2/2] boot: iterate over directories in alphabetical order Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2014-05-13  6:23 UTC (permalink / raw)
  To: barebox

When there are multiple bootsources barebox should try booting them
until one succeeds. This is broken because we bail out of the iteration
loop with a goto. Remove the goto to fix this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/boot.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/commands/boot.c b/commands/boot.c
index 4a83979..468d473 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -446,7 +446,6 @@ static int do_boot(int argc, char *argv[])
 		ret = boot(sources[i]);
 		if (!ret)
 			break;
-		goto out;
 	}
 
 out:
-- 
2.0.0.rc0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] boot: iterate over directories in alphabetical order
  2014-05-13  6:23 [PATCH 1/2] boot: fix multiple boot sources Sascha Hauer
@ 2014-05-13  6:23 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2014-05-13  6:23 UTC (permalink / raw)
  To: barebox

When iterating over directories in order to find boot scripts do
this alphabetically to get a predictable order. This can be done
with glob() rather than readdir().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/boot.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/commands/boot.c b/commands/boot.c
index 468d473..a23ffb1 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -23,6 +23,7 @@
 #include <malloc.h>
 #include <clock.h>
 #include <boot.h>
+#include <glob.h>
 #include <menu.h>
 #include <fs.h>
 #include <complete.h>
@@ -129,10 +130,10 @@ static int bootscript_create_entry(struct blspec *blspec, const char *name)
 static int bootscript_scan_path(struct blspec *blspec, const char *path)
 {
 	struct stat s;
-	DIR *dir;
-	struct dirent *d;
-	int ret;
+	char *files;
+	int ret, i;
 	int found = 0;
+	glob_t globb;
 
 	ret = stat(path, &s);
 	if (ret)
@@ -145,25 +146,24 @@ static int bootscript_scan_path(struct blspec *blspec, const char *path)
 		return 1;
 	}
 
-	dir = opendir(path);
-	if (!dir)
-		return -errno;
+	files = asprintf("%s/*", path);
+
+	glob(files, 0, NULL, &globb);
 
-	while ((d = readdir(dir))) {
-		char *bootscript_path;
+	for (i = 0; i < globb.gl_pathc; i++) {
+		char *bootscript_path = globb.gl_pathv[i];;
 
-		if (*d->d_name == '.')
+		if (*basename(bootscript_path) == '.')
 			continue;
 
-		bootscript_path = asprintf("%s/%s", path, d->d_name);
 		bootscript_create_entry(blspec, bootscript_path);
 		found++;
-		free(bootscript_path);
 	}
 
-	ret = found;
+	globfree(&globb);
+	free(files);
 
-	closedir(dir);
+	ret = found;
 
 	return ret;
 }
-- 
2.0.0.rc0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-13  6:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-13  6:23 [PATCH 1/2] boot: fix multiple boot sources Sascha Hauer
2014-05-13  6:23 ` [PATCH 2/2] boot: iterate over directories in alphabetical order Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox