@@ -1678,6 +1678,7 @@ static int SwapLists(WOLFSSL_CRL* crl)
16781678#include <sys/time.h>
16791679#include <fcntl.h>
16801680#include <unistd.h>
1681+ #include <errno.h>
16811682
16821683#ifdef __MACH__
16831684 #define XEVENT_MODE O_EVTONLY
@@ -1686,6 +1687,7 @@ static int SwapLists(WOLFSSL_CRL* crl)
16861687#endif
16871688
16881689
1690+
16891691/* we need a unique kqueue user filter fd for crl in case user is doing custom
16901692 * events too */
16911693#ifndef CRL_CUSTOM_FD
@@ -1729,6 +1731,7 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
17291731 SignalSetup (crl , MONITOR_SETUP_E );
17301732 return NULL ;
17311733 }
1734+ wc_set_cloexec (crl -> mfd );
17321735
17331736 /* listen for custom shutdown event */
17341737 EV_SET (& change , CRL_CUSTOM_FD , EVFILT_USER , EV_ADD , 0 , 0 , NULL );
@@ -1743,7 +1746,7 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
17431746 fDER = -1 ;
17441747
17451748 if (crl -> monitors [0 ].path ) {
1746- fPEM = open (crl -> monitors [0 ].path , XEVENT_MODE );
1749+ fPEM = wc_open_cloexec (crl -> monitors [0 ].path , XEVENT_MODE );
17471750 if (fPEM == -1 ) {
17481751 WOLFSSL_MSG ("PEM event dir open failed" );
17491752 SignalSetup (crl , MONITOR_SETUP_E );
@@ -1753,7 +1756,7 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
17531756 }
17541757
17551758 if (crl -> monitors [1 ].path ) {
1756- fDER = open (crl -> monitors [1 ].path , XEVENT_MODE );
1759+ fDER = wc_open_cloexec (crl -> monitors [1 ].path , XEVENT_MODE );
17571760 if (fDER == -1 ) {
17581761 WOLFSSL_MSG ("DER event dir open failed" );
17591762 if (fPEM != -1 )
@@ -1820,7 +1823,8 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
18201823#include <sys/inotify.h>
18211824#include <sys/eventfd.h>
18221825#include <unistd.h>
1823-
1826+ #include <fcntl.h>
1827+ #include <errno.h>
18241828
18251829#ifndef max
18261830 static WC_INLINE int max (int a , int b )
@@ -1855,14 +1859,32 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
18551859
18561860 WOLFSSL_ENTER ("DoMonitor" );
18571861
1862+ #ifdef EFD_CLOEXEC
1863+ crl -> mfd = eventfd (0 , EFD_CLOEXEC ); /* our custom shutdown event */
1864+ if (crl -> mfd < 0 && (errno == ENOSYS || errno == EINVAL )) {
1865+ crl -> mfd = eventfd (0 , 0 );
1866+ wc_set_cloexec (crl -> mfd );
1867+ }
1868+ #else
18581869 crl -> mfd = eventfd (0 , 0 ); /* our custom shutdown event */
1870+ wc_set_cloexec (crl -> mfd );
1871+ #endif
18591872 if (crl -> mfd < 0 ) {
18601873 WOLFSSL_MSG ("eventfd failed" );
18611874 SignalSetup (crl , MONITOR_SETUP_E );
18621875 return NULL ;
18631876 }
18641877
1878+ #ifdef IN_CLOEXEC
1879+ notifyFd = inotify_init1 (IN_CLOEXEC );
1880+ if (notifyFd < 0 && (errno == ENOSYS || errno == EINVAL )) {
1881+ notifyFd = inotify_init ();
1882+ wc_set_cloexec (notifyFd );
1883+ }
1884+ #else
18651885 notifyFd = inotify_init ();
1886+ wc_set_cloexec (notifyFd );
1887+ #endif
18661888 if (notifyFd < 0 ) {
18671889 WOLFSSL_MSG ("inotify failed" );
18681890 (void )close (crl -> mfd );
0 commit comments