-
- pidfile_refresh();
-
- if (start_listener(port) < 0)
- return EXIT_FAILURE;
-
- while (!sigint) {
- struct epoll_event evts[1024];
- int n;
-
- n = epoll_wait(epollfd, evts, countof(evts), -1);
- if (n < 0) {
- if (errno != EAGAIN && errno != EINTR) {
- UNIXERR("epoll_wait");
- return EXIT_FAILURE;
- }
- continue;
- }
-
- while (--n >= 0) {
- plicyd_t *d = evts[n].data.ptr;
-
- if (d->listener) {
- int fd = accept(d->fd, NULL, 0);
- if (fd < 0) {
- if (errno != EINTR && errno != EAGAIN) {
- UNIXERR("accept");
- return EXIT_FAILURE;
- }
- continue;
- }
- thread_launch(policy_run, fd, NULL);
- }
- }
- threads_join();
- }
-
- syslog(LOG_INFO, "Stopping...");
- return EXIT_SUCCESS;