[PATCH] qemu: Remove unnecessary variables and labels
by Kristina Hanicova
This patch removes variables such as 'ret', 'rc' and others which
are easily replaced. Therefore, making the code look cleaner and
easier to understand.
Signed-off-by: Kristina Hanicova <khanicov(a)redhat.com>
---
src/driver.c | 4 +--
src/qemu/qemu_agent.c | 4 +--
src/qemu/qemu_alias.c | 14 +++-----
src/qemu/qemu_capabilities.c | 21 +++++------
src/qemu/qemu_cgroup.c | 7 ++--
src/qemu/qemu_conf.c | 15 ++++----
src/qemu/qemu_domain_address.c | 9 ++---
src/qemu/qemu_driver.c | 64 ++++++++++++----------------------
8 files changed, 48 insertions(+), 90 deletions(-)
diff --git a/src/driver.c b/src/driver.c
index 329d493a50..9ae95cb4c3 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -52,7 +52,6 @@ virDriverLoadModule(const char *name,
bool required)
{
g_autofree char *modfile = NULL;
- int ret;
VIR_DEBUG("Module load %s", name);
@@ -64,8 +63,7 @@ virDriverLoadModule(const char *name,
"LIBVIRT_DRIVER_DIR")))
return -1;
- ret = virModuleLoad(modfile, regfunc, required);
- return ret;
+ return virModuleLoad(modfile, regfunc, required);
}
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index c3b02569cd..08436a9705 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -176,7 +176,6 @@ qemuAgentOpenUnix(const char *socketpath)
{
struct sockaddr_un addr;
int agentfd;
- int ret = -1;
if ((agentfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
virReportSystemError(errno,
@@ -199,8 +198,7 @@ qemuAgentOpenUnix(const char *socketpath)
goto error;
}
- ret = connect(agentfd, (struct sockaddr *)&addr, sizeof(addr));
- if (ret < 0) {
+ if (connect(agentfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
virReportSystemError(errno, "%s",
_("failed to connect to agent socket"));
goto error;
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index a36f346592..5e35f43614 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -744,16 +744,13 @@ qemuAssignDeviceAliases(virDomainDef *def, virQEMUCaps *qemuCaps)
char *
qemuAliasDiskDriveFromDisk(const virDomainDiskDef *disk)
{
- char *ret;
-
if (!disk->info.alias) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("disk does not have an alias"));
return NULL;
}
- ret = g_strdup_printf("%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
- return ret;
+ return g_strdup_printf("%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
}
@@ -780,18 +777,15 @@ qemuAliasDiskDriveSkipPrefix(const char *dev_name)
char *
qemuAliasFromHostdev(const virDomainHostdevDef *hostdev)
{
- char *ret;
-
if (!hostdev->info->alias) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("hostdev does not have an alias"));
return NULL;
}
- ret = g_strdup_printf("%s-%s",
- virDomainDeviceAddressTypeToString(hostdev->info->type),
- hostdev->info->alias);
- return ret;
+ return g_strdup_printf("%s-%s",
+ virDomainDeviceAddressTypeToString(hostdev->info->type),
+ hostdev->info->alias);
}
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a4c492dde2..33797469a6 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3070,7 +3070,6 @@ virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
g_auto(GStrv) list = NULL;
size_t i;
size_t n;
- int ret = -1;
*features = NULL;
modelInfo = virQEMUCapsGetCPUModelInfo(qemuCaps, virtType);
@@ -3091,12 +3090,10 @@ virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
}
*features = g_steal_pointer(&list);
- if (migratable && !modelInfo->migratability)
- ret = 1;
- else
- ret = 0;
- return ret;
+ if (migratable && !modelInfo->migratability)
+ return 1;
+ return 0;
}
@@ -5237,15 +5234,13 @@ virQEMUCapsProbeQMPSchemaCapabilities(virQEMUCaps *qemuCaps,
virDomainVirtType
virQEMUCapsGetVirtType(virQEMUCaps *qemuCaps)
{
- virDomainVirtType type;
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
- type = VIR_DOMAIN_VIRT_KVM;
- else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_TCG))
- type = VIR_DOMAIN_VIRT_QEMU;
- else
- type = VIR_DOMAIN_VIRT_NONE;
+ return VIR_DOMAIN_VIRT_KVM;
+
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_TCG))
+ return VIR_DOMAIN_VIRT_QEMU;
- return type;
+ return VIR_DOMAIN_VIRT_NONE;
}
int
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 1e7b562b33..c07058d2f8 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -336,18 +336,15 @@ static int
qemuSetupTPMCgroup(virDomainObj *vm,
virDomainTPMDef *dev)
{
- int ret = 0;
-
switch (dev->type) {
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
- ret = qemuSetupChrSourceCgroup(vm, dev->data.passthrough.source);
- break;
+ return qemuSetupChrSourceCgroup(vm, dev->data.passthrough.source);
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
}
- return ret;
+ return 0;
}
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 0451bc70ac..d31cd05ab4 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1915,16 +1915,13 @@ qemuGetBaseHugepagePath(virQEMUDriver *driver,
virHugeTLBFS *hugepage)
{
const char *root = driver->embeddedRoot;
- char *ret;
if (root && !STRPREFIX(hugepage->mnt_dir, root)) {
g_autofree char * hash = virDomainDriverGenerateRootHash("qemu", root);
- ret = g_strdup_printf("%s/libvirt/%s", hugepage->mnt_dir, hash);
- } else {
- ret = g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir);
+ return g_strdup_printf("%s/libvirt/%s", hugepage->mnt_dir, hash);
}
- return ret;
+ return g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir);
}
@@ -1935,11 +1932,11 @@ qemuGetDomainHugepagePath(virQEMUDriver *driver,
{
g_autofree char *base = qemuGetBaseHugepagePath(driver, hugepage);
g_autofree char *domPath = virDomainDefGetShortName(def);
- char *ret = NULL;
- if (base && domPath)
- ret = g_strdup_printf("%s/%s", base, domPath);
- return ret;
+ if (!base || !domPath)
+ return NULL;
+
+ return g_strdup_printf("%s/%s", base, domPath);
}
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 9abe2b84c8..22bf5d3b54 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -2465,7 +2465,6 @@ static int
qemuDomainAddressFindNewTargetIndex(virDomainDef *def)
{
int targetIndex;
- int ret = -1;
/* Try all indexes between 1 and 31 - QEMU only supports 32
* PHBs, and 0 is reserved for the default, implicit one */
@@ -2490,13 +2489,11 @@ qemuDomainAddressFindNewTargetIndex(virDomainDef *def)
/* If no existing PCI controller uses this index, great,
* it means it's free and we can return it to the caller */
- if (!found) {
- ret = targetIndex;
- break;
- }
+ if (!found)
+ return targetIndex;
}
- return ret;
+ return -1;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d954635dde..860c5b70a8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1332,7 +1332,6 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
g_autofree char *data = NULL;
g_auto(GStrv) lines = NULL;
size_t i;
- int ret = -1;
double val;
*cpuWait = 0;
@@ -1344,21 +1343,19 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
else
proc = g_strdup_printf("/proc/%d/sched", (int)pid);
if (!proc)
- goto cleanup;
- ret = -1;
+ return -1;
/* The file is not guaranteed to exist (needs CONFIG_SCHED_DEBUG) */
if (access(proc, R_OK) < 0) {
- ret = 0;
- goto cleanup;
+ return 0;
}
if (virFileReadAll(proc, (1<<16), &data) < 0)
- goto cleanup;
+ return -1;
lines = g_strsplit(data, "\n", 0);
if (!lines)
- goto cleanup;
+ return -1;
for (i = 0; lines[i] != NULL; i++) {
const char *line = lines[i];
@@ -1372,7 +1369,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Missing separator in sched info '%s'"),
lines[i]);
- goto cleanup;
+ return -1;
}
line++;
while (*line == ' ')
@@ -1382,7 +1379,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to parse sched info value '%s'"),
line);
- goto cleanup;
+ return -1;
}
*cpuWait = (unsigned long long)(val * 1000000);
@@ -1390,10 +1387,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
}
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
@@ -3178,7 +3172,6 @@ doCoreDump(virQEMUDriver *driver,
{
int fd = -1;
int ret = -1;
- int rc = -1;
virFileWrapperFd *wrapperFd = NULL;
int directFlag = 0;
bool needUnlink = false;
@@ -3224,8 +3217,9 @@ doCoreDump(virQEMUDriver *driver,
if (STREQ(memory_dump_format, "elf"))
memory_dump_format = NULL;
- rc = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
- memory_dump_format);
+ if (qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
+ memory_dump_format) < 0)
+ goto cleanup;
} else {
if (dumpformat != VIR_DOMAIN_CORE_DUMP_FORMAT_RAW) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
@@ -3237,13 +3231,11 @@ doCoreDump(virQEMUDriver *driver,
if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0))
goto cleanup;
- rc = qemuMigrationSrcToFile(driver, vm, fd, compressor,
- QEMU_ASYNC_JOB_DUMP);
+ if (qemuMigrationSrcToFile(driver, vm, fd, compressor,
+ QEMU_ASYNC_JOB_DUMP) < 0)
+ goto cleanup;
}
- if (rc < 0)
- goto cleanup;
-
if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno,
_("unable to close file %s"),
@@ -7225,14 +7217,12 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm,
{
virQEMUDriver *driver = dom->conn->privateData;
virDomainDeviceDef oldDev = { .type = dev->type };
- int ret = -1;
int idx;
switch ((virDomainDeviceType)dev->type) {
case VIR_DOMAIN_DEVICE_DISK:
qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL);
- ret = qemuDomainChangeDiskLive(vm, dev, driver, force);
- break;
+ return qemuDomainChangeDiskLive(vm, dev, driver, force);
case VIR_DOMAIN_DEVICE_GRAPHICS:
if ((idx = qemuDomainFindGraphicsIndex(vm->def, dev->data.graphics)) >= 0) {
@@ -7243,8 +7233,7 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm,
return -1;
}
- ret = qemuDomainChangeGraphics(driver, vm, dev->data.graphics);
- break;
+ return qemuDomainChangeGraphics(driver, vm, dev->data.graphics);
case VIR_DOMAIN_DEVICE_NET:
if ((idx = virDomainNetFindIdx(vm->def, dev->data.net)) >= 0) {
@@ -7255,12 +7244,10 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm,
return -1;
}
- ret = qemuDomainChangeNet(driver, vm, dev);
- break;
+ return qemuDomainChangeNet(driver, vm, dev);
case VIR_DOMAIN_DEVICE_MEMORY:
- ret = qemuDomainChangeMemoryLive(driver, vm, dev);
- break;
+ return qemuDomainChangeMemoryLive(driver, vm, dev);
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
@@ -7288,10 +7275,10 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("live update of device '%s' is not supported"),
virDomainDeviceTypeToString(dev->type));
- break;
+ return -1;
}
- return ret;
+ return -1;
}
@@ -9681,13 +9668,11 @@ qemuGetVcpusBWLive(virDomainObj *vm,
{
g_autoptr(virCgroup) cgroup_vcpu = NULL;
qemuDomainObjPrivate *priv = NULL;
- int rc;
priv = vm->privateData;
if (!qemuDomainHasVcpuPids(vm)) {
/* We do not create sub dir for each vcpu */
- rc = qemuGetVcpuBWLive(priv->cgroup, period, quota);
- if (rc < 0)
+ if (qemuGetVcpuBWLive(priv->cgroup, period, quota) < 0)
return -1;
if (*quota > 0)
@@ -9700,8 +9685,7 @@ qemuGetVcpusBWLive(virDomainObj *vm,
false, &cgroup_vcpu) < 0)
return -1;
- rc = qemuGetVcpuBWLive(cgroup_vcpu, period, quota);
- if (rc < 0)
+ if (qemuGetVcpuBWLive(cgroup_vcpu, period, quota) < 0)
return -1;
return 0;
@@ -9731,12 +9715,11 @@ qemuGetIOThreadsBWLive(virDomainObj *vm,
{
g_autoptr(virCgroup) cgroup_iothread = NULL;
qemuDomainObjPrivate *priv = NULL;
- int rc;
priv = vm->privateData;
if (!vm->def->niothreadids) {
/* We do not create sub dir for each iothread */
- if ((rc = qemuGetVcpuBWLive(priv->cgroup, period, quota)) < 0)
+ if (qemuGetVcpuBWLive(priv->cgroup, period, quota) < 0)
return -1;
return 0;
@@ -9748,8 +9731,7 @@ qemuGetIOThreadsBWLive(virDomainObj *vm,
false, &cgroup_iothread) < 0)
return -1;
- rc = qemuGetVcpuBWLive(cgroup_iothread, period, quota);
- if (rc < 0)
+ if (qemuGetVcpuBWLive(cgroup_iothread, period, quota) < 0)
return -1;
return 0;
--
2.31.1
3 years, 4 months
[libvirt PATCH] ci: display installed packages at start of build
by Daniel P. Berrangé
When a build fails it is helpful to know what packages were installed,
because by the time we look at the build job output, the original
container image might have changed.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
.gitlab-ci.yml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d486faca58..6ba11a0431 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -24,6 +24,7 @@ include: '/ci/gitlab.yml'
key: "$CI_JOB_NAME"
before_script:
- *script_variables
+ - cat /packages.txt
script:
- meson setup build --werror $MESON_ARGS || (cat build/meson-logs/meson-log.txt && exit 1)
- meson dist -C build --no-tests
@@ -43,6 +44,7 @@ include: '/ci/gitlab.yml'
key: "$CI_JOB_NAME"
before_script:
- *script_variables
+ - cat /packages.txt
script:
- meson setup build --werror $MESON_OPTS || (cat build/meson-logs/meson-log.txt && exit 1)
- meson compile -C build
--
2.33.1
3 years, 4 months
[libvirt PATCH 0/4] Coverity fixes
by Ján Tomko
Ján Tomko (4):
tools: virt-host-validate: fix memory leak
vbox: fix vboxCapsInit
ch: fix logic in virCHMonitorBuildPtyJson
tests: pcivpdtest: check return value of virCreateAnonymousFile
src/ch/ch_monitor.c | 4 +---
src/vbox/vbox_common.c | 1 -
tests/virpcivpdtest.c | 20 ++++++++++++++++++++
tools/virt-host-validate-ch.c | 2 +-
4 files changed, 22 insertions(+), 5 deletions(-)
--
2.31.1
3 years, 4 months
[libvirt PATCH 0/3] ci: improve mingw coverage
by Daniel P. Berrangé
This ensures at least one mingw job is gating for pipelines
Daniel P. Berrangé (3):
ci: replace Fedora 33 with Fedora 35
ci: refresh variables/dockerfiles with latest content
ci: run a mingw64 job on stable Fedora
ci/cirrus/freebsd-12.vars | 7 +-
ci/cirrus/freebsd-13.vars | 7 +-
ci/cirrus/freebsd-current.vars | 7 +-
ci/cirrus/macos-11.vars | 7 +-
ci/containers/centos-8.Dockerfile | 7 +-
ci/containers/centos-stream-8.Dockerfile | 7 +-
.../fedora-35-cross-mingw32.Dockerfile | 92 +++++++++++++++++++
.../fedora-35-cross-mingw64.Dockerfile | 92 +++++++++++++++++++
...ora-33.Dockerfile => fedora-35.Dockerfile} | 2 +-
.../fedora-rawhide-cross-mingw32.Dockerfile | 2 +-
.../fedora-rawhide-cross-mingw64.Dockerfile | 2 +-
ci/containers/fedora-rawhide.Dockerfile | 2 +-
ci/containers/opensuse-tumbleweed.Dockerfile | 2 +-
ci/gitlab.yml | 50 ++++++----
ci/manifest.yml | 13 ++-
15 files changed, 254 insertions(+), 45 deletions(-)
create mode 100644 ci/containers/fedora-35-cross-mingw32.Dockerfile
create mode 100644 ci/containers/fedora-35-cross-mingw64.Dockerfile
rename ci/containers/{fedora-33.Dockerfile => fedora-35.Dockerfile} (98%)
--
2.33.1
3 years, 4 months
[PATCH v3 0/2] Fix /proc/*/stat parsing
by Martin Kletzander
While working on some polkit stuff I found out that we are inconsistent with the
way we parse /proc/*/stat files, so I added a new helper instead along with some
tests. Unfortunately using it for the thing I wanted is not really viable in
the end, so it "violates" the Rule of three, but at least it does something
correctly.
v3:
- Added an enum with names for the fields of the file
- Made this not limited to linux as that was the way it worked in qemu before
v2:
- https://listman.redhat.com/archives/libvir-list/2021-November/msg00606.html
- Fixed open64 by just using virFileReadAllQuiet instead of g_file_get_contents
- Removed some leftover unused variables
- Still do not know why my cirrus builds fail
v1:
- https://listman.redhat.com/archives/libvir-list/2021-November/msg00580.html
Martin Kletzander (2):
util: Add virProcessGetStat
Use virProcessGetStat
src/libvirt_private.syms | 1 +
src/qemu/qemu_driver.c | 34 ++-----
src/util/virprocess.c | 125 +++++++++++++++++---------
src/util/virprocess.h | 66 ++++++++++++++
tests/meson.build | 1 +
tests/virprocessstatdata/complex/stat | 2 +
tests/virprocessstatdata/simple/stat | 1 +
tests/virprocessstattest.c | 88 ++++++++++++++++++
8 files changed, 249 insertions(+), 69 deletions(-)
create mode 100644 tests/virprocessstatdata/complex/stat
create mode 100644 tests/virprocessstatdata/simple/stat
create mode 100644 tests/virprocessstattest.c
--
2.34.0
3 years, 4 months
[libvirt PATCH 0/2] snapshot revert fix followup
by Pavel Hrdina
Pavel Hrdina (2):
qemu_monitor: remove unused load snapshot code
virsh: man: update snapshot-revert description
docs/manpages/virsh.rst | 4 ++++
src/qemu/qemu_monitor.c | 11 -----------
src/qemu/qemu_monitor.h | 1 -
src/qemu/qemu_monitor_text.c | 36 ------------------------------------
src/qemu/qemu_monitor_text.h | 1 -
5 files changed, 4 insertions(+), 49 deletions(-)
--
2.31.1
3 years, 4 months
[PATCH 00/12] Remove virXMLPropStringLimit and virXPathStringLimit
by Peter Krempa
The functions have API which is impossible to be use correctly by
callers. Refactor callers and remove the functions.
Note that this patchset preserves semantics of the callers (except for
removing duplicate or ignored errors). Some of the callers look fishy,
but that is not addressed here.
Peter Krempa (12):
util: seclabel: Define autoptr cleanup func for virSecurityLabelDef
and virSecurityDeviceLabelDef
virSecurityLabelDef: Declare 'type' as 'virDomainSeclabelType'
virSecurityLabelDefParseXML: Directly assign strings into appropriate
variables
virSecurityLabelDefParseXML: Don't reuse temporary string 'p'
virSecurityLabelDefParseXML: Use automatic freeing for 'seclabel'
virSecurityLabelDefParseXML: Remove pointless 'error' label
virNodeDeviceCapVPDParseCustomFields: Don't use 'virXPathStringLimit'
virSecurityLabelDefParseXML: Don't use 'virXPathStringLimit'
virSecurityDeviceLabelDefParseXML: Use automatic memory clearing for
temp strings
virSecurityDeviceLabelDefParseXML: Don't use 'virXPathStringLimit'
virSecurityLabelDefParseXML: Don't use virXMLPropStringLimit
util: xml: Remove virXMLPropStringLimit and virXPathStringLimit
src/conf/domain_conf.c | 104 +++++++++++++++-----------------
src/conf/node_device_conf.c | 6 +-
src/libvirt_private.syms | 2 -
src/security/security_selinux.c | 3 +-
src/util/virseclabel.h | 6 +-
src/util/virxml.c | 62 -------------------
src/util/virxml.h | 8 ---
7 files changed, 59 insertions(+), 132 deletions(-)
--
2.31.1
3 years, 4 months
[PATCH 0/1] tools/bash-completion: fix variable leaks of "IFS" and "word"
by Koichi Murase
Description:
The bash-completion function for virsh, which is defined in
/usr/share/bash-completion/completions/virsh (generated from libvirt
tools/bash-completion/vsh.in), overwrites the shell variables "IFS"
and "word" on query for completions.
Repeat-By:
I am testing it with Fedora 35 Workstation where the completion
script is provided by the package:
libvirt-client-7.6.0-3.fc35.x86_64
With a Bash session with bash-completion loaded, one can observe the
change of Bash behavior after the attempt of the completion for
"virsh" command as follows:
$ declare -p IFS | cat -A
declare -- IFS=" ^I$
"$
$ virsh a[TAB][TAB]
allocpages attach-device attach-disk attach-interface autostart
$ virsh a[C-c]
$ declare -p IFS | cat -A
declare -- IFS="$
"$
Originally the value of IFS is IFS=$' \t\n', but it becomes
IFS=$'\n' after the attempt of the completion. After that, word
splitting of the shell will not be processed as normal:
$ a='a b c'
$ printf '<%s>\n' $a
<a>
<b>
<c>
$ virsh a[TAB][TAB][C-c]
$ printf '<%s>\n' $a
<a b c>
The shell variable "word" is also affected by the virsh completion.
Fix:
The completion function "_virsh_complete" should declare "IFS" and
"word" as local variables before changing them.
Reference:
I initially received the related issue in my project at
https://github.com/akinomyoga/ble.sh/issues/147
--
Koichi
Koichi Murase (1):
bash-completion: fix variable leaks of "IFS" and "word"
tools/bash-completion/vsh.in | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--
2.21.3
3 years, 4 months
[PATCH] meson: fix cpuset_getaffinity() detection
by Roman Bogorodskiy
The cpuset_getaffinity() function is checked in sys/cpuset.h to see if
BSD CPU affinity APIs are available. This check requires including
sys/param.h to work properly, otherwise the test program fails with
unrelated errors like:
/usr/include/sys/cpuset.h:155:1: error: unknown type name
'__BEGIN_DECLS'
__BEGIN_DECLS
^
/usr/include/sys/cpuset.h:156:12: error: unknown type name 'cpusetid_t';
did you mean 'cpuset_t'?
int cpuset(cpusetid_t *);
and so forth.
Signed-off-by: Roman Bogorodskiy <bogorodskiy(a)gmail.com>
---
meson.build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/meson.build b/meson.build
index e4f36e8574..ad0cd44aca 100644
--- a/meson.build
+++ b/meson.build
@@ -709,7 +709,7 @@ if (cc.has_header_symbol('net/if_bridgevar.h', 'BRDGSFD', prefix: brd_required_h
endif
# Check for BSD CPU affinity availability
-if cc.has_header_symbol('sys/cpuset.h', 'cpuset_getaffinity')
+if cc.has_header_symbol('sys/cpuset.h', 'cpuset_getaffinity', prefix: '#include <sys/param.h>')
conf.set('WITH_BSD_CPU_AFFINITY', 1)
endif
--
2.33.1
3 years, 4 months
[PATCH] meson: improve CPU affinity routines check
by Roman Bogorodskiy
Recently, FreeBSD has got sched_get/setaffinity(3) implementations and
the sched.h header as well [1]. To make these routines visible,
users have to define _WITH_CPU_SET_T.
This breaks current detection. Specifically, meson sees the
sched_getaffinity() symbol and defines WITH_SCHED_GETAFFINITY. This
define unlocks Linux implementation of virProcessSetAffinity() and other
functions, which fails to build on FreeBSD because cpu_set_t is not
visible as _WITH_CPU_SET_T is not defined.
For now, change detection to the following:
- Instead of checking sched_getaffinity(), check if 'cpu_set_t' is
available through sched.h
- Explicitly check the sched.h header instead of assuming its presence
if WITH_SCHED_SETSCHEDULER is defined
1:
https://cgit.freebsd.org/src/commit/?id=43736b71dd051212d5c55be9fa21c4599...
https://cgit.freebsd.org/src/commit/?id=160b4b922b6021848b6b48afc894d16b8...
https://cgit.freebsd.org/src/commit/?id=90fa9705d5cd29cf11c5dc7319299788d...
Signed-off-by: Roman Bogorodskiy <bogorodskiy(a)gmail.com>
---
meson.build | 4 +++-
src/util/virprocess.c | 8 ++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/meson.build b/meson.build
index 9022bcfdc9..e4f36e8574 100644
--- a/meson.build
+++ b/meson.build
@@ -553,7 +553,6 @@ functions = [
'posix_fallocate',
'posix_memalign',
'prlimit',
- 'sched_getaffinity',
'sched_setscheduler',
'setgroups',
'setns',
@@ -602,6 +601,7 @@ headers = [
'net/if.h',
'pty.h',
'pwd.h',
+ 'sched.h',
'sys/auxv.h',
'sys/ioctl.h',
'sys/mount.h',
@@ -671,6 +671,8 @@ symbols = [
# Check for BSD approach for setting MAC addr
[ 'net/if_dl.h', 'link_addr', '#include <sys/types.h>\n#include <sys/socket.h>' ],
+
+ [ 'sched.h', 'cpu_set_t' ],
]
if host_machine.system() == 'linux'
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 6de3f36f52..81de90200e 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -35,7 +35,7 @@
# include <sys/time.h>
# include <sys/resource.h>
#endif
-#if WITH_SCHED_SETSCHEDULER
+#if WITH_SCHED_H
# include <sched.h>
#endif
@@ -480,7 +480,7 @@ int virProcessKillPainfully(pid_t pid, bool force)
return virProcessKillPainfullyDelay(pid, force, 0, false);
}
-#if WITH_SCHED_GETAFFINITY
+#if WITH_DECL_CPU_SET_T
int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet)
{
@@ -626,7 +626,7 @@ virProcessGetAffinity(pid_t pid)
return ret;
}
-#else /* WITH_SCHED_GETAFFINITY */
+#else /* WITH_DECL_CPU_SET_T */
int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED,
virBitmap *map G_GNUC_UNUSED,
@@ -646,7 +646,7 @@ virProcessGetAffinity(pid_t pid G_GNUC_UNUSED)
_("Process CPU affinity is not supported on this platform"));
return NULL;
}
-#endif /* WITH_SCHED_GETAFFINITY */
+#endif /* WITH_DECL_CPU_SET_T */
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
--
2.33.1
3 years, 4 months