diff --git a/trunk/3rdparty/st-srs/event.c b/trunk/3rdparty/st-srs/event.c index c2386b054..4fea5986e 100644 --- a/trunk/3rdparty/st-srs/event.c +++ b/trunk/3rdparty/st-srs/event.c @@ -98,6 +98,7 @@ static struct _st_kqdata { int dellist_size; int dellist_cnt; int kq; + pid_t pid; } *_st_kq_data; #ifndef ST_KQ_MIN_EVTLIST_SIZE @@ -463,6 +464,7 @@ ST_HIDDEN int _st_kq_init(void) goto cleanup_kq; } fcntl(_st_kq_data->kq, F_SETFD, FD_CLOEXEC); + _st_kq_data->pid = getpid(); /* * Allocate file descriptor data array. @@ -698,6 +700,7 @@ ST_HIDDEN void _st_kq_dispatch(void) tsp = &timeout; } + retry_kevent: /* Check for I/O operations */ nfd = kevent(_st_kq_data->kq, _st_kq_data->addlist, _st_kq_data->addlist_cnt, @@ -791,6 +794,23 @@ ST_HIDDEN void _st_kq_dispatch(void) osfd = _st_kq_data->evtlist[i].ident; _ST_KQ_REVENTS(osfd) = 0; } + } else if (nfd < 0) { + if (errno == EBADF && _st_kq_data->pid != getpid()) { + /* We probably forked, reinitialize kqueue */ + if ((_st_kq_data->kq = kqueue()) < 0) { + /* There is nothing we can do here, will retry later */ + return; + } + fcntl(_st_kq_data->kq, F_SETFD, FD_CLOEXEC); + _st_kq_data->pid = getpid(); + /* Re-register all descriptors on ioq with new kqueue */ + memset(_st_kq_data->fd_data, 0, _st_kq_data->fd_data_size * sizeof(_kq_fd_data_t)); + for (q = _ST_IOQ.next; q != &_ST_IOQ; q = q->next) { + pq = _ST_POLLQUEUE_PTR(q); + _st_kq_pollset_add(pq->pds, pq->npds); + } + goto retry_kevent; + } } } diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index e80454d63..cf8dfacd1 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 5.0 Changelog +* v5.0, 2021-10-17, Support daemon(fork twice) for Darwin/OSX [ST#23](https://github.com/ossrs/state-threads/issues/23). v5.0.18 * v5.0, 2021-10-16, DVR: support mp3 audio codec. (#2593) v5.0.17 * v5.0, 2021-10-03, OpenWRT: Disable mprotect of ST. 5.0.16 * v5.0, 2021-10-03, Actions: Create source tar lik srs-server-5.0.14.tar.gz diff --git a/trunk/src/core/srs_core_version5.hpp b/trunk/src/core/srs_core_version5.hpp index 5b26c3add..358224cca 100644 --- a/trunk/src/core/srs_core_version5.hpp +++ b/trunk/src/core/srs_core_version5.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 0 -#define VERSION_REVISION 17 +#define VERSION_REVISION 18 #endif