if (lxcContainerResolveSymlinks(root, false) < 0)
return -1;
- if (virAsprintf(&dst, "%s/%s.root",
- LXC_STATE_DIR, def->name) < 0)
- return -1;
+ dst = g_strdup_printf("%s/%s.root", LXC_STATE_DIR, def->name);
tmp = root->dst;
root->dst = dst;
goto err;
}
- if (virAsprintf(&oldroot, "%s/.oldroot", root->src->path) < 0)
- goto err;
+ oldroot = g_strdup_printf("%s/.oldroot", root->src->path);
if (virFileMakePath(oldroot) < 0) {
virReportSystemError(errno,
}
/* Create a directory called 'new' in tmpfs */
- if (virAsprintf(&newroot, "%s/new", oldroot) < 0)
- goto err;
+ newroot = g_strdup_printf("%s/new", oldroot);
if (virFileMakePath(newroot) < 0) {
virReportSystemError(errno,
char *hostdir;
int ret;
- if (virAsprintf(&hostdir, "/.oldroot%s", mnt->dst) < 0)
- goto cleanup;
+ hostdir = g_strdup_printf("/.oldroot%s", mnt->dst);
ret = virFileIsMountPoint(hostdir);
VIR_FREE(hostdir);
VIR_DEBUG("Mount /proc/meminfo stateDir=%s", stateDir);
- if ((ret = virAsprintf(&meminfo_path,
- "/.oldroot/%s/%s.fuse/meminfo",
- stateDir,
- def->name)) < 0)
- return ret;
+ meminfo_path = g_strdup_printf("/.oldroot/%s/%s.fuse/meminfo",
+ stateDir,
+ def->name);
if ((ret = mount(meminfo_path, "/proc/meminfo",
NULL, MS_BIND, NULL)) < 0) {
VIR_DEBUG("Mount /dev/ stateDir=%s", stateDir);
- if ((ret = virAsprintf(&path, "/.oldroot/%s/%s.dev",
- stateDir, def->name)) < 0)
- return ret;
+ path = g_strdup_printf("/.oldroot/%s/%s.dev", stateDir, def->name);
if (virFileMakePath("/dev") < 0) {
virReportSystemError(errno, "%s",
VIR_DEBUG("Mount /dev/pts stateDir=%s", stateDir);
- if (virAsprintf(&path, "/.oldroot/%s/%s.devpts",
- stateDir, def->name) < 0)
- return ret;
+ path = g_strdup_printf("/.oldroot/%s/%s.devpts", stateDir, def->name);
if (virFileMakePath("/dev/pts") < 0) {
virReportSystemError(errno, "%s",
for (i = 0; i < nttyPaths; i++) {
char *tty;
- if (virAsprintf(&tty, "/dev/tty%zu", i+1) < 0)
- return -1;
+ tty = g_strdup_printf("/dev/tty%zu", i + 1);
if (virFileBindMountDevice(ttyPaths[i], tty) < 0) {
VIR_FREE(tty);
VIR_DEBUG("src=%s dst=%s", fs->src->path, fs->dst);
- if (virAsprintf(&src, "%s%s", srcprefix, fs->src->path) < 0)
- goto cleanup;
+ src = g_strdup_printf("%s%s", srcprefix, fs->src->path);
if (stat(fs->dst, &st) < 0) {
if (errno != ENOENT) {
/* First time around we use /etc/filesystems */
retry:
- if (virAsprintf(&fslist, "%s%s", srcprefix,
- tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0)
- goto cleanup;
+ fslist = g_strdup_printf("%s%s", srcprefix,
+ tryProc ? "/proc/filesystems" : "/etc/filesystems");
VIR_DEBUG("Open fslist %s", fslist);
if (!(fp = fopen(fslist, "r"))) {
VIR_DEBUG("src=%s dst=%s", fs->src->path, fs->dst);
- if (virAsprintf(&src, "%s%s", srcprefix, fs->src->path) < 0)
- goto cleanup;
+ src = g_strdup_printf("%s%s", srcprefix, fs->src->path);
ret = lxcContainerMountFSBlockHelper(fs, src, srcprefix, sec_mount_options);
VIR_DEBUG("Done mounting filesystem ret=%d", ret);
- cleanup:
VIR_FREE(src);
return ret;
}
VIR_DEBUG("usage=%lld sec=%s", fs->usage, sec_mount_options);
- if (virAsprintf(&data,
- "size=%lld%s", fs->usage, sec_mount_options) < 0)
- goto cleanup;
+ data = g_strdup_printf("size=%lld%s", fs->usage, sec_mount_options);
if (virFileMakePath(fs->dst) < 0) {
virReportSystemError(errno,
/* These filesystems are created by libvirt temporarily, they
* shouldn't appear in container. */
- if (virAsprintf(&tmp, "%s/%s.dev", stateDir, domain) < 0 ||
- lxcContainerUnmountSubtree(tmp, false) < 0)
+ tmp = g_strdup_printf("%s/%s.dev", stateDir, domain);
+
+ if (lxcContainerUnmountSubtree(tmp, false) < 0)
goto cleanup;
VIR_FREE(tmp);
- if (virAsprintf(&tmp, "%s/%s.devpts", stateDir, domain) < 0 ||
- lxcContainerUnmountSubtree(tmp, false) < 0)
+ tmp = g_strdup_printf("%s/%s.devpts", stateDir, domain);
+
+ if (lxcContainerUnmountSubtree(tmp, false) < 0)
goto cleanup;
#if WITH_FUSE
VIR_FREE(tmp);
- if (virAsprintf(&tmp, "%s/%s.fuse", stateDir, domain) < 0 ||
- lxcContainerUnmountSubtree(tmp, false) < 0)
+ tmp = g_strdup_printf("%s/%s.fuse", stateDir, domain);
+
+ if (lxcContainerUnmountSubtree(tmp, false) < 0)
goto cleanup;
#endif
const char *tty = argv->ttyPaths[0];
if (STRPREFIX(tty, "/dev/pts/"))
tty += strlen("/dev/pts/");
- if (virAsprintf(&ttyPath, "%s/%s.devpts/%s",
- LXC_STATE_DIR, vmDef->name, tty) < 0)
- goto cleanup;
+ ttyPath = g_strdup_printf("%s/%s.devpts/%s", LXC_STATE_DIR, vmDef->name,
+ tty);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("At least one tty is required"));
size_t loops = 0;
pid_t pid;
- if (!STRPREFIX(dev, "/dev/") ||
- virAsprintf(&pidpath, "/sys/devices/virtual/block/%s/pid", dev + 5) < 0)
+ if (!STRPREFIX(dev, "/dev/"))
goto cleanup;
+ pidpath = g_strdup_printf("/sys/devices/virtual/block/%s/pid", dev + 5);
+
/* Wait for the pid file to appear */
while (!virFileExists(pidpath)) {
/* wait for 100ms before checking again, but don't do it for ever */
virNetServerServicePtr svc = NULL;
char *sockpath;
- if (virAsprintf(&sockpath, "%s/%s.sock",
- LXC_STATE_DIR, ctrl->name) < 0)
- return -1;
+ sockpath = g_strdup_printf("%s/%s.sock", LXC_STATE_DIR, ctrl->name);
if (!(srv = virNetServerNew("LXC", 1,
0, 0, 0, 1,
}
VIR_DEBUG("Setting up userns maps");
- if (virAsprintf(&uid_map, "/proc/%d/uid_map", ctrl->initpid) < 0)
- goto cleanup;
+ uid_map = g_strdup_printf("/proc/%d/uid_map", ctrl->initpid);
if (virLXCControllerSetupUsernsMap(ctrl->def->idmap.uidmap,
ctrl->def->idmap.nuidmap,
uid_map) < 0)
goto cleanup;
- if (virAsprintf(&gid_map, "/proc/%d/gid_map", ctrl->initpid) < 0)
- goto cleanup;
+ gid_map = g_strdup_printf("/proc/%d/gid_map", ctrl->initpid);
if (virLXCControllerSetupUsernsMap(ctrl->def->idmap.gidmap,
ctrl->def->idmap.ngidmap,
mount_options = virSecurityManagerGetMountOptions(ctrl->securityManager,
ctrl->def);
- if (virAsprintf(&dev, "/%s/%s.dev",
- LXC_STATE_DIR, ctrl->def->name) < 0)
- goto cleanup;
+ dev = g_strdup_printf("/%s/%s.dev", LXC_STATE_DIR, ctrl->def->name);
/*
* tmpfs is limited to 64kb, since we only have device nodes in there
* and don't want to DOS the entire OS RAM usage
*/
- if (virAsprintf(&opts,
- "mode=755,size=65536%s", mount_options) < 0)
- goto cleanup;
+ opts = g_strdup_printf("mode=755,size=65536%s", mount_options);
if (virFileSetupDev(dev, opts) < 0)
goto cleanup;
/* Populate /dev/ with a few important bits */
for (i = 0; i < G_N_ELEMENTS(devs); i++) {
- if (virAsprintf(&path, "/%s/%s.dev/%s",
- LXC_STATE_DIR, ctrl->def->name, devs[i].path) < 0)
- goto cleanup;
+ path = g_strdup_printf("/%s/%s.dev/%s", LXC_STATE_DIR, ctrl->def->name,
+ devs[i].path);
dev_t dev = makedev(devs[i].maj, devs[i].min);
if (mknod(path, S_IFCHR, dev) < 0 ||
mode_t mode;
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
- if (virAsprintf(&src, USB_DEVFS "/%03d/%03d",
- usbsrc->bus, usbsrc->device) < 0)
- goto cleanup;
+ src = g_strdup_printf(USB_DEVFS "/%03d/%03d", usbsrc->bus, usbsrc->device);
- if (virAsprintf(&vroot, "/%s/%s.dev/bus/usb/",
- LXC_STATE_DIR, vmDef->name) < 0)
- goto cleanup;
+ vroot = g_strdup_printf("/%s/%s.dev/bus/usb/", LXC_STATE_DIR, vmDef->name);
- if (virAsprintf(&dstdir, "%s/%03d/", vroot, usbsrc->bus) < 0)
- goto cleanup;
+ dstdir = g_strdup_printf("%s/%03d/", vroot, usbsrc->bus);
- if (virAsprintf(&dstfile, "%s/%03d", dstdir, usbsrc->device) < 0)
- goto cleanup;
+ dstfile = g_strdup_printf("%s/%03d", dstdir, usbsrc->device);
if (stat(src, &sb) < 0) {
virReportSystemError(errno,
while (*(path + len) == '/')
len++;
- if (virAsprintf(&dst, "/%s/%s.dev/%s",
- LXC_STATE_DIR, vmDef->name,
- strchr(path + len, '/')) < 0)
- goto cleanup;
+ dst = g_strdup_printf("/%s/%s.dev/%s", LXC_STATE_DIR, vmDef->name,
+ strchr(path + len, '/'));
if (stat(dev, &sb) < 0) {
virReportSystemError(errno,
while (*(path + len) == '/')
len++;
- if (virAsprintf(&dst, "/%s/%s.dev/%s",
- LXC_STATE_DIR, vmDef->name,
- strchr(path + len, '/')) < 0)
- goto cleanup;
+ dst = g_strdup_printf("/%s/%s.dev/%s", LXC_STATE_DIR, vmDef->name,
+ strchr(path + len, '/'));
if (stat(dev, &sb) < 0) {
virReportSystemError(errno,
goto cleanup;
}
- if (virAsprintf(&dst, "/%s/%s.dev/%s",
- LXC_STATE_DIR, ctrl->def->name, def->dst) < 0)
- goto cleanup;
+ dst = g_strdup_printf("/%s/%s.dev/%s", LXC_STATE_DIR, ctrl->def->name,
+ def->dst);
if (stat(def->src->path, &sb) < 0) {
virReportSystemError(errno,
* while glibc has to fstat(), fchmod(), and fchown() for older
* kernels, we can skip those steps. ptyno shouldn't currently be
* anything other than 0, but let's play it safe. */
- if ((virAsprintf(ttyName, "/dev/pts/%d", ptyno) < 0) ||
- (virAsprintf(ttyHostPath, "/%s/%s.devpts/%d", LXC_STATE_DIR,
- ctrl->def->name, ptyno) < 0)) {
- errno = ENOMEM;
- goto cleanup;
- }
+ *ttyName = g_strdup_printf("/dev/pts/%d", ptyno);
+ *ttyHostPath = g_strdup_printf("/%s/%s.devpts/%d", LXC_STATE_DIR, ctrl->def->name, ptyno);
ret = 0;
mount_options = virSecurityManagerGetMountOptions(ctrl->securityManager,
ctrl->def);
- if (virAsprintf(&devpts, "%s/%s.devpts",
- LXC_STATE_DIR, ctrl->def->name) < 0 ||
- virAsprintf(&ctrl->devptmx, "%s/%s.devpts/ptmx",
- LXC_STATE_DIR, ctrl->def->name) < 0)
- goto cleanup;
+ devpts = g_strdup_printf("%s/%s.devpts", LXC_STATE_DIR, ctrl->def->name);
+ ctrl->devptmx = g_strdup_printf("%s/%s.devpts/ptmx", LXC_STATE_DIR, ctrl->def->name);
if (virFileMakePath(devpts) < 0) {
virReportSystemError(errno,
/* XXX should we support gid=X for X!=5 for distros which use
* a different gid for tty? */
- if (virAsprintf(&opts, "newinstance,ptmxmode=0666,mode=0620,gid=%u%s",
- ptsgid, NULLSTR_EMPTY(mount_options)) < 0)
- goto cleanup;
+ opts = g_strdup_printf("newinstance,ptmxmode=0666,mode=0620,gid=%u%s", ptsgid,
+ NULLSTR_EMPTY(mount_options));
VIR_DEBUG("Mount devpts on %s type=tmpfs flags=0x%x, opts=%s",
devpts, MS_NOSUID, opts);
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0)
goto cleanup;
- if (virAsprintf(&file,
- "/dev/%s", def->dst) < 0)
- goto cleanup;
+ file = g_strdup_printf("/dev/%s", def->dst);
if (lxcDomainAttachDeviceMknod(driver,
0700 | S_IFBLK,
}
usbsrc = &def->source.subsys.u.usb;
- if (virAsprintf(&src, "/dev/bus/usb/%03d/%03d",
- usbsrc->bus, usbsrc->device) < 0)
- goto cleanup;
+ src = g_strdup_printf("/dev/bus/usb/%03d/%03d", usbsrc->bus, usbsrc->device);
if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL)))
goto cleanup;
def = vm->def->disks[idx];
src = virDomainDiskGetSource(def);
- if (virAsprintf(&dst, "/dev/%s", def->dst) < 0)
- goto cleanup;
+ dst = g_strdup_printf("/dev/%s", def->dst);
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
}
usbsrc = &def->source.subsys.u.usb;
- if (virAsprintf(&dst, "/dev/bus/usb/%03d/%03d",
- usbsrc->bus, usbsrc->device) < 0)
- goto cleanup;
+ dst = g_strdup_printf("/dev/bus/usb/%03d/%03d", usbsrc->bus, usbsrc->device);
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
virDomainDefPtr def = (virDomainDefPtr)context->private_data;
memset(stbuf, 0, sizeof(struct stat));
- if (virAsprintf(&mempath, "/proc/%s", path) < 0)
- return -errno;
+ mempath = g_strdup_printf("/proc/%s", path);
res = 0;
struct fuse_context *context = NULL;
virDomainDefPtr def = NULL;
- if (virAsprintf(&hostpath, "/proc/%s", path) < 0)
- return -errno;
+ hostpath = g_strdup_printf("/proc/%s", path);
context = fuse_get_context();
def = (virDomainDefPtr)context->private_data;
if (virMutexInit(&fuse->lock) < 0)
goto cleanup2;
- if (virAsprintf(&fuse->mountpoint, "%s/%s.fuse/", LXC_STATE_DIR,
- def->name) < 0)
- goto cleanup1;
+ fuse->mountpoint = g_strdup_printf("%s/%s.fuse/", LXC_STATE_DIR, def->name);
if (virFileMakePath(fuse->mountpoint) < 0) {
virReportSystemError(errno, _("Cannot create %s"),
if (!(mon = virObjectLockableNew(virLXCMonitorClass)))
return NULL;
- if (virAsprintf(&sockpath, "%s/%s.sock",
- socketdir, vm->def->name) < 0)
- goto error;
+ sockpath = g_strdup_printf("%s/%s.sock", socketdir, vm->def->name);
if (!(mon->client = virNetClientNewUNIX(sockpath, false, NULL)))
goto error;
return -1;
if (fstab->dst[0] != '/') {
- if (virAsprintf(&dst, "/%s", fstab->dst) < 0)
- goto cleanup;
+ dst = g_strdup_printf("/%s", fstab->dst);
} else {
dst = g_strdup(fstab->dst);
}
* on the host */
if (isVlan && data->vlanid) {
VIR_FREE(hostdev->source.caps.u.net.ifname);
- if (virAsprintf(&hostdev->source.caps.u.net.ifname,
- "%s.%s", data->link, data->vlanid) < 0)
- goto error;
+ hostdev->source.caps.u.net.ifname = g_strdup_printf("%s.%s",
+ data->link,
+ data->vlanid);
}
hostdev->source.caps.u.net.ip.ips = data->ips;
goto cleanup;
}
- if (virAsprintf(&path, "/dev/block/%s", parts[0]) < 0)
- goto cleanup;
+ path = g_strdup_printf("/dev/block/%s", parts[0]);
/* Do we already have a device definition for this path?
* Get that device or create a new one */
char ebuf[1024];
char *file = NULL;
- if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) < 0)
- return;
+ file = g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name);
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
VIR_WARN("Failed to remove domain XML for %s: %s",
goto cleanup;
}
- if (virAsprintf(&path, "/proc/%lld/ns/%s",
- (long long int)priv->initpid,
- nsInfoLocal[ns_type]) < 0)
- goto cleanup;
+ path = g_strdup_printf("/proc/%lld/ns/%s", (long long int)priv->initpid,
+ nsInfoLocal[ns_type]);
if ((fd = open(path, O_RDONLY)) < 0) {
virReportSystemError(errno,
int fd;
char *path;
- if (virAsprintf(&path, "/proc/%s/ns/%s",
- name,
- nsInfoLocal[ns_type]) < 0)
- return -1;
+ path = g_strdup_printf("/proc/%s/ns/%s", name, nsInfoLocal[ns_type]);
fd = open(path, O_RDONLY);
VIR_FREE(path);
if (fd < 0) {
return -1;
}
- if (virAsprintf(&path, "%s/netns/%s", RUNSTATEDIR, name) < 0)
- return -1;
+ path = g_strdup_printf("%s/netns/%s", RUNSTATEDIR, name);
fd = open(path, O_RDONLY);
VIR_FREE(path);
if (fd < 0) {
/* Make sure all net definitions will have a name in the container */
if (!net->ifname_guest) {
- if (virAsprintf(&net->ifname_guest, "eth%zu", niface) < 0)
- goto cleanup;
+ net->ifname_guest = g_strdup_printf("eth%zu", niface);
niface++;
}
}
struct stat sb;
int ret = -1;
- if (virAsprintf(&path, "/proc/%lld/ns/%s",
- (long long)pid, nsname) < 0)
- goto cleanup;
+ path = g_strdup_printf("/proc/%lld/ns/%s", (long long)pid, nsname);
if (stat(path, &sb) < 0) {
virReportSystemError(errno,
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) {
if (nsInheritFDs[i] > 0) {
char *tmp = NULL;
- if (virAsprintf(&tmp, "--share-%s",
- nsInfoLocal[i]) < 0)
- goto error;
+ tmp = g_strdup_printf("--share-%s", nsInfoLocal[i]);
virCommandAddArg(cmd, tmp);
virCommandAddArgFormat(cmd, "%d", nsInheritFDs[i]);
virCommandPassFD(cmd, nsInheritFDs[i], 0);
vm->def->resource = res;
}
- if (virAsprintf(&logfile, "%s/%s.log",
- cfg->logDir, vm->def->name) < 0)
- goto cleanup;
+ logfile = g_strdup_printf("%s/%s.log", cfg->logDir, vm->def->name);
if (!(pidfile = virPidFileBuildPath(cfg->stateDir, vm->def->name)))
goto cleanup;
vm->def->consoles[i]->source->data.file.path = ttyPath;
VIR_FREE(vm->def->consoles[i]->info.alias);
- if (virAsprintf(&vm->def->consoles[i]->info.alias, "console%zu", i) < 0)
- goto cleanup;
+ vm->def->consoles[i]->info.alias = g_strdup_printf("console%zu", i);
}
VIR_DEBUG("Setting up Interfaces");