diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index abad36c5aa0560b1ea08c3cacc11527f30809b11..bdd77722c90d98e2bd82269a44ee6ea156fd2233 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -679,9 +679,7 @@ static int lxcContainerPrepareRoot(virDomainDefPtr def, 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; @@ -716,8 +714,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) 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, @@ -736,8 +733,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) } /* 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, @@ -922,8 +918,7 @@ static int lxcContainerMountBasicFS(bool userns_enabled, 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); @@ -1014,11 +1009,9 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def, 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) { @@ -1047,9 +1040,7 @@ static int lxcContainerMountFSDev(virDomainDefPtr def, 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", @@ -1083,9 +1074,7 @@ static int lxcContainerMountFSDevPTS(virDomainDefPtr def, 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", @@ -1137,8 +1126,7 @@ static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths) 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); @@ -1164,8 +1152,7 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs, 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) { @@ -1335,9 +1322,8 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs, /* 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"))) { @@ -1498,14 +1484,12 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs, 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; } @@ -1519,9 +1503,7 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs, 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, @@ -1664,19 +1646,22 @@ static int lxcContainerUnmountForSharedRoot(const char *stateDir, /* 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 @@ -2238,9 +2223,8 @@ static int lxcContainerChild(void *data) 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")); diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 5ae76082462f04cdf8ab37c4a72af6726a3ee5dd..3235a726ae69d187734a39b8360628c8203fa36b 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -565,10 +565,11 @@ static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl, 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 */ @@ -945,9 +946,7 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl) 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, @@ -1432,16 +1431,14 @@ static int virLXCControllerSetupUserns(virLXCControllerPtr ctrl) } 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, @@ -1467,18 +1464,14 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl) 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; @@ -1518,9 +1511,8 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl) /* 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 || @@ -1558,19 +1550,13 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef, 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, @@ -1644,10 +1630,8 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefPtr vmDef, 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, @@ -1722,10 +1706,8 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr vmDef, 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, @@ -1880,9 +1862,8 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl, 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, @@ -2071,12 +2052,8 @@ lxcCreateTty(virLXCControllerPtr ctrl, int *ttymaster, * 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; @@ -2132,11 +2109,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) 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, @@ -2152,9 +2126,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) /* 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); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index bc677f9958072da6f5ea4a6a14b46c64a32d505d..ca4ddfdd96112bcb4c05701a293153633b49315d 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3776,9 +3776,7 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver, 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, @@ -3963,9 +3961,7 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver, } 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; @@ -4301,8 +4297,7 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm, 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", @@ -4440,9 +4435,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver, } 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", diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index 07cc620fabd473418517fbf98e493080d6520c6f..44f240a0b5d8afbeae42f4fcb2c5cd75922b4691 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -47,8 +47,7 @@ static int lxcProcGetattr(const char *path, struct stat *stbuf) 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; @@ -247,8 +246,7 @@ static int lxcProcRead(const char *path G_GNUC_UNUSED, 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; @@ -303,9 +301,7 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def) 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"), diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index 028e401236de064baadd1a9f9aee15222de527c3..479125374b0111e699da2c56d5aad640078c2df3 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -151,9 +151,7 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm, 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; diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 5018cf115b1fe4771be1178bb5c0cc2de812802d..7e696fd2f02adfe05baa71efb43c52d610411ba6 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -265,8 +265,7 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab) 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); } @@ -492,9 +491,9 @@ lxcAddNetworkDefinition(lxcNetworkParseData *data) * 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; @@ -947,8 +946,7 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data) 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 */ diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 450053d163b8a5f14a34747ec106acf4719078f0..b59e66c29ad819d4494a0547609249e6069549b4 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -138,8 +138,7 @@ lxcProcessRemoveDomainStatus(virLXCDriverConfigPtr cfg, 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", @@ -419,10 +418,8 @@ static int virLXCProcessSetupNamespaceName(virConnectPtr conn, int ns_type, cons 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, @@ -443,10 +440,7 @@ static int virLXCProcessSetupNamespacePID(int ns_type, const char *name) 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) { @@ -470,8 +464,7 @@ static int virLXCProcessSetupNamespaceNet(int ns_type, const char *name) 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) { @@ -632,8 +625,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, /* 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++; } } @@ -757,9 +749,7 @@ virLXCProcessGetNsInode(pid_t pid, 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, @@ -984,9 +974,7 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver, 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); @@ -1269,9 +1257,7 @@ int virLXCProcessStart(virConnectPtr conn, 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; @@ -1358,8 +1344,7 @@ int virLXCProcessStart(virConnectPtr conn, 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");