/* OS X monitoring */ static void* DoMonitor(void* arg) { int fPEM, fDER, kq; struct kevent change; CYASSL_CRL* crl = (CYASSL_CRL*)arg; CYASSL_ENTER("DoMonitor"); kq = kqueue(); if (kq == -1) { CYASSL_MSG("kqueue failed"); return NULL; } fPEM = -1; fDER = -1; if (crl->monitors[0].path) { fPEM = open(crl->monitors[0].path, XEVENT_MODE); if (fPEM == -1) { CYASSL_MSG("PEM event dir open failed"); return NULL; } } if (crl->monitors[1].path) { fDER = open(crl->monitors[1].path, XEVENT_MODE); if (fDER == -1) { CYASSL_MSG("DER event dir open failed"); return NULL; } } if (fPEM != -1) EV_SET(&change, fPEM, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_ONESHOT, NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB, 0, 0); if (fDER != -1) EV_SET(&change, fDER, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_ONESHOT, NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB, 0, 0); for (;;) { struct kevent event; int numEvents = kevent(kq, &change, 1, &event, 1, NULL); CYASSL_MSG("Got kevent"); if (numEvents == -1) { CYASSL_MSG("kevent problem, continue"); continue; } if (SwapLists(crl) < 0) { CYASSL_MSG("SwapLists problem, continue"); } } return NULL; }
/* linux monitoring */ static void* DoMonitor(void* arg) { int notifyFd; int wd; CYASSL_CRL* crl = (CYASSL_CRL*)arg; CYASSL_ENTER("DoMonitor"); notifyFd = inotify_init(); if (notifyFd < 0) { CYASSL_MSG("inotify failed"); return NULL; } if (crl->monitors[0].path) { wd = inotify_add_watch(notifyFd, crl->monitors[0].path, IN_CLOSE_WRITE | IN_DELETE); if (wd < 0) { CYASSL_MSG("PEM notify add watch failed"); return NULL; } } if (crl->monitors[1].path) { wd = inotify_add_watch(notifyFd, crl->monitors[1].path, IN_CLOSE_WRITE | IN_DELETE); if (wd < 0) { CYASSL_MSG("DER notify add watch failed"); return NULL; } } for (;;) { char buff[8192]; int length = read(notifyFd, buff, sizeof(buff)); CYASSL_MSG("Got notify event"); if (length < 0) { CYASSL_MSG("notify read problem, continue"); continue; } if (SwapLists(crl) < 0) { CYASSL_MSG("SwapLists problem, continue"); } } return NULL; }
/* linux monitoring */ static void* DoMonitor(void* arg) { int notifyFd; int wd = -1; WOLFSSL_CRL* crl = (WOLFSSL_CRL*)arg; #ifdef WOLFSSL_SMALL_STACK char* buff; #else char buff[8192]; #endif WOLFSSL_ENTER("DoMonitor"); crl->mfd = eventfd(0, 0); /* our custom shutdown event */ if (crl->mfd < 0) { WOLFSSL_MSG("eventfd failed"); SignalSetup(crl, MONITOR_SETUP_E); return NULL; } notifyFd = inotify_init(); if (notifyFd < 0) { WOLFSSL_MSG("inotify failed"); close(crl->mfd); SignalSetup(crl, MONITOR_SETUP_E); return NULL; } if (crl->monitors[0].path) { wd = inotify_add_watch(notifyFd, crl->monitors[0].path, IN_CLOSE_WRITE | IN_DELETE); if (wd < 0) { WOLFSSL_MSG("PEM notify add watch failed"); close(crl->mfd); close(notifyFd); SignalSetup(crl, MONITOR_SETUP_E); return NULL; } } if (crl->monitors[1].path) { wd = inotify_add_watch(notifyFd, crl->monitors[1].path, IN_CLOSE_WRITE | IN_DELETE); if (wd < 0) { WOLFSSL_MSG("DER notify add watch failed"); close(crl->mfd); close(notifyFd); SignalSetup(crl, MONITOR_SETUP_E); return NULL; } } #ifdef WOLFSSL_SMALL_STACK buff = (char*)XMALLOC(8192, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (buff == NULL) return NULL; #endif /* signal to calling thread we're setup */ if (SignalSetup(crl, 1) != 0) { #ifdef WOLFSSL_SMALL_STACK XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif if (wd > 0) inotify_rm_watch(notifyFd, wd); close(crl->mfd); close(notifyFd); return NULL; } for (;;) { fd_set readfds; int result; int length; FD_ZERO(&readfds); FD_SET(notifyFd, &readfds); FD_SET(crl->mfd, &readfds); result = select(max(notifyFd, crl->mfd) + 1, &readfds, NULL, NULL,NULL); WOLFSSL_MSG("Got notify event"); if (result < 0) { WOLFSSL_MSG("select problem, continue"); continue; } if (FD_ISSET(crl->mfd, &readfds)) { WOLFSSL_MSG("got custom shutdown event, breaking out"); break; } length = (int) read(notifyFd, buff, 8192); if (length < 0) { WOLFSSL_MSG("notify read problem, continue"); continue; } if (SwapLists(crl) < 0) { WOLFSSL_MSG("SwapLists problem, continue"); } } #ifdef WOLFSSL_SMALL_STACK XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif if (wd > 0) inotify_rm_watch(notifyFd, wd); close(crl->mfd); close(notifyFd); return NULL; }
/* OS X monitoring */ static void* DoMonitor(void* arg) { int fPEM, fDER; struct kevent change; WOLFSSL_CRL* crl = (WOLFSSL_CRL*)arg; WOLFSSL_ENTER("DoMonitor"); crl->mfd = kqueue(); if (crl->mfd == -1) { WOLFSSL_MSG("kqueue failed"); SignalSetup(crl, MONITOR_SETUP_E); return NULL; } /* listen for custom shutdown event */ EV_SET(&change, CRL_CUSTOM_FD, EVFILT_USER, EV_ADD, 0, 0, NULL); if (kevent(crl->mfd, &change, 1, NULL, 0, NULL) < 0) { WOLFSSL_MSG("kevent monitor customer event failed"); SignalSetup(crl, MONITOR_SETUP_E); close(crl->mfd); return NULL; } fPEM = -1; fDER = -1; if (crl->monitors[0].path) { fPEM = open(crl->monitors[0].path, XEVENT_MODE); if (fPEM == -1) { WOLFSSL_MSG("PEM event dir open failed"); SignalSetup(crl, MONITOR_SETUP_E); close(crl->mfd); return NULL; } } if (crl->monitors[1].path) { fDER = open(crl->monitors[1].path, XEVENT_MODE); if (fDER == -1) { WOLFSSL_MSG("DER event dir open failed"); if (fPEM != -1) close(fPEM); close(crl->mfd); SignalSetup(crl, MONITOR_SETUP_E); return NULL; } } if (fPEM != -1) EV_SET(&change, fPEM, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_ONESHOT, NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB, 0, 0); if (fDER != -1) EV_SET(&change, fDER, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_ONESHOT, NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_ATTRIB, 0, 0); /* signal to calling thread we're setup */ if (SignalSetup(crl, 1) != 0) { if (fPEM != -1) close(fPEM); if (fDER != -1) close(fDER); close(crl->mfd); return NULL; } for (;;) { struct kevent event; int numEvents = kevent(crl->mfd, &change, 1, &event, 1, NULL); WOLFSSL_MSG("Got kevent"); if (numEvents == -1) { WOLFSSL_MSG("kevent problem, continue"); continue; } if (event.filter == EVFILT_USER) { WOLFSSL_MSG("Got user shutdown event, breaking out"); break; } if (SwapLists(crl) < 0) { WOLFSSL_MSG("SwapLists problem, continue"); } } if (fPEM != -1) close(fPEM); if (fDER != -1) close(fDER); close(crl->mfd); return NULL; }
/* linux monitoring */ static void* DoMonitor(void* arg) { int notifyFd; int wd; CYASSL_CRL* crl = (CYASSL_CRL*)arg; CYASSL_ENTER("DoMonitor"); crl->mfd = eventfd(0, 0); /* our custom shutdown event */ if (crl->mfd < 0) { CYASSL_MSG("eventfd failed"); return NULL; } notifyFd = inotify_init(); if (notifyFd < 0) { CYASSL_MSG("inotify failed"); close(crl->mfd); return NULL; } if (crl->monitors[0].path) { wd = inotify_add_watch(notifyFd, crl->monitors[0].path, IN_CLOSE_WRITE | IN_DELETE); if (wd < 0) { CYASSL_MSG("PEM notify add watch failed"); close(crl->mfd); close(notifyFd); return NULL; } } if (crl->monitors[1].path) { wd = inotify_add_watch(notifyFd, crl->monitors[1].path, IN_CLOSE_WRITE | IN_DELETE); if (wd < 0) { CYASSL_MSG("DER notify add watch failed"); close(crl->mfd); close(notifyFd); return NULL; } } for (;;) { fd_set readfds; char buff[8192]; int result, length; FD_ZERO(&readfds); FD_SET(notifyFd, &readfds); FD_SET(crl->mfd, &readfds); result = select(max(notifyFd, crl->mfd) + 1, &readfds, NULL, NULL,NULL); CYASSL_MSG("Got notify event"); if (result < 0) { CYASSL_MSG("select problem, continue"); continue; } if (FD_ISSET(crl->mfd, &readfds)) { CYASSL_MSG("got custom shutdown event, breaking out"); break; } length = read(notifyFd, buff, sizeof(buff)); if (length < 0) { CYASSL_MSG("notify read problem, continue"); continue; } if (SwapLists(crl) < 0) { CYASSL_MSG("SwapLists problem, continue"); } } inotify_rm_watch(notifyFd, wd); close(crl->mfd); close(notifyFd); return NULL; }