]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: sleep in poll()
authorQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 16 Jun 2017 20:15:31 +0000 (20:15 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 30 Nov 2017 21:18:03 +0000 (16:18 -0500)
poll won't sleep if there are no file descriptors! gotta sleep!

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
bgpd/bgp_io.c

index 78a421bd837cab6e32fcd46a6858e6050947f060..26629c1b2fc481d85f663dc2b5ecf2ddbf67cf0b 100644 (file)
@@ -61,11 +61,21 @@ void bgp_io_init()
        bgp_io_thread_started = false;
 }
 
+static int bgp_io_dummy(struct thread *thread)
+{
+       return 0;
+}
+
 void *bgp_io_start(void *arg)
 {
        struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
        fpt->master->owner = pthread_self();
 
+       // fd so we can sleep in poll()
+       int sleeper[2];
+       pipe(sleeper);
+       thread_add_read(fpt->master, &bgp_io_dummy, NULL, sleeper[0], NULL);
+
        // we definitely don't want to handle signals
        fpt->master->handle_signals = false;
 
@@ -81,28 +91,22 @@ void *bgp_io_start(void *arg)
                }
        }
 
+       close(sleeper[1]);
+       close(sleeper[0]);
+
        return NULL;
 }
 
 static int bgp_io_finish(struct thread *thread)
 {
-       /* if we ever have resources to clean up, that code should be placed in
-        * a pthread_cleanup handler and called from here */
-
-       /* set stop flag */
        atomic_store_explicit(&bgp_io_thread_run, false, memory_order_relaxed);
-
        return 0;
 }
 
 int bgp_io_stop(void **result, struct frr_pthread *fpt)
 {
-       /* schedule stop job */
        thread_add_event(fpt->master, &bgp_io_finish, NULL, 0, NULL);
-
-       /* join */
        pthread_join(fpt->thread, result);
-
        return 0;
 }
 
@@ -236,12 +240,14 @@ static int bgp_process_writes(struct thread *thread)
  */
 static int bgp_process_reads(struct thread *thread)
 {
-       static struct peer *peer; // peer to read from
-       uint16_t status;          // bgp_read status code
-       bool more = true;        // whether we got more data
-       bool fatal = false;       // whether fatal error occurred
-       bool added_pkt = false;   // whether we pushed onto ->ibuf
-       bool header_valid = true; // whether header is valid
+       /* clang-format off */
+       static struct peer *peer;       // peer to read from
+       uint16_t status;                // bgp_read status code
+       bool more = true;               // whether we got more data
+       bool fatal = false;             // whether fatal error occurred
+       bool added_pkt = false;         // whether we pushed onto ->ibuf
+       bool header_valid = true;       // whether header is valid
+       /* clang-format on */
 
        peer = THREAD_ARG(thread);