Skip to content

Commit 8b6aa69

Browse files
Nikita Ivanovhuth
Nikita Ivanov
authored andcommitted
Refactoring: refactor TFR() macro to RETRY_ON_EINTR()
Rename macro name to more transparent one and refactor it to expression. Signed-off-by: Nikita Ivanov <[email protected]> Message-Id: <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Christian Schoenebeck <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent d88ce91 commit 8b6aa69

File tree

9 files changed

+24
-16
lines changed

9 files changed

+24
-16
lines changed

chardev/char-fd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int qmp_chardev_open_file_source(char *src, int flags, Error **errp)
198198
{
199199
int fd = -1;
200200

201-
TFR(fd = qemu_open_old(src, flags, 0666));
201+
fd = RETRY_ON_EINTR(qemu_open_old(src, flags, 0666));
202202
if (fd == -1) {
203203
error_setg_file_open(errp, errno, src);
204204
}

chardev/char-pipe.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ static void qemu_chr_open_pipe(Chardev *chr,
131131

132132
filename_in = g_strdup_printf("%s.in", filename);
133133
filename_out = g_strdup_printf("%s.out", filename);
134-
TFR(fd_in = qemu_open_old(filename_in, O_RDWR | O_BINARY));
135-
TFR(fd_out = qemu_open_old(filename_out, O_RDWR | O_BINARY));
134+
fd_in = RETRY_ON_EINTR(qemu_open_old(filename_in, O_RDWR | O_BINARY));
135+
fd_out = RETRY_ON_EINTR(qemu_open_old(filename_out, O_RDWR | O_BINARY));
136136
g_free(filename_in);
137137
g_free(filename_out);
138138
if (fd_in < 0 || fd_out < 0) {
@@ -142,7 +142,9 @@ static void qemu_chr_open_pipe(Chardev *chr,
142142
if (fd_out >= 0) {
143143
close(fd_out);
144144
}
145-
TFR(fd_in = fd_out = qemu_open_old(filename, O_RDWR | O_BINARY));
145+
fd_in = fd_out = RETRY_ON_EINTR(
146+
qemu_open_old(filename, O_RDWR | O_BINARY)
147+
);
146148
if (fd_in < 0) {
147149
error_setg_file_open(errp, errno, filename);
148150
return;

include/qemu/osdep.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,13 @@ void QEMU_ERROR("code path is reachable")
251251
#define ESHUTDOWN 4099
252252
#endif
253253

254-
#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
254+
#define RETRY_ON_EINTR(expr) \
255+
(__extension__ \
256+
({ typeof(expr) __result; \
257+
do { \
258+
__result = (expr); \
259+
} while (__result == -1 && errno == EINTR); \
260+
__result; }))
255261

256262
/* time_t may be either 32 or 64 bits depending on the host OS, and
257263
* can be either signed or unsigned, so we can't just hardcode a

net/tap-bsd.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
5656
} else {
5757
snprintf(dname, sizeof dname, "/dev/tap%d", i);
5858
}
59-
TFR(fd = open(dname, O_RDWR));
59+
fd = RETRY_ON_EINTR(open(dname, O_RDWR));
6060
if (fd >= 0) {
6161
break;
6262
}
@@ -111,7 +111,7 @@ static int tap_open_clone(char *ifname, int ifname_size, Error **errp)
111111
int fd, s, ret;
112112
struct ifreq ifr;
113113

114-
TFR(fd = open(PATH_NET_TAP, O_RDWR));
114+
fd = RETRY_ON_EINTR(open(PATH_NET_TAP, O_RDWR));
115115
if (fd < 0) {
116116
error_setg_errno(errp, errno, "could not open %s", PATH_NET_TAP);
117117
return -1;
@@ -159,7 +159,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
159159
if (ifname[0] != '\0') {
160160
char dname[100];
161161
snprintf(dname, sizeof dname, "/dev/%s", ifname);
162-
TFR(fd = open(dname, O_RDWR));
162+
fd = RETRY_ON_EINTR(open(dname, O_RDWR));
163163
if (fd < 0 && errno != ENOENT) {
164164
error_setg_errno(errp, errno, "could not open %s", dname);
165165
return -1;

net/tap-linux.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
4545
int len = sizeof(struct virtio_net_hdr);
4646
unsigned int features;
4747

48-
TFR(fd = open(PATH_NET_TUN, O_RDWR));
48+
fd = RETRY_ON_EINTR(open(PATH_NET_TUN, O_RDWR));
4949
if (fd < 0) {
5050
error_setg_errno(errp, errno, "could not open %s", PATH_NET_TUN);
5151
return -1;

net/tap-solaris.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ static int tap_alloc(char *dev, size_t dev_size, Error **errp)
8484
if( ip_fd )
8585
close(ip_fd);
8686

87-
TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
87+
ip_fd = RETRY_ON_EINTR(open("/dev/udp", O_RDWR, 0));
8888
if (ip_fd < 0) {
8989
error_setg(errp, "Can't open /dev/ip (actually /dev/udp)");
9090
return -1;
9191
}
9292

93-
TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
93+
tap_fd = RETRY_ON_EINTR(open("/dev/tap", O_RDWR, 0));
9494
if (tap_fd < 0) {
9595
error_setg(errp, "Can't open /dev/tap");
9696
return -1;
@@ -104,7 +104,7 @@ static int tap_alloc(char *dev, size_t dev_size, Error **errp)
104104
if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0)
105105
error_report("Can't assign new interface");
106106

107-
TFR(if_fd = open("/dev/tap", O_RDWR, 0));
107+
if_fd = RETRY_ON_EINTR(open("/dev/tap", O_RDWR, 0));
108108
if (if_fd < 0) {
109109
error_setg(errp, "Can't open /dev/tap (2)");
110110
return -1;
@@ -137,7 +137,7 @@ static int tap_alloc(char *dev, size_t dev_size, Error **errp)
137137
if (ioctl (ip_fd, I_PUSH, "arp") < 0)
138138
error_report("Can't push ARP module (3)");
139139
/* Open arp_fd */
140-
TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
140+
arp_fd = RETRY_ON_EINTR(open("/dev/tap", O_RDWR, 0));
141141
if (arp_fd < 0)
142142
error_report("Can't open %s", "/dev/tap");
143143

net/tap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,
650650
vnet_hdr_required = 0;
651651
}
652652

653-
TFR(fd = tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_required,
653+
fd = RETRY_ON_EINTR(tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_required,
654654
mq_required, errp));
655655
if (fd < 0) {
656656
return -1;

os-posix.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ void os_setup_post(void)
272272
error_report("not able to chdir to /: %s", strerror(errno));
273273
exit(1);
274274
}
275-
TFR(fd = qemu_open_old("/dev/null", O_RDWR));
275+
fd = RETRY_ON_EINTR(qemu_open_old("/dev/null", O_RDWR));
276276
if (fd == -1) {
277277
exit(1);
278278
}

tests/qtest/libqtest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void qtest_wait_qemu(QTestState *s)
203203
#ifndef _WIN32
204204
pid_t pid;
205205

206-
TFR(pid = waitpid(s->qemu_pid, &s->wstatus, 0));
206+
pid = RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0));
207207
assert(pid == s->qemu_pid);
208208
#else
209209
DWORD ret;

0 commit comments

Comments
 (0)