bsc_fd: Add a build option to be able to debug fd list corruption
authorHolger Hans Peter Freyther <zecke@selfish.org>
Thu, 5 Aug 2010 22:48:43 +0000 (06:48 +0800)
committerHolger Hans Peter Freyther <zecke@selfish.org>
Thu, 5 Aug 2010 22:50:23 +0000 (06:50 +0800)
bsc_register_fd on an already registered fd can corrupt the list
in a heavy way and make the select end in an infinite loop, this
code will workaround the issue and provide a way to set a breakpoint
at the right position in the code.

configure.in
src/select.c

index c3e0061..1684aaa 100644 (file)
@@ -77,6 +77,17 @@ then
        AC_DEFINE([PANIC_INFLOOP],[1],[Use infinite loop on panic rather than fprintf/abort])
 fi
 
+AC_ARG_ENABLE(bsc_fd_check,
+       [AS_HELP_STRING(
+               [--enable-bsc-fd-check],
+               [Instrument bsc_register_fd to check that the fd is registered]
+       )],
+       [fd_check=1], [fd_check=0])
+if test "x$fd_check" = "x1"
+then
+       AC_DEFINE([BSC_FD_CHECK],[1],[Instrument the bsc_register_fd])
+fi
+
 
 AC_OUTPUT(
        libosmocore.pc
index 2f6afa7..f52b0a0 100644 (file)
@@ -19,6 +19,8 @@
  */
 
 #include <fcntl.h>
+#include <stdio.h>
+
 #include <osmocore/select.h>
 #include <osmocore/linuxlist.h>
 #include <osmocore/timer.h>
@@ -48,6 +50,16 @@ int bsc_register_fd(struct bsc_fd *fd)
        if (fd->fd > maxfd)
                maxfd = fd->fd;
 
+#ifdef BSC_FD_CHECK
+       struct bsc_fd *entry;
+       llist_for_each_entry(entry, &bsc_fds, list) {
+               if (entry == fd) {
+                       fprintf(stderr, "Adding a bsc_fd that is already in the list.\n");
+                       return 0;
+               }
+       }
+#endif
+
        llist_add_tail(&fd->list, &bsc_fds);
 
        return 0;