diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 4443b83ae621659da7956c3c9bf92826e8a42dff..f3030b104930e63595ad41f7ec7badf5735a0e5c 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -547,10 +547,8 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup) if (!def->resource && startup) { virDomainResourceDefPtr res; - if (VIR_ALLOC(res) < 0) { - virReportOOMError(); + if (VIR_ALLOC(res) < 0) goto cleanup; - } if (VIR_STRDUP(res->partition, "/machine") < 0) { VIR_FREE(res); diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 81a4a33a614b077f0e50be7095e84475da967265..4e859c5f1f17c21342235a71a3b596808770db83 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -117,7 +117,7 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) if (STRNEQ(model, "none")) { /* Allocate just the primary security driver for LXC. */ if (VIR_ALLOC(caps->host.secModels) < 0) - goto no_memory; + goto error; caps->host.nsecModels = 1; if (VIR_STRDUP(caps->host.secModels[0].model, model) < 0) goto error; @@ -133,9 +133,6 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) return caps; -no_memory: - virReportOOMError(); - error: virObjectUnref(caps); return NULL; diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 595c0f2a882a629b504cc745a68079f91fcd030c..eb86338048b833befe9985a9c79b54aef684a21b 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -158,10 +158,8 @@ int lxcContainerHasReboot(void) VIR_FREE(buf); cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF; - if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) return -1; - } childStack = stack + (getpagesize() * 4); @@ -383,7 +381,6 @@ static int lxcContainerRenameAndEnableInterfaces(bool privNet, for (i = 0; i < nveths; i++) { if (virAsprintf(&newname, "eth%zu", i) < 0) { - virReportOOMError(); rc = -1; goto error_out; } @@ -467,10 +464,8 @@ static int lxcContainerGetSubtree(const char *prefix, if (!STRPREFIX(mntent.mnt_dir, prefix)) continue; - if (VIR_REALLOC_N(mounts, nmounts+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(mounts, nmounts+1) < 0) goto cleanup; - } if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) < 0) goto cleanup; nmounts++; @@ -568,10 +563,8 @@ static int lxcContainerPrepareRoot(virDomainDefPtr def, } if (virAsprintf(&dst, "%s/%s.root", - LXC_STATE_DIR, def->name) < 0) { - virReportOOMError(); + LXC_STATE_DIR, def->name) < 0) return -1; - } tmp = root->dst; root->dst = dst; @@ -606,10 +599,8 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) goto err; } - if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0) { - virReportOOMError(); + if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0) goto err; - } if (virFileMakePath(oldroot) < 0) { virReportSystemError(errno, @@ -628,10 +619,8 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root) } /* Create a directory called 'new' in tmpfs */ - if (virAsprintf(&newroot, "%s/new", oldroot) < 0) { - virReportOOMError(); + if (virAsprintf(&newroot, "%s/new", oldroot) < 0) goto err; - } if (virFileMakePath(newroot) < 0) { virReportSystemError(errno, @@ -893,10 +882,8 @@ 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) { - virReportOOMError(); + if (virAsprintf(&tty, "/dev/tty%zu", i+1) < 0) return -1; - } if (symlink(ttyPaths[i], tty) < 0) { VIR_FREE(tty); virReportSystemError(errno, @@ -924,10 +911,8 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs, int ret = -1; struct stat st; - if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0) goto cleanup; - } if (stat(fs->dst, &st) < 0) { if (errno != ENOENT) { @@ -1097,10 +1082,8 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs, /* First time around we use /etc/filesystems */ retry: if (virAsprintf(&fslist, "/.oldroot%s", - tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) { - virReportOOMError(); + tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) goto cleanup; - } VIR_DEBUG("Open fslist %s", fslist); if (!(fp = fopen(fslist, "r"))) { @@ -1254,10 +1237,8 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs, char *src = NULL; int ret = -1; - if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0) goto cleanup; - } ret = lxcContainerMountFSBlockHelper(fs, src); @@ -1276,10 +1257,8 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs, char *data = NULL; if (virAsprintf(&data, - "size=%lldk%s", fs->usage, sec_mount_options) < 0) { - virReportOOMError(); + "size=%lldk%s", fs->usage, sec_mount_options) < 0) goto cleanup; - } if (virFileMakePath(fs->dst) < 0) { virReportSystemError(errno, @@ -1396,15 +1375,11 @@ static int lxcContainerSetupDisk(virDomainDefPtr vmDef, goto cleanup; } - if (virAsprintf(&src, "/.oldroot/%s", def->src) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "/.oldroot/%s", def->src) < 0) goto cleanup; - } - if (virAsprintf(&dst, "/dev/%s", def->dst) < 0) { - virReportOOMError(); + if (virAsprintf(&dst, "/dev/%s", def->dst) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1484,22 +1459,16 @@ static int lxcContainerSetupHostdevSubsysUSB(virDomainDefPtr vmDef ATTRIBUTE_UNU mode_t mode; if (virAsprintf(&dstdir, USB_DEVFS "/%03d", - def->source.subsys.u.usb.bus) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.bus) < 0) goto cleanup; - } if (virAsprintf(&dstfile, "%s/%03d", dstdir, - def->source.subsys.u.usb.device) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.device) < 0) goto cleanup; - } - if (virAsprintf(&src, "/.oldroot/%s", dstfile) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "/.oldroot/%s", dstfile) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1586,10 +1555,8 @@ static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_U goto cleanup; } - if (virAsprintf(&src, "/.oldroot/%s", dev) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "/.oldroot/%s", dev) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -1650,10 +1617,8 @@ static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUS goto cleanup; } - if (virAsprintf(&src, "/.oldroot/%s", dev) < 0) { - virReportOOMError(); + if (virAsprintf(&src, "/.oldroot/%s", dev) < 0) goto cleanup; - } if (stat(src, &sb) < 0) { virReportSystemError(errno, @@ -2002,10 +1967,8 @@ static int lxcContainerChild(void *data) if (STRPREFIX(tty, "/dev/pts/")) tty += strlen("/dev/pts/"); if (virAsprintf(&ttyPath, "%s/%s.devpts/%s", - LXC_STATE_DIR, vmDef->name, tty) < 0) { - virReportOOMError(); + LXC_STATE_DIR, vmDef->name, tty) < 0) goto cleanup; - } } else if (VIR_STRDUP(ttyPath, "/dev/null") < 0) { goto cleanup; } @@ -2156,10 +2119,8 @@ int lxcContainerStart(virDomainDefPtr def, ttyPaths, nttyPaths, handshakefd}; /* allocate a stack for the container */ - if (VIR_ALLOC_N(stack, stacksize) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(stack, stacksize) < 0) return -1; - } stacktop = stack + stacksize; cflags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|SIGCHLD; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 568227f177abcb29a45baa250c3456ace023559a..4471abfb8c1b1653c525fc1dc37a4d209298a57c 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -150,10 +150,8 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) virDomainXMLOptionPtr xmlopt = NULL; char *configFile = NULL; - if (VIR_ALLOC(ctrl) < 0) { - virReportOOMError(); + if (VIR_ALLOC(ctrl) < 0) goto error; - } ctrl->timerShutdown = -1; ctrl->firstClient = true; @@ -279,10 +277,8 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl) static int virLXCControllerAddConsole(virLXCControllerPtr ctrl, int hostFd) { - if (VIR_EXPAND_N(ctrl->consoles, ctrl->nconsoles, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(ctrl->consoles, ctrl->nconsoles, 1) < 0) return -1; - } ctrl->consoles[ctrl->nconsoles-1].server = ctrl->server; ctrl->consoles[ctrl->nconsoles-1].hostFd = hostFd; ctrl->consoles[ctrl->nconsoles-1].hostWatch = -1; @@ -473,7 +469,6 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl) VIR_DEBUG("Saving loop fd %d", fd); if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) { VIR_FORCE_CLOSE(fd); - virReportOOMError(); goto cleanup; } ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd; @@ -521,7 +516,6 @@ static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl) VIR_DEBUG("Saving loop fd %d", fd); if (VIR_EXPAND_N(ctrl->loopDevFds, ctrl->nloopDevs, 1) < 0) { VIR_FORCE_CLOSE(fd); - virReportOOMError(); goto cleanup; } ctrl->loopDevFds[ctrl->nloopDevs - 1] = fd; @@ -707,10 +701,8 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl) char *sockpath; if (virAsprintf(&sockpath, "%s/%s.sock", - LXC_STATE_DIR, ctrl->name) < 0) { - virReportOOMError(); + LXC_STATE_DIR, ctrl->name) < 0) return -1; - } if (!(ctrl->server = virNetServerNew(0, 0, 0, 1, -1, 0, false, @@ -1228,10 +1220,8 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl) ctrl->def); if (virAsprintf(&dev, "/%s/%s.dev", - LXC_STATE_DIR, ctrl->def->name) < 0) { - virReportOOMError(); + LXC_STATE_DIR, ctrl->def->name) < 0) goto cleanup; - } if (virFileMakePath(dev) < 0) { virReportSystemError(errno, @@ -1245,10 +1235,8 @@ static int virLXCControllerSetupDev(virLXCControllerPtr ctrl) */ if (virAsprintf(&opts, - "mode=755,size=65536%s", mount_options) < 0) { - virReportOOMError(); + "mode=755,size=65536%s", mount_options) < 0) goto cleanup; - } VIR_DEBUG("Mount devfs on %s type=tmpfs flags=%x, opts=%s", dev, MS_NOSUID, opts); @@ -1295,10 +1283,8 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl) /* Populate /dev/ with a few important bits */ for (i = 0; i < ARRAY_CARDINALITY(devs); i++) { if (virAsprintf(&path, "/%s/%s.dev/%s", - LXC_STATE_DIR, ctrl->def->name, devs[i].path) < 0) { - virReportOOMError(); + LXC_STATE_DIR, ctrl->def->name, devs[i].path) < 0) goto cleanup; - } dev_t dev = makedev(devs[i].maj, devs[i].min); if (mknod(path, S_IFCHR, dev) < 0 || @@ -1439,7 +1425,6 @@ lxcCreateTty(virLXCControllerPtr ctrl, int *ttymaster, if ((virAsprintf(ttyName, "/dev/pts/%d", ptyno) < 0) || (virAsprintf(ttyHostPath, "/%s/%s.devpts/%d", LXC_STATE_DIR, ctrl->def->name, ptyno) < 0)) { - virReportOOMError(); errno = ENOMEM; goto cleanup; } @@ -1516,10 +1501,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) 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) { - virReportOOMError(); + LXC_STATE_DIR, ctrl->def->name) < 0) goto cleanup; - } if (virFileMakePath(devpts) < 0) { virReportSystemError(errno, @@ -1531,10 +1514,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=5%s", - (mount_options ? mount_options : "")) < 0) { - virReportOOMError(); + (mount_options ? mount_options : "")) < 0) goto cleanup; - } VIR_DEBUG("Mount devpts on %s type=tmpfs flags=%x, opts=%s", devpts, MS_NOSUID, opts); @@ -1709,10 +1690,8 @@ virLXCControllerRun(virLXCControllerPtr ctrl) size_t i; virCgroupPtr cgroup = NULL; - if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0) goto cleanup; - } if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) { virReportSystemError(errno, "%s", @@ -1872,19 +1851,15 @@ int main(int argc, char *argv[]) break; case 'v': - if (VIR_REALLOC_N(veths, nveths+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(veths, nveths+1) < 0) goto cleanup; - } if (VIR_STRDUP(veths[nveths++], optarg) < 0) goto cleanup; break; case 'c': - if (VIR_REALLOC_N(ttyFDs, nttyFDs + 1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(ttyFDs, nttyFDs + 1) < 0) goto cleanup; - } if (virStrToLong_i(optarg, NULL, 10, &ttyFDs[nttyFDs++]) < 0) { fprintf(stderr, "malformed --console argument '%s'", optarg); goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 2661c1bf136aecc15aa7b9f5347377c32cdf3037..3504dbaa9d152f2a20ac4aa3c4ecd8874e32025c 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2885,10 +2885,8 @@ lxcDomainShutdownFlags(virDomainPtr dom, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (flags == 0 || (flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) { @@ -2977,10 +2975,8 @@ lxcDomainReboot(virDomainPtr dom, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (flags == 0 || (flags & VIR_DOMAIN_REBOOT_INITCTL)) { @@ -3037,10 +3033,8 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef, _("target %s already exists."), disk->dst); return -1; } - if (virDomainDiskInsert(vmdef, disk)) { - virReportOOMError(); + if (virDomainDiskInsert(vmdef, disk)) return -1; - } /* vmdef has the pointer. Generic codes for vmdef will do all jobs */ dev->data.disk = NULL; ret = 0; @@ -3048,10 +3042,8 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef, case VIR_DOMAIN_DEVICE_NET: net = dev->data.net; - if (virDomainNetInsert(vmdef, net) < 0) { - virReportOOMError(); + if (virDomainNetInsert(vmdef, net) < 0) goto cleanup; - } dev->data.net = NULL; ret = 0; break; @@ -3063,10 +3055,8 @@ lxcDomainAttachDeviceConfig(virDomainDefPtr vmdef, _("device is already in the domain configuration")); return -1; } - if (virDomainHostdevInsert(vmdef, hostdev) < 0) { - virReportOOMError(); + if (virDomainHostdevInsert(vmdef, hostdev) < 0) return -1; - } dev->data.hostdev = NULL; ret = 0; break; @@ -3241,15 +3231,11 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver, } if (virAsprintf(&dst, "/proc/%llu/root/dev/%s", - (unsigned long long)priv->initpid, def->dst) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid, def->dst) < 0) goto cleanup; - } - if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) goto cleanup; - } mode = 0700; if (S_ISCHR(sb.st_mode)) @@ -3329,10 +3315,8 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn, } /* preallocate new slot for device */ - if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0) return -1; - } /* If appropriate, grab a physical device from the configured * network's pool of devices, or resolve bridge device name @@ -3466,31 +3450,23 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (virAsprintf(&dstdir, "%s/dev/bus/%03d", vroot, - def->source.subsys.u.usb.bus) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.bus) < 0) goto cleanup; - } if (virAsprintf(&dstfile, "%s/%03d", dstdir, - def->source.subsys.u.usb.device) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.device) < 0) goto cleanup; - } if (virAsprintf(&src, "/dev/bus/usb/%03d/%03d", def->source.subsys.u.usb.bus, - def->source.subsys.u.usb.device) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.device) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -3599,22 +3575,16 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (virAsprintf(&dst, "%s/%s", vroot, - def->source.caps.u.storage.block) < 0) { - virReportOOMError(); + def->source.caps.u.storage.block) < 0) goto cleanup; - } - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) goto cleanup; - } if (lxcContainerSetupHostdevCapsMakePath(dst) < 0) { virReportSystemError(errno, @@ -3710,22 +3680,16 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (virAsprintf(&dst, "%s/%s", vroot, - def->source.caps.u.misc.chardev) < 0) { - virReportOOMError(); + def->source.caps.u.misc.chardev) < 0) goto cleanup; - } - if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { - virReportOOMError(); + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) goto cleanup; - } if (lxcContainerSetupHostdevCapsMakePath(dst) < 0) { virReportSystemError(errno, @@ -3913,10 +3877,8 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm, def = vm->def->disks[i]; if (virAsprintf(&dst, "/proc/%llu/root/dev/%s", - (unsigned long long)priv->initpid, def->dst) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid, def->dst) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4035,18 +3997,14 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver, } if (virAsprintf(&vroot, "/proc/%llu/root", - (unsigned long long)priv->initpid) < 0) { - virReportOOMError(); + (unsigned long long)priv->initpid) < 0) goto cleanup; - } if (virAsprintf(&dst, "%s/dev/bus/usb/%03d/%03d", vroot, def->source.subsys.u.usb.bus, - def->source.subsys.u.usb.device) < 0) { - virReportOOMError(); + def->source.subsys.u.usb.device) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4113,10 +4071,8 @@ lxcDomainDetachDeviceHostdevStorageLive(virDomainObjPtr vm, if (virAsprintf(&dst, "/proc/%llu/root/%s", (unsigned long long)priv->initpid, - def->source.caps.u.storage.block) < 0) { - virReportOOMError(); + def->source.caps.u.storage.block) < 0) goto cleanup; - } if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -4174,10 +4130,8 @@ lxcDomainDetachDeviceHostdevMiscLive(virDomainObjPtr vm, if (virAsprintf(&dst, "/proc/%llu/root/%s", (unsigned long long)priv->initpid, - def->source.caps.u.misc.chardev) < 0) { - virReportOOMError(); + def->source.caps.u.misc.chardev) < 0) goto cleanup; - } 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 b98a0d9973dcd5ba465660595231b23eb8833e79..ea4ab7afd8d8d53a98455912328b32244e4141d2 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -52,10 +52,8 @@ 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) { - virReportOOMError(); + if (virAsprintf(&mempath, "/proc/%s", path) < 0) return -errno; - } res = 0; @@ -238,10 +236,8 @@ static int lxcProcRead(const char *path ATTRIBUTE_UNUSED, struct fuse_context *context = NULL; virDomainDefPtr def = NULL; - if (virAsprintf(&hostpath, "/proc/%s", path) < 0) { - virReportOOMError(); + if (virAsprintf(&hostpath, "/proc/%s", path) < 0) return -errno; - } context = fuse_get_context(); def = (virDomainDefPtr)context->private_data; @@ -297,10 +293,8 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def) goto cleanup2; if (virAsprintf(&fuse->mountpoint, "%s/%s.fuse/", LXC_STATE_DIR, - def->name) < 0) { - virReportOOMError(); + def->name) < 0) goto cleanup1; - } 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 a205d6962f89a8c309a8ece39ffc54e2512f739c..999039b3b43aab5d2f9dfb12f416d72124ea335e 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -155,7 +155,7 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm, if (virAsprintf(&sockpath, "%s/%s.sock", socketdir, vm->def->name) < 0) - goto no_memory; + goto error; if (!(mon->client = virNetClientNewUNIX(sockpath, false, NULL))) goto error; @@ -185,8 +185,6 @@ cleanup: VIR_FREE(sockpath); return mon; -no_memory: - virReportOOMError(); error: virObjectUnref(mon); mon = NULL; diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 861ab65aa58ac1b9147be202dabf45b936bd9e76..6f74bd2a04f8949eb74632f846261356bd195cf3 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -442,10 +442,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn, if (networkAllocateActualDevice(def->nets[i]) < 0) goto cleanup; - if (VIR_EXPAND_N(*veths, *nveths, 1) < 0) { - virReportOOMError(); + if (VIR_EXPAND_N(*veths, *nveths, 1) < 0) goto cleanup; - } switch (virDomainNetGetActualType(def->nets[i])) { case VIR_DOMAIN_NET_TYPE_NETWORK: { @@ -648,10 +646,8 @@ virLXCProcessGetNsInode(pid_t pid, int ret = -1; if (virAsprintf(&path, "/proc/%llu/ns/%s", - (unsigned long long)pid, nsname) < 0) { - virReportOOMError(); + (unsigned long long)pid, nsname) < 0) goto cleanup; - } if (stat(path, &sb) < 0) { virReportSystemError(errno, @@ -992,7 +988,7 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm) return 0; if (VIR_ALLOC(root) < 0) - goto no_memory; + goto error; root->type = VIR_DOMAIN_FS_TYPE_MOUNT; @@ -1000,16 +996,14 @@ virLXCProcessEnsureRootFS(virDomainObjPtr vm) VIR_STRDUP(root->dst, "/") < 0) goto error; - if (VIR_INSERT_ELEMENT_QUIET(vm->def->fss, - 0, - vm->def->nfss, - root) < 0) - goto no_memory; + if (VIR_INSERT_ELEMENT(vm->def->fss, + 0, + vm->def->nfss, + root) < 0) + goto error; return 0; -no_memory: - virReportOOMError(); error: virDomainFSDefFree(root); return -1; @@ -1084,10 +1078,8 @@ int virLXCProcessStart(virConnectPtr conn, } if (virAsprintf(&logfile, "%s/%s.log", - driver->logDir, vm->def->name) < 0) { - virReportOOMError(); + driver->logDir, vm->def->name) < 0) return -1; - } /* Do this up front, so any part of the startup process can add * runtime state to vm->def that won't be persisted. This let's us @@ -1127,10 +1119,8 @@ int virLXCProcessStart(virConnectPtr conn, * and forward I/O between them. */ nttyFDs = vm->def->nconsoles; - if (VIR_ALLOC_N(ttyFDs, nttyFDs) < 0) { - virReportOOMError(); + if (VIR_ALLOC_N(ttyFDs, nttyFDs) < 0) goto cleanup; - } for (i = 0; i < vm->def->nconsoles; i++) ttyFDs[i] = -1; @@ -1170,10 +1160,8 @@ 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) { - virReportOOMError(); + if (virAsprintf(&vm->def->consoles[i]->info.alias, "console%zu", i) < 0) goto cleanup; - } } if (virLXCProcessSetupInterfaces(conn, vm->def, &nveths, &veths) < 0) @@ -1224,10 +1212,8 @@ int virLXCProcessStart(virConnectPtr conn, } /* Log timestamp */ - if ((timestamp = virTimeStringNow()) == NULL) { - virReportOOMError(); + if ((timestamp = virTimeStringNow()) == NULL) goto cleanup; - } if (safewrite(logfd, timestamp, strlen(timestamp)) < 0 || safewrite(logfd, START_POSTFIX, strlen(START_POSTFIX)) < 0) { VIR_WARN("Unable to write timestamp to logfile: %s",