stats: Fix the compiler warnings
[osmocom-bb.git] / src / select.c
index 4f5d7ed..adf3619 100644 (file)
@@ -5,8 +5,9 @@
  * (C) 2000-2009 by Harald Welte <laforge@gnumonks.org>
  *
  *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2 
- *  as published by the Free Software Foundation
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  */
 
 #include <fcntl.h>
-#include <osmocore/select.h>
-#include <osmocore/linuxlist.h>
-#include <osmocore/timer.h>
+#include <stdio.h>
+
+#include <osmocom/core/select.h>
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/timer.h>
+
+#include "../config.h"
 
 #ifdef HAVE_SYS_SELECT_H
 
@@ -46,6 +51,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;
@@ -119,7 +134,8 @@ restart:
                /* ugly, ugly hack. If more than one filedescriptors were
                 * unregistered, they might have been consecutive and
                 * llist_for_each_entry_safe() is no longer safe */
-               if (unregistered_count > 1)
+               /* this seems to happen with the last element of the list as well */
+               if (unregistered_count >= 1)
                        goto restart;
        }
        return work;