From: Peter Krempa <[email protected]> Some test cases (qemuxmlconftest) currently use made up descriptors, which cause e.g. valgrind to be unhappy:
==831186== File descriptor 1729 Invalid file descriptor ==831186== at 0x531042E: fgetxattr (in /usr/lib64/libc.so.6) ==831186== by 0x5AE2846: ??? (in /usr/lib64/libselinux.so.1) ==831186== by 0x5AE7093: fgetfilecon_raw (in /usr/lib64/libselinux.so.1) ==831186== by 0x4EB736F: qemuFDPassLogFDInfo (qemu_fd.c:92) ==831186== by 0x4EB7B8E: qemuFDPassDirectTransferCommand (qemu_fd.c:443) when tracking FDs. Since 'qemuFDPassLogFDInfo' just logs information about the FD we can simply not query the FD if it's made up. Signed-off-by: Peter Krempa <[email protected]> --- src/qemu/qemu_fd.c | 65 +++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_fd.c b/src/qemu/qemu_fd.c index ef0a8d8127..8c8b6afcfd 100644 --- a/src/qemu/qemu_fd.c +++ b/src/qemu/qemu_fd.c @@ -25,6 +25,8 @@ #include "virfile.h" #include "virlog.h" +#include <fcntl.h> + /* Used strictly for logging selinux context of passed FD */ #ifdef WITH_SECDRIVER_SELINUX # include <selinux/selinux.h> @@ -59,40 +61,43 @@ qemuFDPassLogFDInfo(const char *name, g_autofree char *selinux = NULL; g_autofree char *tmp = NULL; - if (fstat(fd, &st) == 0) { - switch (st.st_mode & S_IFMT) { - case S_IFBLK: - type = "block"; - break; - case S_IFCHR: - type = "char"; - break; - case S_IFDIR: - type = "directory"; - break; - case S_IFIFO: - type = "pipe"; - break; - case S_IFLNK: - type = "symlink"; - break; - case S_IFREG: - type = "file"; - break; - case S_IFSOCK: - type = "socket"; - break; - default: - type = tmp = g_strdup_printf("unknown:'0x%x')", st.st_mode & S_IFMT); - break; + if (fcntl(fd, F_GETFD) != -1) { + if (fstat(fd, &st) == 0) { + switch (st.st_mode & S_IFMT) { + case S_IFBLK: + type = "block"; + break; + case S_IFCHR: + type = "char"; + break; + case S_IFDIR: + type = "directory"; + break; + case S_IFIFO: + type = "pipe"; + break; + case S_IFLNK: + type = "symlink"; + break; + case S_IFREG: + type = "file"; + break; + case S_IFSOCK: + type = "socket"; + break; + default: + type = tmp = g_strdup_printf("unknown:'0x%x')", st.st_mode & S_IFMT); + break; + } } - } #ifdef WITH_SECDRIVER_SELINUX - ignore_value(fgetfilecon_raw(fd, &selinux)); -#else - selinux = g_strdup("N/A"); + ignore_value(fgetfilecon_raw(fd, &selinux)); #endif + } + + if (!selinux) + selinux = g_strdup("N/A"); VIR_DEBUG("passing fd:'%i', name:'%s'(%zu) type:'%s' selinux:'%s'", fd, name, idx, type, selinux); -- 2.54.0
