|
@@ -99,42 +99,38 @@ static struct command_descriptor set_cmd =
|
99
|
99
|
static int set_exec ( int argc, char **argv ) {
|
100
|
100
|
struct set_options opts;
|
101
|
101
|
const char *name;
|
102
|
|
- size_t len;
|
103
|
|
- int i;
|
|
102
|
+ char *value;
|
104
|
103
|
int rc;
|
105
|
104
|
|
106
|
105
|
/* Parse options */
|
107
|
106
|
if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
|
108
|
|
- return rc;
|
|
107
|
+ goto err_parse_options;
|
109
|
108
|
|
110
|
109
|
/* Parse setting name */
|
111
|
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
|
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
|
136
|
/** "clear" options */
|