---
src/xenxs/xen_sxpr.c | 200 ++++++++++++++++++++++-----------------------------
src/xenxs/xen_xm.c | 91 +++++++++++------------
2 files changed, 125 insertions(+), 166 deletions(-)
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 9a76d04..aa99a61 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -192,9 +192,8 @@ xenParseSxprChar(const char *value,
if (value[0] == '/') {
def->source.type = VIR_DOMAIN_CHR_TYPE_DEV;
- def->source.data.file.path = strdup(value);
- if (!def->source.data.file.path)
- goto no_memory;
+ if (VIR_STRDUP(def->source.data.file.path, value) < 0)
+ goto error;
} else {
if ((tmp = strchr(value, ':')) != NULL) {
*tmp = '\0';
@@ -215,15 +214,14 @@ xenParseSxprChar(const char *value,
switch (def->source.type) {
case VIR_DOMAIN_CHR_TYPE_PTY:
- if (tty != NULL &&
- !(def->source.data.file.path = strdup(tty)))
- goto no_memory;
+ if (VIR_STRDUP(def->source.data.file.path, tty) < 0)
+ goto error;
break;
case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
- if (!(def->source.data.file.path = strdup(value)))
- goto no_memory;
+ if (VIR_STRDUP(def->source.data.file.path, value) < 0)
+ goto error;
break;
case VIR_DOMAIN_CHR_TYPE_TCP:
@@ -238,18 +236,14 @@ xenParseSxprChar(const char *value,
}
if (offset != value &&
- (def->source.data.tcp.host = strndup(value,
- offset - value)) == NULL)
- goto no_memory;
+ VIR_STRNDUP(def->source.data.tcp.host, value, offset - value) < 0)
+ goto error;
offset2 = strchr(offset, ',');
- if (offset2 == NULL)
- def->source.data.tcp.service = strdup(offset+1);
- else
- def->source.data.tcp.service = strndup(offset+1,
- offset2-(offset+1));
- if (def->source.data.tcp.service == NULL)
- goto no_memory;
+ if ((offset && VIR_STRNDUP(def->source.data.tcp.service,
+ offset + 1, offset2 - offset - 1) < 0) ||
+ (!offset && VIR_STRDUP(def->source.data.tcp.service, offset + 1)
< 0))
+ goto error;
if (offset2 && strstr(offset2, ",server"))
def->source.data.tcp.listen = true;
@@ -268,15 +262,14 @@ xenParseSxprChar(const char *value,
}
if (offset != value &&
- (def->source.data.udp.connectHost
- = strndup(value, offset - value)) == NULL)
- goto no_memory;
+ VIR_STRNDUP(def->source.data.udp.connectHost, value, offset - value) <
0)
+ goto error;
offset2 = strchr(offset, '@');
if (offset2 != NULL) {
- if ((def->source.data.udp.connectService
- = strndup(offset + 1, offset2-(offset+1))) == NULL)
- goto no_memory;
+ if (VIR_STRNDUP(def->source.data.udp.connectService,
+ offset + 1, offset2 - offset - 1) < 0)
+ goto error;
offset3 = strchr(offset2, ':');
if (offset3 == NULL) {
@@ -286,17 +279,15 @@ xenParseSxprChar(const char *value,
}
if (offset3 > (offset2 + 1) &&
- (def->source.data.udp.bindHost
- = strndup(offset2 + 1, offset3 - (offset2+1))) == NULL)
- goto no_memory;
+ VIR_STRNDUP(def->source.data.udp.bindHost,
+ offset2 + 1, offset3 - offset2 - 1) < 0)
+ goto error;
- if ((def->source.data.udp.bindService
- = strdup(offset3 + 1)) == NULL)
- goto no_memory;
+ if (VIR_STRDUP(def->source.data.udp.bindService, offset3 + 1) < 0)
+ goto error;
} else {
- if ((def->source.data.udp.connectService
- = strdup(offset + 1)) == NULL)
- goto no_memory;
+ if (VIR_STRDUP(def->source.data.udp.connectService, offset + 1) < 0)
+ goto error;
}
}
break;
@@ -304,12 +295,9 @@ xenParseSxprChar(const char *value,
case VIR_DOMAIN_CHR_TYPE_UNIX:
{
const char *offset = strchr(value, ',');
- if (offset)
- def->source.data.nix.path = strndup(value, (offset - value));
- else
- def->source.data.nix.path = strdup(value);
- if (def->source.data.nix.path == NULL)
- goto no_memory;
+ if ((offset && VIR_STRNDUP(def->source.data.nix.path, value, offset -
value) < 0) ||
+ (!offset && VIR_STRDUP(def->source.data.nix.path, value) < 0))
+ goto error;
if (offset != NULL &&
strstr(offset, ",server") != NULL)
@@ -320,8 +308,6 @@ xenParseSxprChar(const char *value,
return def;
-no_memory:
- virReportOOMError();
error:
virDomainChrDefFree(def);
return NULL;
@@ -411,8 +397,8 @@ xenParseSxprDisks(virDomainDefPtr def,
if (sexpr_lookup(node, "device/tap2") &&
STRPREFIX(src, "tap:")) {
- if (!(disk->driverName = strdup("tap2")))
- goto no_memory;
+ if (VIR_STRDUP(disk->driverName, "tap2") < 0)
+ goto error;
} else {
if (VIR_ALLOC_N(disk->driverName, (offset-src)+1) < 0)
goto no_memory;
@@ -438,8 +424,8 @@ xenParseSxprDisks(virDomainDefPtr def,
goto error;
}
- if (!(driverType = strndup(src, offset - src)))
- goto no_memory;
+ if (VIR_STRNDUP(driverType, src, offset - src) < 0)
+ goto error;
if (STREQ(driverType, "aio"))
disk->format = VIR_STORAGE_FILE_RAW;
else
@@ -490,11 +476,10 @@ xenParseSxprDisks(virDomainDefPtr def,
}
}
- if (!(disk->dst = strdup(dst)))
- goto no_memory;
- if (src &&
- !(disk->src = strdup(src)))
- goto no_memory;
+ if (VIR_STRDUP(disk->dst, dst) < 0)
+ goto error;
+ if (VIR_STRDUP(disk->src, src) < 0)
+ goto error;
if (STRPREFIX(disk->dst, "xvd"))
disk->bus = VIR_DOMAIN_DISK_BUS_XEN;
@@ -572,26 +557,21 @@ xenParseSxprNets(virDomainDefPtr def,
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
/* XXX virtual network reverse resolve */
- if (tmp &&
- !(net->data.bridge.brname = strdup(tmp)))
- goto no_memory;
- if (tmp2 &&
- net->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
- !(net->script = strdup(tmp2)))
- goto no_memory;
+ if (VIR_STRDUP(net->data.bridge.brname, tmp) < 0)
+ goto cleanup;
+ if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE &&
+ VIR_STRDUP(net->script, tmp2) < 0)
+ goto cleanup;
tmp = sexpr_node(node, "device/vif/ip");
- if (tmp &&
- !(net->data.bridge.ipaddr = strdup(tmp)))
- goto no_memory;
+ if (VIR_STRDUP(net->data.bridge.ipaddr, tmp) < 0)
+ goto cleanup;
} else {
net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
- if (tmp2 &&
- !(net->script = strdup(tmp2)))
- goto no_memory;
+ if (VIR_STRDUP(net->script, tmp2) < 0)
+ goto cleanup;
tmp = sexpr_node(node, "device/vif/ip");
- if (tmp &&
- !(net->data.ethernet.ipaddr = strdup(tmp)))
- goto no_memory;
+ if (VIR_STRDUP(net->data.ethernet.ipaddr, tmp) < 0)
+ goto cleanup;
}
tmp = sexpr_node(node, "device/vif/vifname");
@@ -599,8 +579,8 @@ xenParseSxprNets(virDomainDefPtr def,
* definition regardless of domain state. If vifname is not
* specified, only generate one if domain is active (id != -1). */
if (tmp) {
- if (!(net->ifname = strdup(tmp)))
- goto no_memory;
+ if (VIR_STRDUP(net->ifname, tmp) < 0)
+ goto cleanup;
} else if (def->id != -1) {
if (virAsprintf(&net->ifname, "vif%d.%d", def->id,
vif_index) < 0)
goto no_memory;
@@ -615,14 +595,12 @@ xenParseSxprNets(virDomainDefPtr def,
}
}
- if (model &&
- !(net->model = strdup(model)))
- goto no_memory;
+ if (VIR_STRDUP(net->model, model) < 0)
+ goto cleanup;
- if (!model && type &&
- STREQ(type, "netfront") &&
- !(net->model = strdup("netfront")))
- goto no_memory;
+ if (!model && type && STREQ(type, "netfront")
&&
+ VIR_STRDUP(net->model, "netfront") < 0)
+ goto cleanup;
if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0)
goto no_memory;
@@ -833,13 +811,11 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, -1, true))
goto error;
- if (vncPasswd &&
- !(graphics->data.vnc.auth.passwd = strdup(vncPasswd)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0)
+ goto error;
- if (keymap &&
- !(graphics->data.vnc.keymap = strdup(keymap)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.vnc.keymap, keymap) < 0)
+ goto error;
if (VIR_ALLOC_N(def->graphics, 1) < 0)
goto no_memory;
@@ -856,12 +832,10 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
goto no_memory;
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
- if (display &&
- !(graphics->data.sdl.display = strdup(display)))
- goto no_memory;
- if (xauth &&
- !(graphics->data.sdl.xauth = strdup(xauth)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.sdl.display, display) < 0)
+ goto error;
+ if (VIR_STRDUP(graphics->data.sdl.xauth, xauth) < 0)
+ goto error;
if (VIR_ALLOC_N(def->graphics, 1) < 0)
goto no_memory;
@@ -926,12 +900,10 @@ xenParseSxprGraphicsNew(virDomainDefPtr def,
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
const char *display = sexpr_node(node, "device/vfb/display");
const char *xauth = sexpr_node(node, "device/vfb/xauthority");
- if (display &&
- !(graphics->data.sdl.display = strdup(display)))
- goto no_memory;
- if (xauth &&
- !(graphics->data.sdl.xauth = strdup(xauth)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.sdl.display, display) < 0)
+ goto error;
+ if (VIR_STRDUP(graphics->data.sdl.xauth, xauth) < 0)
+ goto error;
} else {
int port;
const char *listenAddr = sexpr_node(node,
"device/vfb/vnclisten");
@@ -960,13 +932,11 @@ xenParseSxprGraphicsNew(virDomainDefPtr def,
virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, -1,
true))
goto error;
- if (vncPasswd &&
- !(graphics->data.vnc.auth.passwd = strdup(vncPasswd)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.vnc.auth.passwd, vncPasswd) < 0)
+ goto error;
- if (keymap &&
- !(graphics->data.vnc.keymap = strdup(keymap)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.vnc.keymap, keymap) < 0)
+ goto error;
}
if (VIR_ALLOC_N(def->graphics, 1) < 0)
@@ -1180,8 +1150,8 @@ xenParseSxpr(const struct sexpr *root,
if (!def->os.bootloader &&
sexpr_has(root, "domain/bootloader") &&
- (def->os.bootloader = strdup("")) == NULL)
- goto no_memory;
+ VIR_STRDUP(def->os.bootloader, "") < 0)
+ goto error;
if (def->os.bootloader &&
sexpr_node_copy(root, "domain/bootloader_args",
@@ -1189,8 +1159,8 @@ xenParseSxpr(const struct sexpr *root,
goto no_memory;
}
- if (!(def->os.type = strdup(hvm ? "hvm" : "linux")))
- goto no_memory;
+ if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "linux") < 0)
+ goto error;
if (def->id != 0) {
if (sexpr_lookup(root, "domain/image")) {
@@ -1357,19 +1327,19 @@ xenParseSxpr(const struct sexpr *root,
virDomainDiskDefPtr disk;
if (VIR_ALLOC(disk) < 0)
goto no_memory;
- if (!(disk->src = strdup(tmp))) {
+ if (VIR_STRDUP(disk->src, tmp) < 0) {
virDomainDiskDefFree(disk);
- goto no_memory;
+ goto error;
}
disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
- if (!(disk->dst = strdup("hdc"))) {
+ if (VIR_STRDUP(disk->dst, "hdc") < 0) {
virDomainDiskDefFree(disk);
- goto no_memory;
+ goto error;
}
- if (!(disk->driverName = strdup("file"))) {
+ if (VIR_STRDUP(disk->driverName, "file") < 0) {
virDomainDiskDefFree(disk);
- goto no_memory;
+ goto error;
}
disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
disk->readonly = true;
@@ -1393,19 +1363,19 @@ xenParseSxpr(const struct sexpr *root,
virDomainDiskDefPtr disk;
if (VIR_ALLOC(disk) < 0)
goto no_memory;
- if (!(disk->src = strdup(tmp))) {
+ if (VIR_STRDUP(disk->src, tmp) < 0) {
VIR_FREE(disk);
- goto no_memory;
+ goto error;
}
disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
disk->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY;
- if (!(disk->dst = strdup(fds[i]))) {
+ if (VIR_STRDUP(disk->dst, fds[i]) < 0) {
virDomainDiskDefFree(disk);
- goto no_memory;
+ goto error;
}
- if (!(disk->driverName = strdup("file"))) {
+ if (VIR_STRDUP(disk->driverName, "file") < 0) {
virDomainDiskDefFree(disk);
- goto no_memory;
+ goto error;
}
disk->bus = VIR_DOMAIN_DISK_BUS_FDC;
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 57ce2e7..c28b79e 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -183,12 +183,7 @@ static int xenXMConfigCopyStringInternal(virConfPtr conf,
return -1;
}
- if (!(*value = strdup(val->str))) {
- virReportOOMError();
- return -1;
- }
-
- return 0;
+ return VIR_STRDUP(*value, val->str);
}
@@ -288,8 +283,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
STREQ(str, "hvm"))
hvm = 1;
- if (!(def->os.type = strdup(hvm ? "hvm" : "xen")))
- goto no_memory;
+ if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0)
+ goto cleanup;
def->os.arch =
virCapabilitiesDefaultGuestArch(caps,
@@ -307,8 +302,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
def->os.arch,
virDomainVirtTypeToString(def->virtType));
if (defaultMachine != NULL) {
- if (!(def->os.machine = strdup(defaultMachine)))
- goto no_memory;
+ if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
+ goto cleanup;
}
if (hvm) {
@@ -562,8 +557,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (!(tmp = strchr(disk->src, ':')))
goto skipdisk;
- if (!(driverType = strndup(disk->src, tmp - disk->src)))
- goto no_memory;
+ if (VIR_STRNDUP(driverType, disk->src, tmp - disk->src) <
0)
+ goto cleanup;
if (STREQ(driverType, "aio"))
disk->format = VIR_STORAGE_FILE_RAW;
else
@@ -585,8 +580,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
/* No source, or driver name, so fix to phy: */
if (!disk->driverName &&
- !(disk->driverName = strdup("phy")))
- goto no_memory;
+ VIR_STRDUP(disk->driverName, "phy") < 0)
+ goto cleanup;
/* phy: type indicates a block device */
@@ -637,12 +632,12 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
- if (!(disk->driverName = strdup("file")))
- goto no_memory;
- if (!(disk->src = strdup(str)))
- goto no_memory;
- if (!(disk->dst = strdup("hdc")))
- goto no_memory;
+ if (VIR_STRDUP(disk->driverName, "file") < 0)
+ goto cleanup;
+ if (VIR_STRDUP(disk->src, str) < 0)
+ goto cleanup;
+ if (VIR_STRDUP(disk->dst, "hdc") < 0)
+ goto cleanup;
disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
disk->readonly = true;
@@ -703,9 +698,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
} else if (STRPREFIX(key, "script=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
VIR_FREE(script);
- if (!(script = strndup(data, len))) {
- goto no_memory;
- }
+ if (VIR_STRNDUP(script, data, len) < 0)
+ goto cleanup;
} else if (STRPREFIX(key, "model=")) {
int len = nextkey ? (nextkey - data) : sizeof(model) - 1;
if (virStrncpy(model, data, len, sizeof(model)) == NULL) {
@@ -763,34 +757,30 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
}
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
- if (bridge[0] &&
- !(net->data.bridge.brname = strdup(bridge)))
- goto no_memory;
- if (ip[0] &&
- !(net->data.bridge.ipaddr = strdup(ip)))
- goto no_memory;
+ if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge)
< 0)
+ goto cleanup;
+ if (ip[0] && VIR_STRDUP(net->data.bridge.ipaddr, ip) < 0)
+ goto cleanup;
} else {
- if (ip[0] &&
- !(net->data.ethernet.ipaddr = strdup(ip)))
- goto no_memory;
+ if (ip[0] && VIR_STRDUP(net->data.ethernet.ipaddr, ip) <
0)
+ goto cleanup;
}
if (script && script[0] &&
- !(net->script = strdup(script)))
- goto no_memory;
+ VIR_STRDUP(net->script, script) < 0)
+ goto cleanup;
if (model[0] &&
- !(net->model = strdup(model)))
+ VIR_STRDUP(net->model, model) < 0)
goto no_memory;
- if (!model[0] && type[0] &&
- STREQ(type, "netfront") &&
- !(net->model = strdup("netfront")))
- goto no_memory;
+ if (!model[0] && type[0] && STREQ(type, "netfront")
&&
+ VIR_STRDUP(net->model, "netfront") < 0)
+ goto cleanup;
if (vifname[0] &&
- !(net->ifname = strdup(vifname)))
- goto no_memory;
+ VIR_STRDUP(net->ifname, vifname) < 0)
+ goto cleanup;
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0)
goto no_memory;
@@ -1019,21 +1009,21 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
-1, true) < 0)
goto cleanup;
} else if (STRPREFIX(key, "vncpasswd=")) {
- if (!(graphics->data.vnc.auth.passwd = strdup(key + 10)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) <
0)
+ goto cleanup;
} else if (STRPREFIX(key, "keymap=")) {
- if (!(graphics->data.vnc.keymap = strdup(key + 7)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0)
+ goto cleanup;
} else if (STRPREFIX(key, "vncdisplay=")) {
graphics->data.vnc.port = strtol(key+11, NULL, 10) + 5900;
}
} else {
if (STRPREFIX(key, "display=")) {
- if (!(graphics->data.sdl.display = strdup(key + 8)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.sdl.display, key + 8) < 0)
+ goto cleanup;
} else if (STRPREFIX(key, "xauthority=")) {
- if (!(graphics->data.sdl.xauth = strdup(key + 11)))
- goto no_memory;
+ if (VIR_STRDUP(graphics->data.sdl.xauth, key + 11) < 0)
+ goto cleanup;
}
}
@@ -1193,9 +1183,8 @@ int xenXMConfigSetString(virConfPtr conf, const char *setting, const
char *str)
value->type = VIR_CONF_STRING;
value->next = NULL;
- if (!(value->str = strdup(str))) {
+ if (VIR_STRDUP(value->str, str) < 0) {
VIR_FREE(value);
- virReportOOMError();
return -1;
}
--
1.8.2.1