1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Support daemon(fork twice) for Darwin/OSX. v5.0.18

This commit is contained in:
winlin 2021-10-17 16:53:39 +08:00
parent 7fd5e8607c
commit 596dd8c523
3 changed files with 22 additions and 1 deletions

View file

@ -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;
}
}
}

View file

@ -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

View file

@ -9,6 +9,6 @@
#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 17
#define VERSION_REVISION 18
#endif