Commit 7183b4b47a008577f9488bc236d67480a9079cdc
1 parent
c96f1a48
Improve error reporting in init_timer_alarm
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5634 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
42 additions
and
16 deletions
vl.c
| ... | ... | @@ -1374,6 +1374,21 @@ static uint64_t qemu_next_deadline_dyntick(void) |
| 1374 | 1374 | |
| 1375 | 1375 | #ifndef _WIN32 |
| 1376 | 1376 | |
| 1377 | +/* Sets a specific flag */ | |
| 1378 | +static int fcntl_setfl(int fd, int flag) | |
| 1379 | +{ | |
| 1380 | + int flags; | |
| 1381 | + | |
| 1382 | + flags = fcntl(fd, F_GETFL); | |
| 1383 | + if (flags == -1) | |
| 1384 | + return -errno; | |
| 1385 | + | |
| 1386 | + if (fcntl(fd, F_SETFL, flags | flag) == -1) | |
| 1387 | + return -errno; | |
| 1388 | + | |
| 1389 | + return 0; | |
| 1390 | +} | |
| 1391 | + | |
| 1377 | 1392 | #if defined(__linux__) |
| 1378 | 1393 | |
| 1379 | 1394 | #define RTC_FREQ 1024 |
| ... | ... | @@ -1388,7 +1403,7 @@ static void enable_sigio_timer(int fd) |
| 1388 | 1403 | act.sa_handler = host_alarm_handler; |
| 1389 | 1404 | |
| 1390 | 1405 | sigaction(SIGIO, &act, NULL); |
| 1391 | - fcntl(fd, F_SETFL, O_ASYNC); | |
| 1406 | + fcntl_setfl(fd, O_ASYNC); | |
| 1392 | 1407 | fcntl(fd, F_SETOWN, getpid()); |
| 1393 | 1408 | } |
| 1394 | 1409 | |
| ... | ... | @@ -1674,22 +1689,24 @@ static void win32_rearm_timer(struct qemu_alarm_timer *t) |
| 1674 | 1689 | |
| 1675 | 1690 | #endif /* _WIN32 */ |
| 1676 | 1691 | |
| 1677 | -static void init_timer_alarm(void) | |
| 1692 | +static int init_timer_alarm(void) | |
| 1678 | 1693 | { |
| 1679 | 1694 | struct qemu_alarm_timer *t = NULL; |
| 1680 | 1695 | int i, err = -1; |
| 1681 | 1696 | int fds[2]; |
| 1682 | 1697 | |
| 1683 | - if (pipe(fds) < 0) { | |
| 1684 | - fail: | |
| 1685 | - perror("creating timer pipe"); | |
| 1686 | - exit(1); | |
| 1687 | - } | |
| 1688 | - for (i = 0; i < 2; i++) { | |
| 1689 | - int flags = fcntl(fds[i], F_GETFL); | |
| 1690 | - if (flags == -1 || fcntl(fds[i], F_SETFL, flags | O_NONBLOCK)) | |
| 1691 | - goto fail; | |
| 1692 | - } | |
| 1698 | + err = pipe(fds); | |
| 1699 | + if (err == -1) | |
| 1700 | + return -errno; | |
| 1701 | + | |
| 1702 | + err = fcntl_setfl(fds[0], O_NONBLOCK); | |
| 1703 | + if (err < 0) | |
| 1704 | + goto fail; | |
| 1705 | + | |
| 1706 | + err = fcntl_setfl(fds[1], O_NONBLOCK); | |
| 1707 | + if (err < 0) | |
| 1708 | + goto fail; | |
| 1709 | + | |
| 1693 | 1710 | alarm_timer_rfd = fds[0]; |
| 1694 | 1711 | alarm_timer_wfd = fds[1]; |
| 1695 | 1712 | |
| ... | ... | @@ -1702,12 +1719,18 @@ static void init_timer_alarm(void) |
| 1702 | 1719 | } |
| 1703 | 1720 | |
| 1704 | 1721 | if (err) { |
| 1705 | - fprintf(stderr, "Unable to find any suitable alarm timer.\n"); | |
| 1706 | - fprintf(stderr, "Terminating\n"); | |
| 1707 | - exit(1); | |
| 1722 | + err = -ENOENT; | |
| 1723 | + goto fail; | |
| 1708 | 1724 | } |
| 1709 | 1725 | |
| 1710 | 1726 | alarm_timer = t; |
| 1727 | + | |
| 1728 | + return 1; | |
| 1729 | + | |
| 1730 | +fail: | |
| 1731 | + close(fds[0]); | |
| 1732 | + close(fds[1]); | |
| 1733 | + return err; | |
| 1711 | 1734 | } |
| 1712 | 1735 | |
| 1713 | 1736 | static void quit_timers(void) |
| ... | ... | @@ -6075,7 +6098,10 @@ int main(int argc, char **argv) |
| 6075 | 6098 | setvbuf(stdout, NULL, _IOLBF, 0); |
| 6076 | 6099 | |
| 6077 | 6100 | init_timers(); |
| 6078 | - init_timer_alarm(); | |
| 6101 | + if (init_timer_alarm() < 0) { | |
| 6102 | + fprintf(stderr, "could not initialize alarm timer\n"); | |
| 6103 | + exit(1); | |
| 6104 | + } | |
| 6079 | 6105 | if (use_icount && icount_time_shift < 0) { |
| 6080 | 6106 | use_icount = 2; |
| 6081 | 6107 | /* 125MIPS seems a reasonable initial guess at the guest speed. | ... | ... |