+Tue Dec 23 13:39:48 CET 2008 Guido Günther <agx@sigxcpu.org>
+
+ use virAsprintf instead of asprintf
+ * .x-sc_prohibit_asprintf, Makefile.maint (sc_prohibit_asprintf): new
+ rule
+ * src/cgroup.c, src/domain_conf.c, src/driver.c, src/libvirt.c,
+ src/logging.c, src/lxc_container.c, src/lxc_controller.c,
+ src/lxc_driver.c, src/network_conf.c, src/network_driver.c,
+ src/openvz_conf.c, src/qemu_conf.c, src/qemu_driver.c,
+ src/remote_internal.c, src/stats_linux.c, src/storage_backend_iscsi.c,
+ src/storage_driver.c, src/uml_conf.c, src/uml_driver.c, src/util.c,
+ src/veth.c, src/virsh.c, src/xm_internal.c: use virAsprintf instead of
+ asprintf
+
Mon Dec 22 11:33:16 EST 2008 Cole Robinson <crobinso@redhat.com>
* src/storage_driver.c: Fix storage driver null dereference.
{ echo '$(ME): use STREQ in place of the above uses of str''cmp' \
1>&2; exit 1; } || :
+# Use virAsprintf rather than a'sprintf since *strp is undefined on error.
+sc_prohibit_asprintf:
+ @grep -nE '\<[a]sprintf\>' $$($(VC_LIST_EXCEPT)) && \
+ { echo '$(ME): use virAsprintf, not a'sprintf 1>&2; exit 1; } || :
+
# Using EXIT_SUCCESS as the first argument to error is misleading,
# since when that parameter is 0, error does not exit. Use `0' instead.
sc_error_exit_success:
goto out;
}
- if (asprintf(path, "%s/%s", root->path, group) == -1)
+ if (virAsprintf(path, "%s/%s", root->path, group) == -1)
rc = -ENOMEM;
out:
virCgroupFree(&root);
goto out;
}
- if (asprintf(path, "%s/%s/%s", root->path, grppath, key) == -1)
+ if (virAsprintf(path, "%s/%s/%s", root->path, grppath, key) == -1)
rc = -ENOMEM;
out:
virCgroupFree(&root);
char *strval = NULL;
int rc;
- if (asprintf(&strval, "%" PRIu64, value) == -1)
+ if (virAsprintf(&strval, "%" PRIu64, value) == -1)
return -ENOMEM;
rc = virCgroupSetValueStr(group, key, strval);
char *strval = NULL;
int rc;
- if (asprintf(&strval, "%" PRIi64, value) == -1)
+ if (virAsprintf(&strval, "%" PRIi64, value) == -1)
return -ENOMEM;
rc = virCgroupSetValueStr(group, key, strval);
memset(buf, 0, sizeof(buf));
- if (asprintf(&keypath, "%s/%s", path, key) == -1) {
+ if (virAsprintf(&keypath, "%s/%s", path, key) == -1) {
rc = -ENOMEM;
goto out;
}
goto out;
}
- if (asprintf(&pkeypath, "%s/../%s", path, key) == -1) {
+ if (virAsprintf(&pkeypath, "%s/../%s", path, key) == -1) {
rc = -ENOMEM;
VIR_FREE(keypath);
goto out;
goto err;
}
- rc = asprintf(&((*newgroup)->path),
- "%s/%s",
- (*parent)->path,
- group);
+ rc = virAsprintf(&((*newgroup)->path),
+ "%s/%s",
+ (*parent)->path,
+ group);
if (rc == -1) {
rc = -ENOMEM;
goto err;
if (rc != 0)
goto done;
- if (asprintf(&taskpath, "%s/tasks", grppath) == -1) {
+ if (virAsprintf(&taskpath, "%s/tasks", grppath) == -1) {
rc = -ENOMEM;
goto done;
}
goto done;
}
- if (asprintf(&pidstr, "%lu", (unsigned long)pid) == -1) {
+ if (virAsprintf(&pidstr, "%lu", (unsigned long)pid) == -1) {
rc = -ENOMEM;
goto done;
}
int rc;
char *devstr = NULL;
- if (asprintf(&devstr, "%c %i:%i rwm", type, major, minor) == -1) {
+ if (virAsprintf(&devstr, "%c %i:%i rwm", type, major, minor) == -1) {
rc = -ENOMEM;
goto out;
}
int rc;
char *devstr = NULL;
- if (asprintf(&devstr, "%c %i:* rwm", type, major) == -1) {
+ if (virAsprintf(&devstr, "%c %i:* rwm", type, major) == -1) {
rc = -ENOMEM;
goto out;
}
{
char *ret = NULL;
- if (asprintf(&ret, "%s/%s.xml", dir, name) < 0) {
+ if (virAsprintf(&ret, "%s/%s.xml", dir, name) < 0) {
virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
DEBUG("Module load %s", name);
- if (asprintf(&modfile, "%s/libvirt_driver_%s.so", moddir, name) < 0)
+ if (virAsprintf(&modfile, "%s/libvirt_driver_%s.so", moddir, name) < 0)
return NULL;
if (access(modfile, R_OK) < 0) {
goto cleanup;
}
- if (asprintf(®func, "%sRegister", name) < 0) {
- regfunc = NULL;
+ if (virAsprintf(®func, "%sRegister", name) < 0) {
goto cleanup;
}
"Is the libvirtd daemon running ?");
} else {
char *msg;
- if (asprintf(&msg, "Is the %s daemon running?",
- virDeviceMonitorTab[i]->name) > 0) {
+ if (virAsprintf(&msg, "Is the %s daemon running?",
+ virDeviceMonitorTab[i]->name) > 0) {
virLibConnWarning (NULL, VIR_WAR_NO_NODE, msg);
VIR_FREE(msg);
}
localtime_r(&cur_time.tv_sec, &time_info);
if ((funcname != NULL) && (priority == VIR_LOG_DEBUG)) {
- ret = asprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s:%lld : %s\n",
- time_info.tm_hour, time_info.tm_min,
- time_info.tm_sec, (int) cur_time.tv_usec / 1000,
- virLogPriorityString(priority), funcname, linenr, str);
+ ret = virAsprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s:%lld : %s\n",
+ time_info.tm_hour, time_info.tm_min,
+ time_info.tm_sec, (int) cur_time.tv_usec / 1000,
+ virLogPriorityString(priority), funcname, linenr, str);
} else {
- ret = asprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s\n",
- time_info.tm_hour, time_info.tm_min,
- time_info.tm_sec, (int) cur_time.tv_usec / 1000,
- virLogPriorityString(priority), str);
+ ret = virAsprintf(&msg, "%02d:%02d:%02d.%03d: %s : %s\n",
+ time_info.tm_hour, time_info.tm_min,
+ time_info.tm_sec, (int) cur_time.tv_usec / 1000,
+ virLogPriorityString(priority), str);
}
VIR_FREE(str);
if (ret < 0) {
return -1;
}
- if (asprintf(&oldroot, "%s/.oldroot", root->src) < 0) {
- oldroot = NULL;
+ if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0) {
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
if (vmDef->fss[i]->type != VIR_DOMAIN_FS_TYPE_MOUNT)
continue;
- if (asprintf(&src, "/.oldroot/%s", vmDef->fss[i]->src) < 0) {
+ if (virAsprintf(&src, "/.oldroot/%s", vmDef->fss[i]->src) < 0) {
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
static char*lxcMonitorPath(virDomainDefPtr def)
{
char *sockpath;
- if (asprintf(&sockpath, "%s/%s.sock",
- LXC_STATE_DIR, def->name) < 0) {
+
+ if (virAsprintf(&sockpath, "%s/%s.sock",
+ LXC_STATE_DIR, def->name) < 0)
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
- return NULL;
- }
return sockpath;
}
int fd;
struct sockaddr_un addr;
- if (asprintf(&sockpath, "%s/%s.sock",
- driver->stateDir, vm->def->name) < 0) {
+ if (virAsprintf(&sockpath, "%s/%s.sock",
+ driver->stateDir, vm->def->name) < 0) {
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
return -1;
}
- if (asprintf(&logfile, "%s/%s.log",
- driver->logDir, vm->def->name) < 0) {
+ if (virAsprintf(&logfile, "%s/%s.log",
+ driver->logDir, vm->def->name) < 0) {
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
inaddress.s_addr &= innetmask.s_addr;
netaddr = inet_ntoa(inaddress);
- if (asprintf(&def->network, "%s/%s", netaddr, def->netmask) < 0) {
+ if (virAsprintf(&def->network, "%s/%s", netaddr, def->netmask) < 0) {
virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL);
goto error;
}
int err;
if (!net->configFile &&
- asprintf(&net->configFile, "%s/%s.xml",
- configDir, net->def->name) < 0) {
- net->configFile = NULL;
+ virAsprintf(&net->configFile, "%s/%s.xml",
+ configDir, net->def->name) < 0) {
virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL);
goto cleanup;
}
if (!net->autostartLink &&
- asprintf(&net->autostartLink, "%s/%s.xml",
- autostartDir, net->def->name) < 0) {
- net->autostartLink = NULL;
+ virAsprintf(&net->autostartLink, "%s/%s.xml",
+ autostartDir, net->def->name) < 0) {
virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL);
goto cleanup;
}
virNetworkObjPtr net;
int autostart;
- if (asprintf(&configFile, "%s/%s",
- configDir, file) < 0) {
- configFile = NULL;
+ if (virAsprintf(&configFile, "%s/%s",
+ configDir, file) < 0) {
virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL);
goto error;
}
- if (asprintf(&autostartLink, "%s/%s",
- autostartDir, file) < 0) {
- autostartLink = NULL;
+ if (virAsprintf(&autostartLink, "%s/%s",
+ autostartDir, file) < 0) {
virNetworkReportError(conn, VIR_ERR_NO_MEMORY, NULL);
goto error;
}
networkDriverLock(driverState);
if (!uid) {
- if (asprintf(&driverState->logDir,
- "%s/log/libvirt/qemu", LOCAL_STATE_DIR) == -1)
+ if (virAsprintf(&driverState->logDir,
+ "%s/log/libvirt/qemu", LOCAL_STATE_DIR) == -1)
goto out_of_memory;
if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
goto out_of_memory;
}
- if (asprintf(&driverState->logDir,
- "%s/.libvirt/qemu/log", pw->pw_dir) == -1)
+ if (virAsprintf(&driverState->logDir,
+ "%s/.libvirt/qemu/log", pw->pw_dir) == -1)
goto out_of_memory;
- if (asprintf (&base, "%s/.libvirt", pw->pw_dir) == -1) {
- networkLog (NETWORK_ERR,
- "%s", _("out of memory in asprintf\n"));
+ if (virAsprintf(&base, "%s/.libvirt", pw->pw_dir) == -1) {
goto out_of_memory;
}
}
/* Configuration paths are either ~/.libvirt/qemu/... (session) or
* /etc/libvirt/qemu/... (system).
*/
- if (asprintf (&driverState->networkConfigDir, "%s/qemu/networks", base) == -1)
+ if (virAsprintf(&driverState->networkConfigDir, "%s/qemu/networks", base) == -1)
goto out_of_memory;
- if (asprintf (&driverState->networkAutostartDir, "%s/qemu/networks/autostart",
- base) == -1)
+ if (virAsprintf(&driverState->networkAutostartDir, "%s/qemu/networks/autostart",
+ base) == -1)
goto out_of_memory;
VIR_FREE(base);
dom->pid = veid;
dom->def->id = dom->state == VIR_DOMAIN_SHUTOFF ? -1 : veid;
- if (asprintf(&dom->def->name, "%i", veid) < 0) {
- dom->def->name = NULL;
+ if (virAsprintf(&dom->def->name, "%i", veid) < 0)
goto no_memory;
- }
openvzGetVPSUUID(veid, uuidstr);
ret = virUUIDParse(uuidstr, dom->def->uuid);
do { \
ADD_ARG_LIT("-usbdevice"); \
ADD_ARG_SPACE; \
- if ((asprintf((char **)&(qargv[qargc++]), \
- "disk:%s", thisarg)) == -1) { \
- qargv[qargc-1] = NULL; \
+ if ((virAsprintf((char **)&(qargv[qargc++]), \
+ "disk:%s", thisarg)) == -1) { \
goto no_memory; \
} \
} while (0)
char *envval; \
ADD_ENV_SPACE; \
if (val != NULL) { \
- if (asprintf(&envval, "%s=%s", envname, val) < 0) \
+ if (virAsprintf(&envval, "%s=%s", envname, val) < 0) \
goto no_memory; \
qenv[qenvc++] = envval; \
} \
char *display = NULL;
if (vm->def->graphics->data.sdl.xauth &&
- asprintf(&xauth, "XAUTHORITY=%s",
- vm->def->graphics->data.sdl.xauth) < 0)
+ virAsprintf(&xauth, "XAUTHORITY=%s",
+ vm->def->graphics->data.sdl.xauth) < 0)
goto no_memory;
if (vm->def->graphics->data.sdl.display &&
- asprintf(&display, "DISPLAY=%s",
- vm->def->graphics->data.sdl.display) < 0) {
+ virAsprintf(&display, "DISPLAY=%s",
+ vm->def->graphics->data.sdl.display) < 0) {
VIR_FREE(xauth);
goto no_memory;
}
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
if(hostdev->source.subsys.u.usb.vendor) {
- ret = asprintf(&usbdev, "host:%.4x:%.4x",
+ ret = virAsprintf(&usbdev, "host:%.4x:%.4x",
hostdev->source.subsys.u.usb.vendor,
hostdev->source.subsys.u.usb.product);
} else {
- ret = asprintf(&usbdev, "host:%.3d.%.3d",
+ ret = virAsprintf(&usbdev, "host:%.3d.%.3d",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device);
}
- if (ret < 0) {
- usbdev = NULL;
+ if (ret < 0)
goto error;
- }
+
ADD_ARG_LIT("-usbdevice");
ADD_ARG_LIT(usbdev);
VIR_FREE(usbdev);
goto error;
if (!uid) {
- if (asprintf(&qemu_driver->logDir,
- "%s/log/libvirt/qemu", LOCAL_STATE_DIR) == -1)
+ if (virAsprintf(&qemu_driver->logDir,
+ "%s/log/libvirt/qemu", LOCAL_STATE_DIR) == -1)
goto out_of_memory;
if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
goto error;
}
- if (asprintf(&qemu_driver->logDir,
- "%s/.libvirt/qemu/log", pw->pw_dir) == -1)
+ if (virAsprintf(&qemu_driver->logDir,
+ "%s/.libvirt/qemu/log", pw->pw_dir) == -1)
goto out_of_memory;
- if (asprintf (&base, "%s/.libvirt", pw->pw_dir) == -1)
+ if (virAsprintf(&base, "%s/.libvirt", pw->pw_dir) == -1)
goto out_of_memory;
if (virAsprintf(&qemu_driver->stateDir, "%s/qemu/run", base) == -1)
goto out_of_memory;
driverConf[sizeof(driverConf)-1] = '\0';
- if (asprintf (&qemu_driver->configDir, "%s/qemu", base) == -1)
+ if (virAsprintf(&qemu_driver->configDir, "%s/qemu", base) == -1)
goto out_of_memory;
- if (asprintf (&qemu_driver->autostartDir, "%s/qemu/autostart", base) == -1)
+ if (virAsprintf(&qemu_driver->autostartDir, "%s/qemu/autostart", base) == -1)
goto out_of_memory;
VIR_FREE(base);
"%s", _("out of memory"));
goto cleanup;
}
- if (asprintf (&command, "migrate \"exec:"
+ if (virAsprintf(&command, "migrate \"exec:"
"dd of='%s' oflag=append conv=notrunc 2>/dev/null"
"\"", safe_path) == -1) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
switch (disk->bus) {
case VIR_DOMAIN_DISK_BUS_IDE:
if (disk->device== VIR_DOMAIN_DISK_DEVICE_DISK)
- ret = asprintf(&devname, "ide%d-hd%d", busid, devid);
+ ret = virAsprintf(&devname, "ide%d-hd%d", busid, devid);
else
- ret = asprintf(&devname, "ide%d-cd%d", busid, devid);
+ ret = virAsprintf(&devname, "ide%d-cd%d", busid, devid);
break;
case VIR_DOMAIN_DISK_BUS_SCSI:
if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK)
- ret = asprintf(&devname, "scsi%d-hd%d", busid, devid);
+ ret = virAsprintf(&devname, "scsi%d-hd%d", busid, devid);
else
- ret = asprintf(&devname, "scsi%d-cd%d", busid, devid);
+ ret = virAsprintf(&devname, "scsi%d-cd%d", busid, devid);
break;
case VIR_DOMAIN_DISK_BUS_FDC:
- ret = asprintf(&devname, "floppy%d", devid);
+ ret = virAsprintf(&devname, "floppy%d", devid);
break;
case VIR_DOMAIN_DISK_BUS_VIRTIO:
- ret = asprintf(&devname, "virtio%d", devid);
+ ret = virAsprintf(&devname, "virtio%d", devid);
break;
default:
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_SUPPORT,
VIR_FREE(devname);
return -1;
}
- if (asprintf (&cmd, "change %s \"%s\"", devname, safe_path) == -1) {
+ if (virAsprintf(&cmd, "change %s \"%s\"", devname, safe_path) == -1) {
qemudReportError(conn, dom, NULL, VIR_ERR_NO_MEMORY, NULL);
VIR_FREE(safe_path);
VIR_FREE(devname);
}
VIR_FREE(safe_path);
- } else if (asprintf(&cmd, "eject %s", devname) == -1) {
+ } else if (virAsprintf(&cmd, "eject %s", devname) == -1) {
qemudReportError(conn, dom, NULL, VIR_ERR_NO_MEMORY, NULL);
VIR_FREE(devname);
return -1;
return -1;
}
- ret = asprintf(&cmd, "pci_add 0 storage file=%s,if=%s",
- safe_path, type);
+ ret = virAsprintf(&cmd, "pci_add 0 storage file=%s,if=%s",
+ safe_path, type);
VIR_FREE(safe_path);
if (ret == -1) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
- ret = asprintf(&cmd, "usb_add disk:%s", safe_path);
+ ret = virAsprintf(&cmd, "usb_add disk:%s", safe_path);
VIR_FREE(safe_path);
if (ret == -1) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
}
if (dev->data.hostdev->source.subsys.u.usb.vendor) {
- ret = asprintf(&cmd, "usb_add host:%.4x:%.4x",
- dev->data.hostdev->source.subsys.u.usb.vendor,
- dev->data.hostdev->source.subsys.u.usb.product);
+ ret = virAsprintf(&cmd, "usb_add host:%.4x:%.4x",
+ dev->data.hostdev->source.subsys.u.usb.vendor,
+ dev->data.hostdev->source.subsys.u.usb.product);
} else {
- ret = asprintf(&cmd, "usb_add host:%.3d.%.3d",
- dev->data.hostdev->source.subsys.u.usb.bus,
- dev->data.hostdev->source.subsys.u.usb.device);
+ ret = virAsprintf(&cmd, "usb_add host:%.3d.%.3d",
+ dev->data.hostdev->source.subsys.u.usb.bus,
+ dev->data.hostdev->source.subsys.u.usb.device);
}
if (ret == -1) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
goto cleanup;
}
- if (asprintf(&cmd, "pci_del 0 %d", detach->slotnum) < 0) {
+ if (virAsprintf(&cmd, "pci_del 0 %d", detach->slotnum) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
- cmd = NULL;
goto cleanup;
}
}
/* Caller frees */
- if (asprintf(uri_out, "tcp:%s:%d", hostname, this_port) < 0) {
+ if (virAsprintf(uri_out, "tcp:%s:%d", hostname, this_port) < 0) {
qemudReportError (dconn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", strerror (errno));
- *uri_out = NULL;
goto cleanup;
}
} else {
/* Remote server defaults to "localhost" if not specified. */
if (conn->uri && conn->uri->port != 0) {
- if (asprintf (&port, "%d", conn->uri->port) == -1) goto out_of_memory;
+ if (virAsprintf(&port, "%d", conn->uri->port) == -1) goto out_of_memory;
} else if (transport == trans_tls) {
port = strdup (LIBVIRTD_TLS_PORT);
if (!port) goto out_of_memory;
goto failed;
}
- if (asprintf (&sockname, "@%s" LIBVIRTD_USER_UNIX_SOCKET, pw->pw_dir) < 0) {
- sockname = NULL;
+ if (virAsprintf(&sockname, "@%s" LIBVIRTD_USER_UNIX_SOCKET, pw->pw_dir) < 0)
goto out_of_memory;
- }
+
} else {
if (flags & VIR_DRV_OPEN_REMOTE_RO)
sockname = strdup (LIBVIRTD_PRIV_UNIX_SOCKET_RO);
*/
if (strlen(path) >= 5 && STRPREFIX(path, "/dev/"))
- retval = asprintf(&mod_path, "%s", path);
+ retval = virAsprintf(&mod_path, "%s", path);
else
- retval = asprintf(&mod_path, "/dev/%s", path);
+ retval = virAsprintf(&mod_path, "/dev/%s", path);
if (retval < 0) {
statsErrorFunc (conn, VIR_ERR_NO_MEMORY, __FUNCTION__,
vol->type = VIR_STORAGE_VOL_BLOCK;
- if (asprintf(&(vol->name), "lun-%d", lun) < 0) {
+ if (virAsprintf(&(vol->name), "lun-%d", lun) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("name"));
goto cleanup;
}
- if (asprintf(&devpath, "/dev/%s", dev) < 0) {
+ if (virAsprintf(&devpath, "/dev/%s", dev) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("devpath"));
goto cleanup;
}
goto out_of_memory;
}
- if (asprintf (&base, "%s/.libvirt", pw->pw_dir) == -1) {
- storageLog("out of memory in asprintf");
+ if (virAsprintf(&base, "%s/.libvirt", pw->pw_dir) == -1) {
+ storageLog("out of memory in virAsprintf");
goto out_of_memory;
}
}
goto out_of_memory;
driverConf[sizeof(driverConf)-1] = '\0';
- if (asprintf (&driverState->configDir,
- "%s/storage", base) == -1)
+ if (virAsprintf(&driverState->configDir,
+ "%s/storage", base) == -1)
goto out_of_memory;
- if (asprintf (&driverState->autostartDir,
- "%s/storage/autostart", base) == -1)
+ if (virAsprintf(&driverState->autostartDir,
+ "%s/storage/autostart", base) == -1)
goto out_of_memory;
VIR_FREE(base);
switch (def->type) {
case VIR_DOMAIN_CHR_TYPE_NULL:
- if (asprintf(&ret, "%s%d=null", dev, def->dstPort) < 0) {
+ if (virAsprintf(&ret, "%s%d=null", dev, def->dstPort) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
break;
case VIR_DOMAIN_CHR_TYPE_PTY:
- if (asprintf(&ret, "%s%d=pts", dev, def->dstPort) < 0) {
+ if (virAsprintf(&ret, "%s%d=pts", dev, def->dstPort) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
break;
case VIR_DOMAIN_CHR_TYPE_DEV:
- if (asprintf(&ret, "%s%d=tty:%s", dev, def->dstPort,
- def->data.file.path) < 0) {
+ if (virAsprintf(&ret, "%s%d=tty:%s", dev, def->dstPort,
+ def->data.file.path) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
break;
case VIR_DOMAIN_CHR_TYPE_STDIO:
- if (asprintf(&ret, "%s%d=fd:0,fd:1", dev, def->dstPort) < 0) {
+ if (virAsprintf(&ret, "%s%d=fd:0,fd:1", dev, def->dstPort) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
return NULL;
}
- if (asprintf(&ret, "%s%d=port:%s", dev, def->dstPort,
- def->data.tcp.service) < 0) {
+ if (virAsprintf(&ret, "%s%d=port:%s", dev, def->dstPort,
+ def->data.tcp.service) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
do { \
char *arg; \
ADD_ARG_SPACE; \
- if (asprintf(&arg, "%s=%s", key, val) < 0) \
+ if (virAsprintf(&arg, "%s=%s", key, val) < 0) \
goto no_memory; \
- qargv[qargc++] = arg; \
+ qargv[qargc++] = arg; \
} while (0)
char *envval; \
ADD_ENV_SPACE; \
if (val != NULL) { \
- if (asprintf(&envval, "%s=%s", envname, val) < 0) \
+ if (virAsprintf(&envval, "%s=%s", envname, val) < 0) \
goto no_memory; \
qenv[qenvc++] = envval; \
} \
if (i == 0 && vm->def->console)
ret = umlBuildCommandLineChr(conn, vm->def->console, "con");
else
- if (asprintf(&ret, "con%d=none", i) < 0)
+ if (virAsprintf(&ret, "con%d=none", i) < 0)
goto no_memory;
ADD_ARG(ret);
}
if (chr)
ret = umlBuildCommandLineChr(conn, chr, "ssl");
else
- if (asprintf(&ret, "ssl%d=none", i) < 0)
+ if (virAsprintf(&ret, "ssl%d=none", i) < 0)
goto no_memory;
ADD_ARG(ret);
}
char *cmd;
char *res = NULL;
int retries = 0;
- if (asprintf(&cmd, "config %s%d", dev, def->dstPort) < 0) {
+ if (virAsprintf(&cmd, "config %s%d", dev, def->dstPort) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
}
if (!uid) {
- if (asprintf(¨_driver->logDir,
- "%s/log/libvirt/uml", LOCAL_STATE_DIR) == -1)
+ if (virAsprintf(¨_driver->logDir,
+ "%s/log/libvirt/uml", LOCAL_STATE_DIR) == -1)
goto out_of_memory;
if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
goto out_of_memory;
} else {
- if (asprintf(¨_driver->logDir,
- "%s/.libvirt/uml/log", pw->pw_dir) == -1)
+ if (virAsprintf(¨_driver->logDir,
+ "%s/.libvirt/uml/log", pw->pw_dir) == -1)
goto out_of_memory;
- if (asprintf (&base, "%s/.libvirt", pw->pw_dir) == -1)
+ if (virAsprintf(&base, "%s/.libvirt", pw->pw_dir) == -1)
goto out_of_memory;
}
- if (asprintf (¨_driver->monitorDir,
- "%s/.uml", pw->pw_dir) == -1)
+ if (virAsprintf(¨_driver->monitorDir,
+ "%s/.uml", pw->pw_dir) == -1)
goto out_of_memory;
/* Configuration paths are either ~/.libvirt/uml/... (session) or
goto out_of_memory;
driverConf[sizeof(driverConf)-1] = '\0';
- if (asprintf (¨_driver->configDir, "%s/uml", base) == -1)
+ if (virAsprintf(¨_driver->configDir, "%s/uml", base) == -1)
goto out_of_memory;
- if (asprintf (¨_driver->autostartDir, "%s/uml/autostart", base) == -1)
+ if (virAsprintf(¨_driver->autostartDir, "%s/uml/autostart", base) == -1)
goto out_of_memory;
VIR_FREE(base);
int retries = 0;
vm->pid = -1;
- if (asprintf(&pidfile, "%s/%s/pid",
- driver->monitorDir, vm->def->name) < 0) {
+ if (virAsprintf(&pidfile, "%s/%s/pid",
+ driver->monitorDir, vm->def->name) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
struct sockaddr_un *addr) {
char *sockname;
- if (asprintf(&sockname, "%s/%s/mconsole",
- driver->monitorDir, vm->def->name) < 0) {
+ if (virAsprintf(&sockname, "%s/%s/mconsole",
+ driver->monitorDir, vm->def->name) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
return -1;
}
- if (asprintf(&logfile, "%s/%s.log",
- driver->logDir, vm->def->name) < 0) {
+ if (virAsprintf(&logfile, "%s/%s.log",
+ driver->logDir, vm->def->name) < 0) {
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return -1;
}
char* virFilePid(const char *dir, const char* name)
{
- char* pidfile;
-
- if (asprintf(&pidfile, "%s/%s.pid", dir, name) < 0) {
- pidfile = NULL;
- }
+ char *pidfile;
+ virAsprintf(&pidfile, "%s/%s.pid", dir, name);
return pidfile;
}
/**
* virAsprintf
*
- * like asprintf but makes sure *strp == NULL on failure
+ * like glibc's_asprintf but makes sure *strp == NULL on failure
*/
int
virAsprintf(char **strp, const char *fmt, ...)
goto error_out;
}
- if (asprintf(&pid, "%d", pidInNs) == -1)
+ if (virAsprintf(&pid, "%d", pidInNs) == -1)
goto error_out;
argv[5] = pid;
}
}
ret = port ?
- asprintf(&srcSpec,
- "<source><host name='%.*s' port='%s'/></source>",
- (int)hostlen, host, port) :
- asprintf(&srcSpec,
- "<source><host name='%.*s'/></source>",
- (int)hostlen, host);
+ virAsprintf(&srcSpec,
+ "<source><host name='%.*s' port='%s'/></source>",
+ (int)hostlen, host, port) :
+ virAsprintf(&srcSpec,
+ "<source><host name='%.*s'/></source>",
+ (int)hostlen, host);
if (ret < 0) {
switch (errno) {
case ENOMEM:
vshError(ctl, FALSE, "%s", _("Out of memory"));
break;
default:
- vshError(ctl, FALSE, _("asprintf failed (errno %d)"), errno);
+ vshError(ctl, FALSE, _("virAsprintf failed (errno %d)"), errno);
}
return FALSE;
}
return -1;
}
- if (asprintf (&command, "%s %s", editor, filename) == -1) {
+ if (virAsprintf(&command, "%s %s", editor, filename) == -1) {
vshError(ctl, FALSE,
- _("asprintf: could not create editing command: %s"),
+ _("virAsprintf: could not create editing command: %s"),
strerror (errno));
return -1;
}
static char *xenXMAutostartLinkName(virDomainPtr dom)
{
char *ret;
- if (asprintf(&ret, "/etc/xen/auto/%s", dom->name) < 0)
- return NULL;
+ virAsprintf(&ret, "/etc/xen/auto/%s", dom->name);
return ret;
}
static char *xenXMDomainConfigName(virDomainPtr dom)
{
char *ret;
- if (asprintf(&ret, "/etc/xen/%s", dom->name) < 0)
- return NULL;
+ virAsprintf(&ret, "/etc/xen/%s", dom->name);
return ret;
}