mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] boot command: honour global.boot.default also for -l and -m
@ 2014-03-19 15:20 Sascha Hauer
  2014-03-19 15:20 ` [PATCH 2/2] boot command: only create boot entries from scripts Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2014-03-19 15:20 UTC (permalink / raw)
  To: barebox

The boot command is expected to work on bootsources from the commandline
if given, on global.boot.default otherwise. Fix this behaviour for the
-m and -l options also.

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

diff --git a/commands/boot.c b/commands/boot.c
index bb8d07f..9c7aa21 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -333,9 +333,11 @@ static int boot(const char *name)
 
 static int do_boot(int argc, char *argv[])
 {
-	const char *sources = NULL;
-	char *source, *freep;
+	char *freep = NULL;
 	int opt, ret = 0, do_list = 0, do_menu = 0;
+	char **sources;
+	int num_sources;
+	int i;
 
 	verbose = 0;
 	dryrun = 0;
@@ -361,47 +363,62 @@ static int do_boot(int argc, char *argv[])
 		}
 	}
 
-	if (do_list) {
-		bootsources_list(&argv[optind], argc - optind);
-		return 0;
-	}
+	if (optind < argc) {
+		num_sources = argc - optind;
+		sources = xmemdup(&argv[optind], sizeof(char *) * num_sources);
+	} else {
+		const char *def;
+		char *sep;
 
-	if (do_menu) {
-		bootsources_menu(&argv[optind], argc - optind);
-		return 0;
-	}
+		def = getenv("global.boot.default");
+		if (!def)
+			return 0;
 
-	if (optind < argc) {
-		while (optind < argc) {
-			source = argv[optind];
-			optind++;
-			ret = boot(source);
-			if (!ret)
+		sep = freep = xstrdup(def);
+
+		num_sources = 0;
+
+		while (1) {
+			num_sources++;
+
+			sep = strchr(sep, ' ');
+			if (!sep)
 				break;
+			sep++;
+		}
+
+		sources = xmalloc(sizeof(char *) * num_sources);
+
+		sep = freep;
+
+		for (i = 0; i < num_sources; i++) {
+			sources[i] = sep;
+			sep = strchr(sep, ' ');
+			if (sep)
+				*sep = 0;
+			sep++;
 		}
-		return ret;
 	}
 
-	sources = getenv("global.boot.default");
-	if (!sources)
-		return 0;
+	if (do_list) {
+		bootsources_list(sources, num_sources);
+		goto out;
+	}
 
-	freep = source = xstrdup(sources);
+	if (do_menu) {
+		bootsources_menu(sources, num_sources);
+		goto out;
+	}
 
-	while (1) {
-		char *sep = strchr(source, ' ');
-		if (sep)
-			*sep = 0;
-		ret = boot(source);
+	for (i = 0; i < num_sources; i++) {
+		ret = boot(sources[i]);
 		if (!ret)
 			break;
-
-		if (sep)
-			source = sep + 1;
-		else
-			break;
+		goto out;
 	}
 
+out:
+	free(sources);
 	free(freep);
 
 	return ret;
-- 
1.9.0


_______________________________________________
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 command: only create boot entries from scripts
  2014-03-19 15:20 [PATCH 1/2] boot command: honour global.boot.default also for -l and -m Sascha Hauer
@ 2014-03-19 15:20 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2014-03-19 15:20 UTC (permalink / raw)
  To: barebox

When given a directory ignore all files that are not shell scripts.

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

diff --git a/commands/boot.c b/commands/boot.c
index 9c7aa21..a54d0d5 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -106,6 +106,11 @@ static void bootsource_action(struct menu *m, struct menu_entry *me)
 static int bootscript_create_entry(struct blspec *blspec, const char *name)
 {
 	struct blspec_entry *be;
+	enum filetype type;
+
+	type = file_name_detect_type(name);
+	if (type != filetype_sh)
+		return -EINVAL;
 
 	be = blspec_entry_alloc(blspec);
 	be->me.type = MENU_ENTRY_NORMAL;
-- 
1.9.0


_______________________________________________
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-03-19 15:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-19 15:20 [PATCH 1/2] boot command: honour global.boot.default also for -l and -m Sascha Hauer
2014-03-19 15:20 ` [PATCH 2/2] boot command: only create boot entries from scripts Sascha Hauer

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