From: Richard Jones Date: Thu, 2 Apr 2009 19:55:41 +0000 (+0100) Subject: Correctly handle the case when select runs out of filehandles. X-Git-Tag: 0.4~44 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=56465eb694ba2077de37e66600c7bef96061cbe4;p=libguestfs.git Correctly handle the case when select runs out of filehandles. --- diff --git a/examples/df.c b/examples/df.c index 91c07d7..eed31a3 100644 --- a/examples/df.c +++ b/examples/df.c @@ -15,14 +15,13 @@ main (int argc, char *argv[]) exit (1); } - g = guestfs_create (); - if (!g) exit (1); + if (!(g = guestfs_create ())) exit (1); guestfs_set_verbose (g, 1); - guestfs_add_drive (g, argv[1]); + if (guestfs_add_drive (g, argv[1]) == -1) exit (1); - guestfs_launch (g); - guestfs_wait_ready (g); + if (guestfs_launch (g) == -1) exit (1); + if (guestfs_wait_ready (g) == -1) exit (1); diff --git a/src/guestfs.c b/src/guestfs.c index 7e88303..ea86f1b 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -899,6 +899,7 @@ static fd_set wset; static fd_set xset; static int select_init_done = 0; static int max_fd = -1; +static int nr_fds = 0; static struct handle_cb_data *handle_cb_data = NULL; static void @@ -962,6 +963,8 @@ select_add_handle (guestfs_h *g, int fd, int events, handle_cb_data[fd].cb = cb; handle_cb_data[fd].data = data; + nr_fds++; + /* Any integer >= 0 can be the handle, and this is as good as any ... */ return fd; } @@ -991,6 +994,8 @@ select_remove_handle (guestfs_h *g, int fd) sizeof (struct handle_cb_data) * (max_fd+1)); } + nr_fds--; + return 0; } @@ -1024,6 +1029,11 @@ select_main_loop_run (guestfs_h *g) old_level = level++; while (level > old_level) { + if (nr_fds == 0) { + level = old_level; + break; + } + rset2 = rset; wset2 = wset; xset2 = xset;