Commit aeb30be60a92148e38d47f79b6f566a47a8a6cbd
1 parent
6d8aa3bf
Retry interrupted open() calls (proposed by Yigael Felishman).
Linux open(2) doesn't list EINTR, but FreeBSD's open(2) does. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3043 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
24 additions
and
18 deletions
vl.c
| ... | ... | @@ -204,6 +204,8 @@ unsigned int nb_prom_envs = 0; |
| 204 | 204 | const char *prom_envs[MAX_PROM_ENVS]; |
| 205 | 205 | #endif |
| 206 | 206 | |
| 207 | +#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) | |
| 208 | + | |
| 207 | 209 | /***********************************************************/ |
| 208 | 210 | /* x86 ISA bus support */ |
| 209 | 211 | |
| ... | ... | @@ -1029,7 +1031,7 @@ static int rtc_fd; |
| 1029 | 1031 | |
| 1030 | 1032 | static int start_rtc_timer(void) |
| 1031 | 1033 | { |
| 1032 | - rtc_fd = open("/dev/rtc", O_RDONLY); | |
| 1034 | + TFR(rtc_fd = open("/dev/rtc", O_RDONLY)); | |
| 1033 | 1035 | if (rtc_fd < 0) |
| 1034 | 1036 | return -1; |
| 1035 | 1037 | if (ioctl(rtc_fd, RTC_IRQP_SET, RTC_FREQ) < 0) { |
| ... | ... | @@ -1640,7 +1642,7 @@ static CharDriverState *qemu_chr_open_file_out(const char *file_out) |
| 1640 | 1642 | { |
| 1641 | 1643 | int fd_out; |
| 1642 | 1644 | |
| 1643 | - fd_out = open(file_out, O_WRONLY | O_TRUNC | O_CREAT | O_BINARY, 0666); | |
| 1645 | + TFR(fd_out = open(file_out, O_WRONLY | O_TRUNC | O_CREAT | O_BINARY, 0666)); | |
| 1644 | 1646 | if (fd_out < 0) |
| 1645 | 1647 | return NULL; |
| 1646 | 1648 | return qemu_chr_open_fd(-1, fd_out); |
| ... | ... | @@ -1653,14 +1655,14 @@ static CharDriverState *qemu_chr_open_pipe(const char *filename) |
| 1653 | 1655 | |
| 1654 | 1656 | snprintf(filename_in, 256, "%s.in", filename); |
| 1655 | 1657 | snprintf(filename_out, 256, "%s.out", filename); |
| 1656 | - fd_in = open(filename_in, O_RDWR | O_BINARY); | |
| 1657 | - fd_out = open(filename_out, O_RDWR | O_BINARY); | |
| 1658 | + TFR(fd_in = open(filename_in, O_RDWR | O_BINARY)); | |
| 1659 | + TFR(fd_out = open(filename_out, O_RDWR | O_BINARY)); | |
| 1658 | 1660 | if (fd_in < 0 || fd_out < 0) { |
| 1659 | 1661 | if (fd_in >= 0) |
| 1660 | 1662 | close(fd_in); |
| 1661 | 1663 | if (fd_out >= 0) |
| 1662 | 1664 | close(fd_out); |
| 1663 | - fd_in = fd_out = open(filename, O_RDWR | O_BINARY); | |
| 1665 | + TFR(fd_in = fd_out = open(filename, O_RDWR | O_BINARY)); | |
| 1664 | 1666 | if (fd_in < 0) |
| 1665 | 1667 | return NULL; |
| 1666 | 1668 | } |
| ... | ... | @@ -1911,14 +1913,14 @@ static CharDriverState *qemu_chr_open_tty(const char *filename) |
| 1911 | 1913 | CharDriverState *chr; |
| 1912 | 1914 | int fd; |
| 1913 | 1915 | |
| 1914 | - fd = open(filename, O_RDWR | O_NONBLOCK); | |
| 1915 | - if (fd < 0) | |
| 1916 | - return NULL; | |
| 1916 | + TFR(fd = open(filename, O_RDWR | O_NONBLOCK)); | |
| 1917 | 1917 | fcntl(fd, F_SETFL, O_NONBLOCK); |
| 1918 | 1918 | tty_serial_init(fd, 115200, 'N', 8, 1); |
| 1919 | 1919 | chr = qemu_chr_open_fd(fd, fd); |
| 1920 | - if (!chr) | |
| 1920 | + if (!chr) { | |
| 1921 | + close(fd); | |
| 1921 | 1922 | return NULL; |
| 1923 | + } | |
| 1922 | 1924 | chr->chr_ioctl = tty_serial_ioctl; |
| 1923 | 1925 | qemu_chr_reset(chr); |
| 1924 | 1926 | return chr; |
| ... | ... | @@ -2041,7 +2043,7 @@ static CharDriverState *qemu_chr_open_pp(const char *filename) |
| 2041 | 2043 | ParallelCharDriver *drv; |
| 2042 | 2044 | int fd; |
| 2043 | 2045 | |
| 2044 | - fd = open(filename, O_RDWR); | |
| 2046 | + TFR(fd = open(filename, O_RDWR)); | |
| 2045 | 2047 | if (fd < 0) |
| 2046 | 2048 | return NULL; |
| 2047 | 2049 | |
| ... | ... | @@ -3463,7 +3465,7 @@ static int tap_open(char *ifname, int ifname_size) |
| 3463 | 3465 | char *dev; |
| 3464 | 3466 | struct stat s; |
| 3465 | 3467 | |
| 3466 | - fd = open("/dev/tap", O_RDWR); | |
| 3468 | + TFR(fd = open("/dev/tap", O_RDWR)); | |
| 3467 | 3469 | if (fd < 0) { |
| 3468 | 3470 | fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n"); |
| 3469 | 3471 | return -1; |
| ... | ... | @@ -3507,12 +3509,14 @@ int tap_alloc(char *dev) |
| 3507 | 3509 | if( ip_fd ) |
| 3508 | 3510 | close(ip_fd); |
| 3509 | 3511 | |
| 3510 | - if( (ip_fd = open("/dev/udp", O_RDWR, 0)) < 0){ | |
| 3512 | + TFR(ip_fd = open("/dev/udp", O_RDWR, 0)); | |
| 3513 | + if (ip_fd < 0) { | |
| 3511 | 3514 | syslog(LOG_ERR, "Can't open /dev/ip (actually /dev/udp)"); |
| 3512 | 3515 | return -1; |
| 3513 | 3516 | } |
| 3514 | 3517 | |
| 3515 | - if( (tap_fd = open("/dev/tap", O_RDWR, 0)) < 0){ | |
| 3518 | + TFR(tap_fd = open("/dev/tap", O_RDWR, 0)); | |
| 3519 | + if (tap_fd < 0) { | |
| 3516 | 3520 | syslog(LOG_ERR, "Can't open /dev/tap"); |
| 3517 | 3521 | return -1; |
| 3518 | 3522 | } |
| ... | ... | @@ -3525,7 +3529,8 @@ int tap_alloc(char *dev) |
| 3525 | 3529 | if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0) |
| 3526 | 3530 | syslog (LOG_ERR, "Can't assign new interface"); |
| 3527 | 3531 | |
| 3528 | - if( (if_fd = open("/dev/tap", O_RDWR, 0)) < 0){ | |
| 3532 | + TFR(if_fd = open("/dev/tap", O_RDWR, 0)); | |
| 3533 | + if (if_fd < 0) { | |
| 3529 | 3534 | syslog(LOG_ERR, "Can't open /dev/tap (2)"); |
| 3530 | 3535 | return -1; |
| 3531 | 3536 | } |
| ... | ... | @@ -3557,7 +3562,8 @@ int tap_alloc(char *dev) |
| 3557 | 3562 | if (ioctl (ip_fd, I_PUSH, "arp") < 0) |
| 3558 | 3563 | syslog (LOG_ERR, "Can't push ARP module (3)\n"); |
| 3559 | 3564 | /* Open arp_fd */ |
| 3560 | - if ((arp_fd = open ("/dev/tap", O_RDWR, 0)) < 0) | |
| 3565 | + TFR(arp_fd = open ("/dev/tap", O_RDWR, 0)); | |
| 3566 | + if (arp_fd < 0) | |
| 3561 | 3567 | syslog (LOG_ERR, "Can't open %s\n", "/dev/tap"); |
| 3562 | 3568 | |
| 3563 | 3569 | /* Set ifname to arp */ |
| ... | ... | @@ -3613,7 +3619,7 @@ static int tap_open(char *ifname, int ifname_size) |
| 3613 | 3619 | struct ifreq ifr; |
| 3614 | 3620 | int fd, ret; |
| 3615 | 3621 | |
| 3616 | - fd = open("/dev/net/tun", O_RDWR); | |
| 3622 | + TFR(fd = open("/dev/net/tun", O_RDWR)); | |
| 3617 | 3623 | if (fd < 0) { |
| 3618 | 3624 | fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n"); |
| 3619 | 3625 | return -1; |
| ... | ... | @@ -3649,7 +3655,7 @@ static int net_tap_init(VLANState *vlan, const char *ifname1, |
| 3649 | 3655 | pstrcpy(ifname, sizeof(ifname), ifname1); |
| 3650 | 3656 | else |
| 3651 | 3657 | ifname[0] = '\0'; |
| 3652 | - fd = tap_open(ifname, sizeof(ifname)); | |
| 3658 | + TFR(fd = tap_open(ifname, sizeof(ifname))); | |
| 3653 | 3659 | if (fd < 0) |
| 3654 | 3660 | return -1; |
| 3655 | 3661 | |
| ... | ... | @@ -8038,7 +8044,7 @@ int main(int argc, char **argv) |
| 8038 | 8044 | if (len != 1) |
| 8039 | 8045 | exit(1); |
| 8040 | 8046 | |
| 8041 | - fd = open("/dev/null", O_RDWR); | |
| 8047 | + TFR(fd = open("/dev/null", O_RDWR)); | |
| 8042 | 8048 | if (fd == -1) |
| 8043 | 8049 | exit(1); |
| 8044 | 8050 | ... | ... |