Split declarations from initializations

Split those initializations that depend on a statement
above them.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2020-07-28 19:50:28 +02:00
parent a5152f23e7
commit 0a37e0695b
20 changed files with 84 additions and 39 deletions

View File

@ -1935,11 +1935,13 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
addrMatch = false;
for (j = 0; j < nips; j++) {
virNetworkIPDefPtr def2 = &def->ips[j];
int prefix;
if (VIR_SOCKET_ADDR_FAMILY(gateway)
!= VIR_SOCKET_ADDR_FAMILY(&def2->address)) {
continue;
}
int prefix = virNetworkIPDefPrefix(def2);
prefix = virNetworkIPDefPrefix(def2);
virSocketAddrMaskByPrefix(&def2->address, prefix, &testAddr);
virSocketAddrMaskByPrefix(gateway, prefix, &testGw);
if (VIR_SOCKET_ADDR_VALID(&testAddr) &&

View File

@ -2864,10 +2864,13 @@ virNWFilterRuleDefDetailsFormat(virBufferPtr buf,
nwItemDesc *item;
while (att[i].name) {
virNWFilterEntryItemFlags flags;
VIR_WARNINGS_NO_CAST_ALIGN
item = (nwItemDesc *)((char *)def + att[i].dataIdx);
VIR_WARNINGS_RESET
virNWFilterEntryItemFlags flags = item->flags;
flags = item->flags;
if ((flags & NWFILTER_ENTRY_ITEM_FLAG_EXISTS)) {
if (!typeShown) {
virBufferAsprintf(buf, "<%s", type);

View File

@ -1490,11 +1490,12 @@ static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl)
/* Populate /dev/ with a few important bits */
for (i = 0; i < G_N_ELEMENTS(devs); i++) {
g_autofree char *path = NULL;
dev_t dev;
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);
dev = makedev(devs[i].maj, devs[i].min);
if (mknod(path, S_IFCHR, dev) < 0 ||
chmod(path, devs[i].mode)) {
virReportSystemError(errno,
@ -1990,11 +1991,12 @@ static int virLXCControllerMoveInterfaces(virLXCControllerPtr ctrl)
for (i = 0; i < def->nhostdevs; i ++) {
virDomainHostdevDefPtr hdev = def->hostdevs[i];
virDomainHostdevCaps hdcaps;
if (hdev->mode != VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES)
continue;
virDomainHostdevCaps hdcaps = hdev->source.caps;
hdcaps = hdev->source.caps;
if (hdcaps.type != VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET)
continue;

View File

@ -1440,6 +1440,7 @@ static virSecurityManagerPtr
lxcSecurityInit(virLXCDriverConfigPtr cfg)
{
unsigned int flags = VIR_SECURITY_MANAGER_PRIVILEGED;
virSecurityManagerPtr mgr;
VIR_INFO("lxcSecurityInit %s", cfg->securityDriverName);
@ -1448,8 +1449,8 @@ lxcSecurityInit(virLXCDriverConfigPtr cfg)
if (cfg->securityRequireConfined)
flags |= VIR_SECURITY_MANAGER_REQUIRE_CONFINED;
virSecurityManagerPtr mgr = virSecurityManagerNew(cfg->securityDriverName,
LXC_DRIVER_NAME, flags);
mgr = virSecurityManagerNew(cfg->securityDriverName,
LXC_DRIVER_NAME, flags);
if (!mgr)
goto error;

View File

@ -4235,7 +4235,9 @@ qemuBuildVgaVideoCommand(virCommandPtr cmd,
virDomainVideoDefPtr video,
virQEMUCapsPtr qemuCaps)
{
const char *dev;
const char *vgastr = qemuVideoTypeToString(video->type);
if (!vgastr || STREQ(vgastr, "")) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid model for video type '%s'"),
@ -4256,7 +4258,7 @@ qemuBuildVgaVideoCommand(virCommandPtr cmd,
* See 'Graphics Devices' section in docs/qdev-device-use.txt in
* QEMU repository.
*/
const char *dev = qemuDeviceVideoTypeToString(video->type);
dev = qemuDeviceVideoTypeToString(video->type);
if (video->type == VIR_DOMAIN_VIDEO_TYPE_QXL &&
(video->vram || video->ram)) {
@ -4938,9 +4940,11 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
if (dev->data.nix.listen &&
(flags & QEMU_BUILD_CHARDEV_UNIX_FD_PASS) &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS)) {
int fd;
if (qemuSecuritySetSocketLabel(secManager, (virDomainDefPtr)def) < 0)
return NULL;
int fd = qemuOpenChrChardevUNIXSocket(dev);
fd = qemuOpenChrChardevUNIXSocket(dev);
if (qemuSecurityClearSocketLabel(secManager, (virDomainDefPtr)def) < 0) {
VIR_FORCE_CLOSE(fd);
return NULL;

View File

@ -5019,11 +5019,12 @@ qemuProcessSetupRawIO(virQEMUDriverPtr driver,
/* If rawio not already set, check hostdevs as well */
if (!rawio) {
for (i = 0; i < vm->def->nhostdevs; i++) {
virDomainHostdevSubsysSCSIPtr scsisrc;
if (!virHostdevIsSCSIDevice(vm->def->hostdevs[i]))
continue;
virDomainHostdevSubsysSCSIPtr scsisrc =
&vm->def->hostdevs[i]->source.subsys.u.scsi;
scsisrc = &vm->def->hostdevs[i]->source.subsys.u.scsi;
if (scsisrc->rawio == VIR_TRISTATE_BOOL_YES) {
rawio = true;
break;

View File

@ -511,6 +511,8 @@ int virNetMessageEncodePayloadEmpty(virNetMessagePtr msg)
void virNetMessageSaveError(virNetMessageErrorPtr rerr)
{
virErrorPtr verr;
/* This func may be called several times & the first
* error is the one we want because we don't want
* cleanup code overwriting the first one.
@ -519,7 +521,7 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr)
return;
memset(rerr, 0, sizeof(*rerr));
virErrorPtr verr = virGetLastError();
verr = virGetLastError();
if (verr) {
rerr->code = verr->code;
rerr->domain = verr->domain;

View File

@ -325,6 +325,8 @@ int virNetSocketNewListenTCP(const char *nodename,
int bindErrno = 0;
virSocketAddr tmp_addr;
int port = 0;
int e;
struct addrinfo *runp;
*retsocks = NULL;
*nretsocks = 0;
@ -346,7 +348,7 @@ int virNetSocketNewListenTCP(const char *nodename,
virSocketAddrIsWildcard(&tmp_addr)))
hints.ai_flags |= AI_ADDRCONFIG;
int e = getaddrinfo(nodename, service, &hints, &ai);
e = getaddrinfo(nodename, service, &hints, &ai);
if (e != 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Unable to resolve address '%s' service '%s': %s"),
@ -354,7 +356,7 @@ int virNetSocketNewListenTCP(const char *nodename,
return -1;
}
struct addrinfo *runp = ai;
runp = ai;
while (runp) {
virSocketAddr addr;
@ -587,6 +589,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
virSocketAddr remoteAddr;
struct addrinfo *runp;
int savedErrno = ENOENT;
int e;
*retsock = NULL;
@ -598,7 +601,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_V4MAPPED;
hints.ai_socktype = SOCK_STREAM;
int e = getaddrinfo(nodename, service, &hints, &ai);
e = getaddrinfo(nodename, service, &hints, &ai);
if (e != 0) {
virReportError(VIR_ERR_SYSTEM_ERROR,
_("Unable to resolve address '%s' service '%s': %s"),

View File

@ -43,10 +43,12 @@ int
virDaemonForkIntoBackground(const char *argv0)
{
int statuspipe[2];
pid_t pid;
if (virPipeQuiet(statuspipe) < 0)
return -1;
pid_t pid = fork();
pid = fork();
switch (pid) {
case 0:
{

View File

@ -1335,13 +1335,14 @@ void virReportSystemErrorFull(int domcode,
if (fmt) {
va_list args;
size_t len;
int n;
va_start(args, fmt);
n = g_vsnprintf(msgDetailBuf, sizeof(msgDetailBuf), fmt, args);
va_end(args);
size_t len = strlen(errnoDetail);
len = strlen(errnoDetail);
if (0 <= n && n + 2 + len < sizeof(msgDetailBuf)) {
strcpy(msgDetailBuf + n, ": ");
n += 2;

View File

@ -1412,13 +1412,16 @@ virFileReadLimFD(int fd, int maxlen, char **buf)
int
virFileReadAll(const char *path, int maxlen, char **buf)
{
int fd = open(path, O_RDONLY);
int fd;
int len;
fd = open(path, O_RDONLY);
if (fd < 0) {
virReportSystemError(errno, _("Failed to open file '%s'"), path);
return -1;
}
int len = virFileReadLimFD(fd, maxlen, buf);
len = virFileReadLimFD(fd, maxlen, buf);
VIR_FORCE_CLOSE(fd);
if (len < 0) {
virReportSystemError(errno, _("Failed to read file '%s'"), path);
@ -1431,11 +1434,14 @@ virFileReadAll(const char *path, int maxlen, char **buf)
int
virFileReadAllQuiet(const char *path, int maxlen, char **buf)
{
int fd = open(path, O_RDONLY);
int fd;
int len;
fd = open(path, O_RDONLY);
if (fd < 0)
return -errno;
int len = virFileReadLimFD(fd, maxlen, buf);
len = virFileReadLimFD(fd, maxlen, buf);
VIR_FORCE_CLOSE(fd);
if (len < 0)
return -errno;

View File

@ -88,11 +88,13 @@ int virKeycodeValueFromString(virKeycodeSet codeset,
size_t i;
for (i = 0; i < VIR_KEYMAP_ENTRY_MAX; i++) {
const char *name;
if (!virKeymapNames[codeset] ||
!virKeymapValues[codeset])
continue;
const char *name = virKeymapNames[codeset][i];
name = virKeymapNames[codeset][i];
if (name && STREQ_NULLABLE(name, keyname))
return virKeymapValues[codeset][i];

View File

@ -817,10 +817,12 @@ virNetlinkEventServerUnlock(virNetlinkEventSrvPrivatePtr driver)
static int
virNetlinkEventRemoveClientPrimitive(size_t i, unsigned int protocol)
{
virNetlinkEventRemoveCallback removeCB;
if (protocol >= MAX_LINKS)
return -EINVAL;
virNetlinkEventRemoveCallback removeCB = server[protocol]->handles[i].removeCB;
removeCB = server[protocol]->handles[i].removeCB;
if (removeCB) {
(removeCB)(server[protocol]->handles[i].watch,
@ -890,11 +892,13 @@ virNetlinkEventCallback(int watch,
int
virNetlinkEventServiceStop(unsigned int protocol)
{
virNetlinkEventSrvPrivatePtr srv;
size_t i;
if (protocol >= MAX_LINKS)
return -EINVAL;
virNetlinkEventSrvPrivatePtr srv = server[protocol];
size_t i;
srv = server[protocol];
VIR_INFO("stopping netlink event service");

View File

@ -371,6 +371,7 @@ int virDiskNameParse(const char *name, int *disk, int *partition)
int idx = 0;
static char const* const drive_prefix[] = {"fd", "hd", "vd", "sd", "xvd", "ubd"};
size_t i;
size_t n_digits;
for (i = 0; i < G_N_ELEMENTS(drive_prefix); i++) {
if (STRPREFIX(name, drive_prefix[i])) {
@ -391,8 +392,8 @@ int virDiskNameParse(const char *name, int *disk, int *partition)
ptr++;
}
/* Count the trailing digits. */
size_t n_digits = strspn(ptr, "0123456789");
/* Count the trailing digits */
n_digits = strspn(ptr, "0123456789");
if (ptr[n_digits] != '\0')
return -1;
@ -1911,10 +1912,11 @@ static int
virPipeImpl(int fds[2], bool nonblock, bool errreport)
{
#ifdef HAVE_PIPE2
int rv;
int flags = O_CLOEXEC;
if (nonblock)
flags |= O_NONBLOCK;
int rv = pipe2(fds, flags);
rv = pipe2(fds, flags);
#else /* !HAVE_PIPE2 */
# ifdef WIN32
int rv = _pipe(fds, 4096, _O_BINARY);

View File

@ -203,10 +203,11 @@ fakeParentDevice(void)
static int
addDevice(virNodeDeviceDefPtr def)
{
virNodeDeviceObjPtr obj;
if (!def)
return -1;
virNodeDeviceObjPtr obj = virNodeDeviceObjListAssignDef(driver->devs, def);
obj = virNodeDeviceObjListAssignDef(driver->devs, def);
if (!obj) {
virNodeDeviceDefFree(def);

View File

@ -90,6 +90,7 @@ testRange(const char *saddrstr, const char *eaddrstr,
virSocketAddr saddr;
virSocketAddr eaddr;
virSocketAddr netaddr;
int gotsize;
if (virSocketAddrParse(&saddr, saddrstr, AF_UNSPEC) < 0)
return -1;
@ -98,8 +99,8 @@ testRange(const char *saddrstr, const char *eaddrstr,
if (netstr && virSocketAddrParse(&netaddr, netstr, AF_UNSPEC) < 0)
return -1;
int gotsize = virSocketAddrGetRange(&saddr, &eaddr,
netstr ? &netaddr : NULL, prefix);
gotsize = virSocketAddrGetRange(&saddr, &eaddr,
netstr ? &netaddr : NULL, prefix);
VIR_DEBUG("Size want %d vs got %d", size, gotsize);
if (pass) {
/* fail if virSocketAddrGetRange returns failure, or unexpected size */
@ -136,6 +137,7 @@ static int testNetmask(const char *addr1str, const char *addr2str,
virSocketAddr addr1;
virSocketAddr addr2;
virSocketAddr netmask;
int ret;
if (virSocketAddrParse(&addr1, addr1str, AF_UNSPEC) < 0)
return -1;
@ -144,7 +146,7 @@ static int testNetmask(const char *addr1str, const char *addr2str,
if (virSocketAddrParse(&netmask, netmaskstr, AF_UNSPEC) < 0)
return -1;
int ret = virSocketAddrCheckNetmask(&addr1, &addr2, &netmask);
ret = virSocketAddrCheckNetmask(&addr1, &addr2, &netmask);
if (ret <= 0) {
return pass ? -1 : 0;

View File

@ -124,9 +124,12 @@ static int testRotatingFileInitOne(const char *filename,
VIR_DEBUG("Deleting %s", filename);
unlink(filename);
} else {
VIR_DEBUG("Creating %s size %zu", filename, (size_t)size);
char buf[1024];
int fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0700);
int fd;
VIR_DEBUG("Creating %s size %zu", filename, (size_t)size);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0700);
if (fd < 0) {
fprintf(stderr, "Cannot create %s\n", filename);
return -1;

View File

@ -1757,6 +1757,7 @@ virshBlockJobWaitInit(vshControl *ctl,
unsigned int timeout,
bool async_abort)
{
virConnectDomainEventGenericCallback cb;
virshBlockJobWaitDataPtr ret;
virshControlPtr priv = ctl->privData;
@ -1774,8 +1775,7 @@ virshBlockJobWaitInit(vshControl *ctl,
ret->status = -1;
virConnectDomainEventGenericCallback cb =
VIR_DOMAIN_EVENT_CALLBACK(virshBlockJobStatusHandler);
cb = VIR_DOMAIN_EVENT_CALLBACK(virshBlockJobStatusHandler);
if ((ret->cb_id = virConnectDomainEventRegisterAny(priv->conn, dom,
VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
@ -7117,12 +7117,14 @@ virshParseCPUList(vshControl *ctl, int *cpumaplen,
return NULL;
virBitmapSetAll(map);
} else {
int lastcpu;
if (virBitmapParse(cpulist, &map, 1024) < 0 ||
virBitmapIsAllClear(map)) {
vshError(ctl, _("Invalid cpulist '%s'"), cpulist);
goto cleanup;
}
int lastcpu = virBitmapLastSetBit(map);
lastcpu = virBitmapLastSetBit(map);
if (lastcpu >= maxcpu) {
vshError(ctl, _("CPU %d in cpulist '%s' exceed the maxcpu %d"),
lastcpu, cpulist, maxcpu);

View File

@ -275,12 +275,14 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
/* Convert the snapshot parameters into backingStore XML */
if (snapshotStrVol) {
virStorageVolPtr snapVol;
char *snapshotStrVolPath;
/* Lookup snapshot backing volume. Try the backing-vol
* parameter as a name */
vshDebug(ctl, VSH_ERR_DEBUG,
"%s: Look up backing store volume '%s' as name\n",
cmd->def->name, snapshotStrVol);
virStorageVolPtr snapVol = virStorageVolLookupByName(pool, snapshotStrVol);
snapVol = virStorageVolLookupByName(pool, snapshotStrVol);
if (snapVol)
vshDebug(ctl, VSH_ERR_DEBUG,
"%s: Backing store volume found using '%s' as name\n",
@ -315,7 +317,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
char *snapshotStrVolPath;
if ((snapshotStrVolPath = virStorageVolGetPath(snapVol)) == NULL) {
virStorageVolFree(snapVol);
goto cleanup;

View File

@ -428,11 +428,12 @@ dissect_libvirt_payload(tvbuff_t *tvb, proto_tree *tree,
if (status == VIR_NET_OK) {
const vir_dissector_index_t *pds = get_program_data(prog, VIR_PROGRAM_DISSECTORS);
const gsize *len = get_program_data(prog, VIR_PROGRAM_DISSECTORS_LEN);
vir_xdr_dissector_t xd;
if (!len)
goto unknown;
vir_xdr_dissector_t xd = find_payload_dissector(proc, type, pds, *len);
xd = find_payload_dissector(proc, type, pds, *len);
if (xd == NULL)
goto unknown;
dissect_libvirt_payload_xdr_data(tvb, tree, payload_length, status, xd);