[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 17/25] oslib-posix: Ignore fcntl("/dev/null", F_SETFL
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 17/25] oslib-posix: Ignore fcntl("/dev/null", F_SETFL, O_NONBLOCK) failure |
Date: |
Sat, 9 Mar 2019 08:48:10 +0100 |
From: Philippe Mathieu-Daudé <address@hidden>
Previous to OpenBSD 6.3 [1], fcntl(F_SETFL) is not permitted on
memory devices.
Trying this call sets errno to ENODEV ("not a memory device"):
19 ENODEV Operation not supported by device.
An attempt was made to apply an inappropriate function to a device,
for example, trying to read a write-only device such as a printer.
Do not assert fcntl failures in this specific case (errno set to ENODEV)
on OpenBSD. This fixes:
$ lm32-softmmu/qemu-system-lm32
assertion "f != -1" failed: file "util/oslib-posix.c", line 247, function
"qemu_set_nonblock"
Abort trap (core dumped)
[1] The fix seems https://github.com/openbsd/src/commit/c2a35b387f9d3c
"fcntl(F_SETFL) invokes the FIONBIO and FIOASYNC ioctls internally, so
the memory devices (/dev/null, /dev/zero, etc) need to permit them."
Reviewed-by: Peter Maydell <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
util/oslib-posix.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 37c5854..326d92d 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -244,7 +244,19 @@ void qemu_set_nonblock(int fd)
f = fcntl(fd, F_GETFL);
assert(f != -1);
f = fcntl(fd, F_SETFL, f | O_NONBLOCK);
+#ifdef __OpenBSD__
+ if (f == -1) {
+ /*
+ * Previous to OpenBSD 6.3, fcntl(F_SETFL) is not permitted on
+ * memory devices and sets errno to ENODEV.
+ * It's OK if we fail to set O_NONBLOCK on devices like /dev/null,
+ * because they will never block anyway.
+ */
+ assert(errno == ENODEV);
+ }
+#else
assert(f != -1);
+#endif
}
int socket_set_fast_reuse(int fd)
--
1.8.3.1
- [Qemu-devel] [PULL 03/25] hw/i386/pc: run the multiboot loader before the PVH loader, (continued)
- [Qemu-devel] [PULL 03/25] hw/i386/pc: run the multiboot loader before the PVH loader, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 02/25] vfio-pci: enable by default, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 04/25] block/iscsi: Restrict Linux-specific code, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 08/25] i386: extended the cpuid_level when Intel PT is enabled, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 07/25] target-i386: add kvm stubs to user-mode emulators, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 14/25] build: remove unnecessary assignments from Makefile.target, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 12/25] update copyright notice, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 19/25] scsi-disk: Fix crash if request is invaild or disk is no medium, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 11/25] lsi: check if SIGP bit is already set in Wait reselect, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 20/25] lsi: use ldn_le_p()/stn_le_p(), Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 17/25] oslib-posix: Ignore fcntl("/dev/null", F_SETFL, O_NONBLOCK) failure,
Paolo Bonzini <=
- [Qemu-devel] [PULL 16/25] accel: Allow to build QEMU without TCG or KVM support, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 24/25] lsi: return dfifo value, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 10/25] lsi: implement basic SBCL functionality, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 06/25] configure: Enable werror for git worktrees, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 18/25] configure: Disable W^X on OpenBSD, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 25/25] exec: streamline flatview_add_to_dispatch, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 22/25] lsi: use enum type for s->msg_action, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 09/25] virtio-scsi: Fix build with gcc 9, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 23/25] lsi: use SCSI phase names instead of numbers in trace, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 05/25] contrib/elf2dmp: add kernel start address checking, Paolo Bonzini, 2019/03/09