Package: microdc2 Version: 0.15.6-1 Severity: important Tags: upstream patch
After a couple of days, CPU usage is at a constant 100%. A patch was sent to the microdc2 mailing list in 2007: http://lists.gnu.org/archive/html/microdc-devel/2007-04/msg00000.html . The author bundled 4 patches into one, but I've tried to dissect them. Other than that, I haven't added a single byte to the patch. I attach it in quilt format. There have been success reports at e.g. http://bugs.gentoo.org/show_bug.cgi?id=162828#c14 using this patch. I've been using it just for a day, but it seems to be doing what it's supposed to, cleaning up orphaned file handles. -- System Information: Debian Release: wheezy/sid APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Kernel: Linux 2.6.32-5-686-bigmem (SMP w/2 CPU cores) Locale: LANG=sv_SE, LC_CTYPE=sv_SE (charmap=ISO-8859-1) (ignored: LC_ALL set to sv_SE) Shell: /bin/sh linked to /bin/dash Versions of packages microdc2 depends on: ii libbz2-1.0 1.0.5-6 high-quality block-sorting file co ii libc6 2.11.2-11 Embedded GNU C Library: Shared lib ii libreadline6 6.1-3 GNU readline and history libraries ii libxml2 2.7.8.dfsg-2 GNOME XML library microdc2 recommends no packages. microdc2 suggests no packages. -- no debconf information
Index: microdc2-0.15.6/src/main.c =================================================================== --- microdc2-0.15.6.orig/src/main.c 2011-02-11 02:36:28.353479995 +0100 +++ microdc2-0.15.6/src/main.c 2011-02-11 02:37:22.823479996 +0100 @@ -55,6 +55,15 @@ #include "common/msgq.h" #include "microdc.h" +/* Define the macro below for orphan handle checking (useful for debugging) */ +#define CHECK_ORPHAN_HANDLES + +#ifdef CHECK_ORPHAN_HANDLES +#define IF_ORPHAN_HANDLES(x) x +#else +#define IF_ORPHAN_HANDLES(x) +#endif + enum { VERSION_OPT = 256, HELP_OPT @@ -1306,34 +1315,60 @@ break; } - if (running && FD_ISSET(signal_pipe[0], &res_read_fds)) - read_signal_input(); - if (running && FD_ISSET(STDIN_FILENO, &res_read_fds)) + if (running && FD_ISSET(signal_pipe[0], &res_read_fds)) { + FD_CLR(signal_pipe[0], &res_read_fds); + read_signal_input(); + } + if (running && FD_ISSET(STDIN_FILENO, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(STDIN_FILENO, &res_read_fds)); screen_read_input(); - if (running && listen_socket >= 0 && FD_ISSET(listen_socket, &res_read_fds)) + } + if (running && listen_socket >= 0 && FD_ISSET(listen_socket, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(listen_socket, &res_read_fds)); handle_listen_connection(); - if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_read_fds)) + } + if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(hub_socket, &res_read_fds)); hub_input_available(); - if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_write_fds)) + } + if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(hub_socket, &res_write_fds)); hub_now_writable(); + } if (running) check_hub_activity(); - if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_read_fds)) + if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(search_socket, &res_read_fds)); search_input_available(); - if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_write_fds)) + } + if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(search_socket, &res_write_fds)); search_now_writable(); - if (running && FD_ISSET(lookup_request_mq->fd, &res_write_fds)) + } + if (running && FD_ISSET(lookup_request_mq->fd, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(lookup_request_mq->fd, &res_write_fds)); lookup_request_fd_writable(); - if (running && FD_ISSET(lookup_result_mq->fd, &res_read_fds)) + } + if (running && FD_ISSET(lookup_result_mq->fd, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(lookup_result_mq->fd, &res_read_fds)); lookup_result_fd_readable(); - if (running && FD_ISSET(parse_request_mq->fd, &res_write_fds)) + } + if (running && FD_ISSET(parse_request_mq->fd, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(parse_request_mq->fd, &res_write_fds)); parse_request_fd_writable(); - if (running && FD_ISSET(parse_result_mq->fd, &res_read_fds)) + } + if (running && FD_ISSET(parse_result_mq->fd, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(parse_result_mq->fd, &res_read_fds)); parse_result_fd_readable(); - if (running && FD_ISSET(update_request_mq->fd, &res_write_fds)) + } + if (running && FD_ISSET(update_request_mq->fd, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(update_request_mq->fd, &res_write_fds)); update_request_fd_writable(); - if (running && FD_ISSET(update_result_mq->fd, &res_read_fds)) + } + if (running && FD_ISSET(update_result_mq->fd, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(update_result_mq->fd, &res_read_fds)); update_result_fd_readable(); + } if (running) { HMapIterator it; @@ -1341,13 +1376,36 @@ hmap_iterator(user_conns, &it); while (running && it.has_next(&it)) { DCUserConn *uc = it.next(&it); - if (uc->put_mq != NULL && FD_ISSET(uc->put_mq->fd, &res_write_fds)) + if (uc->put_mq != NULL && FD_ISSET(uc->put_mq->fd, &res_write_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(uc->put_mq->fd, &res_write_fds)); user_request_fd_writable(uc); - if (uc->get_mq != NULL && FD_ISSET(uc->get_mq->fd, &res_read_fds)) - user_result_fd_readable(uc); + } + if (uc->get_mq != NULL && FD_ISSET(uc->get_mq->fd, &res_read_fds)) { + IF_ORPHAN_HANDLES (FD_CLR(uc->get_mq->fd, &res_read_fds)); + user_result_fd_readable(uc); + } } } - } + +#ifdef CHECK_ORPHAN_HANDLES + /* Check for orphan file handles */ + { + int i; + for (i = 0; i < FD_SETSIZE; i++) { + if (FD_ISSET (i, &res_read_fds)) { + warn(_("Orphan READ file handle %d, closing\n"), i); + close (i); + FD_CLR (i, &read_fds); + } + if (FD_ISSET (i, &res_write_fds)) { + warn(_("Orphan WRITE file handle %d, closing\n"), i); + close (i); + FD_CLR (i, &write_fds); + } + } + } +#endif + } cleanup: