Browse Source

[settings] Use concat_args() in "set" command

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
aebba8f6eb
2 changed files with 21 additions and 24 deletions
  1. 20
    24
      src/hci/commands/nvo_cmd.c
  2. 1
    0
      src/include/ipxe/errfile.h

+ 20
- 24
src/hci/commands/nvo_cmd.c View File

99
 static int set_exec ( int argc, char **argv ) {
99
 static int set_exec ( int argc, char **argv ) {
100
 	struct set_options opts;
100
 	struct set_options opts;
101
 	const char *name;
101
 	const char *name;
102
-	size_t len;
103
-	int i;
102
+	char *value;
104
 	int rc;
103
 	int rc;
105
 
104
 
106
 	/* Parse options */
105
 	/* Parse options */
107
 	if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
106
 	if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
108
-		return rc;
107
+		goto err_parse_options;
109
 
108
 
110
 	/* Parse setting name */
109
 	/* Parse setting name */
111
 	name = argv[optind];
110
 	name = argv[optind];
112
 
111
 
113
-	/* Determine total length of command line */
114
-	len = 1; /* NUL */
115
-	for ( i = optind + 1 ; i < argc ; i++ )
116
-		len += ( 1 /* possible space */ + strlen ( argv[i] ) );
112
+	/* Parse setting value */
113
+	value = concat_args ( &argv[ optind + 1 ] );
114
+	if ( ! value ) {
115
+		rc = -ENOMEM;
116
+		goto err_concat_args;
117
+	}
117
 
118
 
118
-	{
119
-		char buf[len];
120
-		char *ptr = buf;
121
-
122
-		/* Assemble command line */
123
-		buf[0] = '\0';
124
-		for ( i = optind + 1 ; i < argc ; i++ ) {
125
-			ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
126
-					 argv[i] );
127
-		}
128
-		assert ( ptr < ( buf + len ) );
129
-
130
-		if ( ( rc = storef_named_setting ( name, buf ) ) != 0 ) {
131
-			printf ( "Could not set \"%s\"=\"%s\": %s\n",
132
-				 name, buf, strerror ( rc ) );
133
-			return rc;
134
-		}
119
+	/* Determine total length of command line */
120
+	if ( ( rc = storef_named_setting ( name, value ) ) != 0 ) {
121
+		printf ( "Could not set \"%s\"=\"%s\": %s\n",
122
+			 name, value, strerror ( rc ) );
123
+		goto err_store;
135
 	}
124
 	}
136
 
125
 
126
+	free ( value );
137
 	return 0;
127
 	return 0;
128
+
129
+ err_store:
130
+	free ( value );
131
+ err_concat_args:
132
+ err_parse_options:
133
+	return rc;
138
 }
134
 }
139
 
135
 
140
 /** "clear" options */
136
 /** "clear" options */

+ 1
- 0
src/include/ipxe/errfile.h View File

238
 #define ERRFILE_sanboot_cmd	      ( ERRFILE_OTHER | 0x00200000 )
238
 #define ERRFILE_sanboot_cmd	      ( ERRFILE_OTHER | 0x00200000 )
239
 #define ERRFILE_bofm		      ( ERRFILE_OTHER | 0x00210000 )
239
 #define ERRFILE_bofm		      ( ERRFILE_OTHER | 0x00210000 )
240
 #define ERRFILE_prompt		      ( ERRFILE_OTHER | 0x00220000 )
240
 #define ERRFILE_prompt		      ( ERRFILE_OTHER | 0x00220000 )
241
+#define ERRFILE_nvo_cmd		      ( ERRFILE_OTHER | 0x00230000 )
241
 
242
 
242
 /** @} */
243
 /** @} */
243
 
244
 

Loading…
Cancel
Save