You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.2 KiB

  1. --- a/lib/thread.c
  2. +++ b/lib/thread.c
  3. @@ -830,13 +830,9 @@ static void thread_free(struct thread_ma
  4. XFREE(MTYPE_THREAD, thread);
  5. }
  6. -static int fd_poll(struct thread_master *m, const struct timeval *timer_wait,
  7. - bool *eintr_p)
  8. +static int fd_poll(struct thread_master *m, struct pollfd *pfds, nfds_t pfdsize,
  9. + nfds_t count, const struct timeval *timer_wait)
  10. {
  11. - sigset_t origsigs;
  12. - unsigned char trash[64];
  13. - nfds_t count = m->handler.copycount;
  14. -
  15. /*
  16. * If timer_wait is null here, that means poll() should block
  17. * indefinitely, unless the thread_master has overridden it by setting
  18. @@ -867,58 +863,15 @@ static int fd_poll(struct thread_master
  19. rcu_assert_read_unlocked();
  20. /* add poll pipe poker */
  21. - assert(count + 1 < m->handler.pfdsize);
  22. - m->handler.copy[count].fd = m->io_pipe[0];
  23. - m->handler.copy[count].events = POLLIN;
  24. - m->handler.copy[count].revents = 0x00;
  25. -
  26. - /* We need to deal with a signal-handling race here: we
  27. - * don't want to miss a crucial signal, such as SIGTERM or SIGINT,
  28. - * that may arrive just before we enter poll(). We will block the
  29. - * key signals, then check whether any have arrived - if so, we return
  30. - * before calling poll(). If not, we'll re-enable the signals
  31. - * in the ppoll() call.
  32. - */
  33. -
  34. - sigemptyset(&origsigs);
  35. - if (m->handle_signals) {
  36. - /* Main pthread that handles the app signals */
  37. - if (frr_sigevent_check(&origsigs)) {
  38. - /* Signal to process - restore signal mask and return */
  39. - pthread_sigmask(SIG_SETMASK, &origsigs, NULL);
  40. - num = -1;
  41. - *eintr_p = true;
  42. - goto done;
  43. - }
  44. - } else {
  45. - /* Don't make any changes for the non-main pthreads */
  46. - pthread_sigmask(SIG_SETMASK, NULL, &origsigs);
  47. - }
  48. + assert(count + 1 < pfdsize);
  49. + pfds[count].fd = m->io_pipe[0];
  50. + pfds[count].events = POLLIN;
  51. + pfds[count].revents = 0x00;
  52. -#if defined(HAVE_PPOLL)
  53. - struct timespec ts, *tsp;
  54. + num = poll(pfds, count + 1, timeout);
  55. - if (timeout >= 0) {
  56. - ts.tv_sec = timeout / 1000;
  57. - ts.tv_nsec = (timeout % 1000) * 1000000;
  58. - tsp = &ts;
  59. - } else
  60. - tsp = NULL;
  61. -
  62. - num = ppoll(m->handler.copy, count + 1, tsp, &origsigs);
  63. - pthread_sigmask(SIG_SETMASK, &origsigs, NULL);
  64. -#else
  65. - /* Not ideal - there is a race after we restore the signal mask */
  66. - pthread_sigmask(SIG_SETMASK, &origsigs, NULL);
  67. - num = poll(m->handler.copy, count + 1, timeout);
  68. -#endif
  69. -
  70. -done:
  71. -
  72. - if (num < 0 && errno == EINTR)
  73. - *eintr_p = true;
  74. -
  75. - if (num > 0 && m->handler.copy[count].revents != 0 && num--)
  76. + unsigned char trash[64];
  77. + if (num > 0 && pfds[count].revents != 0 && num--)
  78. while (read(m->io_pipe[0], &trash, sizeof(trash)) > 0)
  79. ;
  80. @@ -1718,7 +1671,7 @@ struct thread *thread_fetch(struct threa
  81. struct timeval zerotime = {0, 0};
  82. struct timeval tv;
  83. struct timeval *tw = NULL;
  84. - bool eintr_p = false;
  85. +
  86. int num = 0;
  87. do {
  88. @@ -1794,14 +1747,14 @@ struct thread *thread_fetch(struct threa
  89. pthread_mutex_unlock(&m->mtx);
  90. {
  91. - eintr_p = false;
  92. - num = fd_poll(m, tw, &eintr_p);
  93. + num = fd_poll(m, m->handler.copy, m->handler.pfdsize,
  94. + m->handler.copycount, tw);
  95. }
  96. pthread_mutex_lock(&m->mtx);
  97. /* Handle any errors received in poll() */
  98. if (num < 0) {
  99. - if (eintr_p) {
  100. + if (errno == EINTR) {
  101. pthread_mutex_unlock(&m->mtx);
  102. /* loop around to signal handler */
  103. continue;