* [Qemu-devel] [PATCH] pci-assign: do not test path with access() before opening
@ 2015-11-02 14:17 Paolo Bonzini
2015-11-02 15:30 ` Eric Blake
2015-11-03 12:12 ` Michael Tokarev
0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2015-11-02 14:17 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
Using access() is a time-of-check/time-of-use race condition. It is
okay to use them to provide better error messages, but that is pretty
much it.
In this case we can get the same error from fopen(), so just use
strerror and errno there---which actually improves the error
message most of the time.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/i386/pci-assign-load-rom.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/hw/i386/pci-assign-load-rom.c b/hw/i386/pci-assign-load-rom.c
index 34a3a7e..e40b586 100644
--- a/hw/i386/pci-assign-load-rom.c
+++ b/hw/i386/pci-assign-load-rom.c
@@ -45,14 +45,10 @@ void *pci_assign_dev_load_option_rom(PCIDevice *dev, struct Object *owner,
return NULL;
}
- if (access(rom_file, F_OK)) {
- error_report("pci-assign: Insufficient privileges for %s", rom_file);
- return NULL;
- }
-
/* Write "1" to the ROM file to enable it */
fp = fopen(rom_file, "r+");
if (fp == NULL) {
+ error_report("pci-assign: Cannot open %s: %s", rom_file, strerror(errno));
return NULL;
}
val = 1;
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] pci-assign: do not test path with access() before opening
2015-11-02 14:17 [Qemu-devel] [PATCH] pci-assign: do not test path with access() before opening Paolo Bonzini
@ 2015-11-02 15:30 ` Eric Blake
2015-11-03 12:12 ` Michael Tokarev
1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2015-11-02 15:30 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: qemu-trivial
[-- Attachment #1: Type: text/plain, Size: 687 bytes --]
On 11/02/2015 07:17 AM, Paolo Bonzini wrote:
> Using access() is a time-of-check/time-of-use race condition. It is
> okay to use them to provide better error messages, but that is pretty
> much it.
>
> In this case we can get the same error from fopen(), so just use
> strerror and errno there---which actually improves the error
> message most of the time.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> hw/i386/pci-assign-load-rom.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] pci-assign: do not test path with access() before opening
2015-11-02 14:17 [Qemu-devel] [PATCH] pci-assign: do not test path with access() before opening Paolo Bonzini
2015-11-02 15:30 ` Eric Blake
@ 2015-11-03 12:12 ` Michael Tokarev
1 sibling, 0 replies; 3+ messages in thread
From: Michael Tokarev @ 2015-11-03 12:12 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: qemu-trivial
02.11.2015 17:17, Paolo Bonzini wrote:
> Using access() is a time-of-check/time-of-use race condition. It is
> okay to use them to provide better error messages, but that is pretty
> much it.
>
> In this case we can get the same error from fopen(), so just use
> strerror and errno there---which actually improves the error
> message most of the time.
Applied to -trivial, thank you!
/mjt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-11-03 12:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-02 14:17 [Qemu-devel] [PATCH] pci-assign: do not test path with access() before opening Paolo Bonzini
2015-11-02 15:30 ` Eric Blake
2015-11-03 12:12 ` Michael Tokarev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).