+Eric for macros & errno handling

On 7/4/20 11:11 AM, Peter Maydell wrote:
> On Fri, 3 Jul 2020 at 22:55, Philippe Mathieu-Daudé <f4...@amsat.org> wrote:
>>
>> On 7/3/20 11:35 PM, Michele Denber wrote:
>>>   What is TFR?
>>
>> TFR() is defined in include/qemu-common.h:
> 
> Yep; adding #include "qemu-common.h" to tap-solaris.c should fix
> this (I think we missed tap-solaris.c in the header cleanup of
> commit a8d2532645cf5ce4).

Any idea what means TFR? I understand it keeps retrying while
interrupted, but can't find the origin of that abbreviation.

I'm not sure what we gain by using this macro, it seems dangerous
as there is no guaranty we 'expr' is a single libc call updating
errno.

We have:

include/qemu-common.h:13:#define TFR(expr) do { if ((expr) != -1) break;
} while (errno == EINTR)

block/file-posix.c:1515:    } while (errno == EINTR);
block/file-posix.c:1539:        } while (errno == EINTR);
block/file-posix.c:1701:        } while (errno == EINTR);

Good, de-macro-ified form.

chardev/char-fd.c:122:    TFR(fd = qemu_open(src, flags, 0666));
chardev/char-pipe.c:135:    TFR(fd_in = qemu_open(filename_in, O_RDWR |
O_BINARY));
chardev/char-pipe.c:136:    TFR(fd_out = qemu_open(filename_out, O_RDWR
| O_BINARY));
chardev/char-pipe.c:146:        TFR(fd_in = fd_out = qemu_open(filename,
O_RDWR | O_BINARY));

^ few cases, we need to check if qemu_open() is errno safe.
Maybe better to inline instead?

os-posix.c:297:        TFR(fd = qemu_open("/dev/null", O_RDWR));

^ I don't really understand this one.

net/tap-bsd.c:68:        TFR(fd = open(dname, O_RDWR));
net/tap-bsd.c:123:    TFR(fd = open(PATH_NET_TAP, O_RDWR));
net/tap-bsd.c:171:        TFR(fd = open(dname, O_RDWR));
net/tap-linux.c:49:    TFR(fd = open(PATH_NET_TUN, O_RDWR));
net/tap-solaris.c:87:    TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
net/tap-solaris.c:93:    TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
net/tap-solaris.c:107:    TFR(if_fd = open("/dev/tap", O_RDWR, 0));
net/tap-solaris.c:140:    TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
net/tap.c:625:    TFR(fd = tap_open(ifname, ifname_sz, vnet_hdr,
vnet_hdr_required,

Ditto, is tap_open() errno safe? If this code prefers to keep the
macro, we could move it to net/tap_int.h.

Reply via email to