[settings] Use concat_args() in "set" command
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
f5fd4dec3b
commit
aebba8f6eb
|
@ -99,42 +99,38 @@ static struct command_descriptor set_cmd =
|
||||||
static int set_exec ( int argc, char **argv ) {
|
static int set_exec ( int argc, char **argv ) {
|
||||||
struct set_options opts;
|
struct set_options opts;
|
||||||
const char *name;
|
const char *name;
|
||||||
size_t len;
|
char *value;
|
||||||
int i;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse options */
|
||||||
if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
|
if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
|
||||||
return rc;
|
goto err_parse_options;
|
||||||
|
|
||||||
/* Parse setting name */
|
/* Parse setting name */
|
||||||
name = argv[optind];
|
name = argv[optind];
|
||||||
|
|
||||||
|
/* Parse setting value */
|
||||||
|
value = concat_args ( &argv[ optind + 1 ] );
|
||||||
|
if ( ! value ) {
|
||||||
|
rc = -ENOMEM;
|
||||||
|
goto err_concat_args;
|
||||||
|
}
|
||||||
|
|
||||||
/* Determine total length of command line */
|
/* Determine total length of command line */
|
||||||
len = 1; /* NUL */
|
if ( ( rc = storef_named_setting ( name, value ) ) != 0 ) {
|
||||||
for ( i = optind + 1 ; i < argc ; i++ )
|
|
||||||
len += ( 1 /* possible space */ + strlen ( argv[i] ) );
|
|
||||||
|
|
||||||
{
|
|
||||||
char buf[len];
|
|
||||||
char *ptr = buf;
|
|
||||||
|
|
||||||
/* Assemble command line */
|
|
||||||
buf[0] = '\0';
|
|
||||||
for ( i = optind + 1 ; i < argc ; i++ ) {
|
|
||||||
ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
|
|
||||||
argv[i] );
|
|
||||||
}
|
|
||||||
assert ( ptr < ( buf + len ) );
|
|
||||||
|
|
||||||
if ( ( rc = storef_named_setting ( name, buf ) ) != 0 ) {
|
|
||||||
printf ( "Could not set \"%s\"=\"%s\": %s\n",
|
printf ( "Could not set \"%s\"=\"%s\": %s\n",
|
||||||
name, buf, strerror ( rc ) );
|
name, value, strerror ( rc ) );
|
||||||
return rc;
|
goto err_store;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free ( value );
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_store:
|
||||||
|
free ( value );
|
||||||
|
err_concat_args:
|
||||||
|
err_parse_options:
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** "clear" options */
|
/** "clear" options */
|
||||||
|
|
|
@ -238,6 +238,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#define ERRFILE_sanboot_cmd ( ERRFILE_OTHER | 0x00200000 )
|
#define ERRFILE_sanboot_cmd ( ERRFILE_OTHER | 0x00200000 )
|
||||||
#define ERRFILE_bofm ( ERRFILE_OTHER | 0x00210000 )
|
#define ERRFILE_bofm ( ERRFILE_OTHER | 0x00210000 )
|
||||||
#define ERRFILE_prompt ( ERRFILE_OTHER | 0x00220000 )
|
#define ERRFILE_prompt ( ERRFILE_OTHER | 0x00220000 )
|
||||||
|
#define ERRFILE_nvo_cmd ( ERRFILE_OTHER | 0x00230000 )
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
Reference in New Issue