[PATCH v2 5/7] commands: make run_command variadic

Marco Felsch m.felsch at pengutronix.de
Mon Feb 23 03:13:44 PST 2026


On 26-02-23, Ahmad Fatoum wrote:
> On 2/23/26 12:03 PM, Sascha Hauer wrote:
> > On Thu, Feb 12, 2026 at 11:02:07PM +0100, Marco Felsch wrote:
> >> This prepares run_command() to receive a format string and variadic
> >> arguments which can become quite handy for board code. It also ensures
> >> a proper cleanup for the command string and generalizes the error
> >> message printing.
> >>
> >> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> >> ---
> >>  common/hush.c     | 23 ++++++++++++++++++++++-
> >>  common/parser.c   | 24 +++++++++++++++++++++++-
> >>  include/command.h |  4 ++--
> >>  3 files changed, 47 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/common/hush.c b/common/hush.c
> >> index 2e0cc4229d3575dcf045f68ef8db3e943c41eedb..b46a42cc90c863376bb819755afc83271120200f 100644
> >> --- a/common/hush.c
> >> +++ b/common/hush.c
> >> @@ -1922,7 +1922,7 @@ static char * make_string(char ** inp)
> >>  	return str;
> >>  }
> >>  
> >> -int run_command(const char *cmd)
> >> +static int __run_command(const char *cmd)
> >>  {
> >>  	struct p_context ctx = {};
> >>  	int ret;
> >> @@ -1938,6 +1938,27 @@ int run_command(const char *cmd)
> >>  	return ret;
> >>  }
> >>  
> >> +int run_command(const char *fmt, ...)
> >> +{
> >> +	va_list vargs;
> >> +	char *cmd;
> >> +	int error;
> >> +
> >> +	va_start(vargs, fmt);
> >> +	cmd = xvasprintf(fmt, vargs);
> >> +	va_end(vargs);
> >> +
> >> +	error = __run_command(cmd);
> >> +	if (error) {
> >> +		error_msg("Failed to run CMD: '%s' with %d\n", cmd, error);
> >> +		free(cmd);
> >> +		return error;
> >> +	}
> > 
> > Dropped this error printing while applying. There was no error printing
> > before this patch and also some commands might intentionally silently
> > fail, so error printing should be done in the caller.
> 
> Good catch. gpio_get_value comes to mind where this would be rather
> confusing.

Sure, I thought it come in handy but I get your point! Thanks for the
inline fixup.

Regards,
  Marco


> 
> Cheers,
> Ahmad
> 
> > 
> > Sascha
> > 
> 
> -- 
> Pengutronix e.K.                  |                             |
> Steuerwalder Str. 21              | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
> 
> 

-- 
#gernperDu 
#CallMeByMyFirstName

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | https://www.pengutronix.de/ |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-9    |



More information about the barebox mailing list