[PATCH v2 6/7] treewide: make use of new run_command variadic

Marco Felsch m.felsch at pengutronix.de
Thu Feb 12 14:02:08 PST 2026


Since run_command accepts variadic inputs we no longer need to alloc the
cmd buffer and instead let run_command do the job for us.

Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
 common/startup.c |  5 +----
 net/ifup.c       | 10 +++-------
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index 055d94fe6ab6d477c2d088108d7944974cebe587..dd643182043f13def7e06a1ea80a7f35d346c550 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -321,7 +321,6 @@ static int run_init(void)
 	if (!ret) {
 		for (i = 0; i < g.gl_pathc; i++) {
 			const char *path = g.gl_pathv[i];
-			char *scr;
 
 			ret = stat(path, &s);
 			if (ret)
@@ -331,9 +330,7 @@ static int run_init(void)
 				continue;
 
 			pr_debug("Executing '%s'...\n", path);
-			scr = basprintf("source %s", path);
-			run_command(scr);
-			free(scr);
+			run_command("source %s", path);
 		}
 
 		globfree(&g);
diff --git a/net/ifup.c b/net/ifup.c
index 0a0c94f6f2a6ba7571514504f3050076a23a893a..bd821535e8b364091ea689588a35b45d50285cf3 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -66,7 +66,7 @@ static int source_env_network(struct eth_device *edev)
 	};
 	IPaddr_t ipaddr, netmask, gateway, serverip;
 	unsigned char ethaddr[6];
-	char *file, *cmd;
+	char *file;
 	const char *ethaddrstr, *modestr, *linuxdevname;
 	int ret, mode, ethaddr_valid = 0, i;
 	struct stat s;
@@ -87,12 +87,9 @@ static int source_env_network(struct eth_device *edev)
 	for (i = 0; i < ARRAY_SIZE(vars); i++)
 		unsetenv(vars[i]);
 
-	cmd = basprintf("source /env/network/%s", edev->devname);
-	ret = run_command(cmd);
-	if (ret) {
-		pr_err("Running '%s' failed with %d\n", cmd, ret);
+	ret = run_command("source /env/network/%s", edev->devname);
+	if (ret)
 		goto out;
-	}
 
 	ipaddr = getenv_ip("ipaddr");
 	netmask = getenv_ip("netmask");
@@ -150,7 +147,6 @@ static int source_env_network(struct eth_device *edev)
 
 out:
 	env_pop_context();
-	free(cmd);
 	free(file);
 
 	return ret;

-- 
2.47.3




More information about the barebox mailing list