/* Iterate over string, splitting on sequences of ' ' */
while (curr && *curr != '\0') {
char *arg;
- const char *next = strchr(curr, ' ');
+ const char *next;
+ if (*curr == '\'') {
+ curr++;
+ next = strchr(curr, '\'');
+ } else if (*curr == '"') {
+ curr++;
+ next = strchr(curr, '"');
+ } else {
+ next = strchr(curr, ' ');
+ }
if (!next)
next = strchr(curr, '\n');
- if (next)
+ if (next) {
arg = strndup(curr, next-curr);
- else
+ if (*next == '\'' ||
+ *next == '"')
+ next++;
+ } else {
arg = strdup(curr);
+ }
if (!arg)
goto no_memory;
int i;
int len = strlen(name);
- for (i = 0 ; progenv[i] ; i++) {
+ for (i = 0 ; progenv && progenv[i] ; i++) {
if (STREQLEN(progenv[i], name, len) &&
progenv[i][len] == '=')
return progenv[i] + len + 1;
int gotvlan;
const char *tmp = strstr(nics[i], "vlan=");
char *end;
- if (tmp)
- tmp += strlen("vlan=");
+ if (!tmp)
+ continue;
+
+ tmp += strlen("vlan=");
if (virStrToLong_i(tmp, &end, 10, &gotvlan) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
return nics[i];
}
+ if (wantvlan == 0 && nnics > 0)
+ return nics[0];
+
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("cannot find NIC definition for vlan %d"), wantvlan);
return NULL;
*/
static virDomainNetDefPtr
qemuParseCommandLineNet(virConnectPtr conn,
+ virCapsPtr caps,
const char *val,
int nnics,
const char **nics)
{
virDomainNetDefPtr def = NULL;
- char **keywords;
- char **values;
+ char **keywords = NULL;
+ char **values = NULL;
int nkeywords;
const char *nic;
int wantvlan = 0;
const char *tmp;
+ int genmac = 1;
int i;
tmp = strchr(val, ',');
- if (!tmp) {
- qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _("cannot extract NIC type from '%s'"), val);
- return NULL;
- }
- if ((nkeywords = qemuParseCommandLineKeywords(conn,
- tmp+1,
- &keywords,
- &values)) < 0)
- return NULL;
+ if (tmp) {
+ if ((nkeywords = qemuParseCommandLineKeywords(conn,
+ tmp+1,
+ &keywords,
+ &values)) < 0)
+ return NULL;
+ } else {
+ nkeywords = 0;
+ }
if (VIR_ALLOC(def) < 0) {
virReportOOMError(conn);
goto cleanup;
}
- if (!STRPREFIX(nic, "nic,")) {
+ if (!STRPREFIX(nic, "nic")) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("cannot parse NIC definition '%s'"), nic);
virDomainNetDefFree(def);
def = NULL;
goto cleanup;
VIR_FREE(keywords);
VIR_FREE(values);
- if ((nkeywords = qemuParseCommandLineKeywords(conn,
- nic + strlen("nic,"),
- &keywords,
- &values)) < 0) {
- virDomainNetDefFree(def);
- def = NULL;
- goto cleanup;
+ if (STRPREFIX(nic, "nic,")) {
+ if ((nkeywords = qemuParseCommandLineKeywords(conn,
+ nic + strlen("nic,"),
+ &keywords,
+ &values)) < 0) {
+ virDomainNetDefFree(def);
+ def = NULL;
+ goto cleanup;
+ }
+ } else {
+ nkeywords = 0;
}
for (i = 0 ; i < nkeywords ; i++) {
if (STREQ(keywords[i], "macaddr")) {
+ genmac = 0;
virParseMacAddr(values[i], def->mac);
} else if (STREQ(keywords[i], "model")) {
def->model = values[i];
}
}
+ if (genmac)
+ virCapabilitiesGenerateMac(caps, def->mac);
+
cleanup:
for (i = 0 ; i < nkeywords ; i++) {
VIR_FREE(keywords[i]);
* as is practical. This is not an exact science....
*/
virDomainDefPtr qemuParseCommandLine(virConnectPtr conn,
+ virCapsPtr caps,
const char **progenv,
const char **progargv)
{
if (VIR_ALLOC(def) < 0)
goto no_memory;
+ virUUIDGenerate(def->uuid);
+
def->id = -1;
def->memory = def->maxmem = 64 * 1024;
def->vcpus = 1;
WANT_VALUE();
if (!STRPREFIX(val, "nic") && STRNEQ(val, "none")) {
virDomainNetDefPtr net;
- if (!(net = qemuParseCommandLineNet(conn, val, nnics, nics)))
+ if (!(net = qemuParseCommandLineNet(conn, caps, val, nnics, nics)))
goto error;
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) {
virDomainNetDefFree(net);
virDomainDefPtr qemuParseCommandLineString(virConnectPtr conn,
+ virCapsPtr caps,
const char *args)
{
const char **progenv = NULL;
if (qemuStringToArgvEnv(args, &progenv, &progargv) < 0)
goto cleanup;
- def = qemuParseCommandLine(conn, progenv, progargv);
+ def = qemuParseCommandLine(conn, caps, progenv, progargv);
cleanup:
for (i = 0 ; progargv && progargv[i] ; i++)