@@ -1659,6 +1659,7 @@ static int SwapLists(WOLFSSL_CRL* crl)
16591659#include <sys/time.h>
16601660#include <fcntl.h>
16611661#include <unistd.h>
1662+ #include <errno.h>
16621663
16631664#ifdef __MACH__
16641665 #define XEVENT_MODE O_EVTONLY
@@ -1667,6 +1668,7 @@ static int SwapLists(WOLFSSL_CRL* crl)
16671668#endif
16681669
16691670
1671+
16701672/* we need a unique kqueue user filter fd for crl in case user is doing custom
16711673 * events too */
16721674#ifndef CRL_CUSTOM_FD
@@ -1710,6 +1712,7 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
17101712 SignalSetup (crl , MONITOR_SETUP_E );
17111713 return NULL ;
17121714 }
1715+ wc_set_cloexec (crl -> mfd );
17131716
17141717 /* listen for custom shutdown event */
17151718 EV_SET (& change , CRL_CUSTOM_FD , EVFILT_USER , EV_ADD , 0 , 0 , NULL );
@@ -1724,7 +1727,7 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
17241727 fDER = -1 ;
17251728
17261729 if (crl -> monitors [0 ].path ) {
1727- fPEM = open (crl -> monitors [0 ].path , XEVENT_MODE );
1730+ fPEM = wc_open_cloexec (crl -> monitors [0 ].path , XEVENT_MODE );
17281731 if (fPEM == -1 ) {
17291732 WOLFSSL_MSG ("PEM event dir open failed" );
17301733 SignalSetup (crl , MONITOR_SETUP_E );
@@ -1734,7 +1737,7 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
17341737 }
17351738
17361739 if (crl -> monitors [1 ].path ) {
1737- fDER = open (crl -> monitors [1 ].path , XEVENT_MODE );
1740+ fDER = wc_open_cloexec (crl -> monitors [1 ].path , XEVENT_MODE );
17381741 if (fDER == -1 ) {
17391742 WOLFSSL_MSG ("DER event dir open failed" );
17401743 if (fPEM != -1 )
@@ -1801,6 +1804,13 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
18011804#include <sys/inotify.h>
18021805#include <sys/eventfd.h>
18031806#include <unistd.h>
1807+ #include <fcntl.h>
1808+ #include <errno.h>
1809+
1810+ /* Fall back to no-op if EFD_CLOEXEC is unavailable. */
1811+ #ifndef EFD_CLOEXEC
1812+ #define EFD_CLOEXEC 0
1813+ #endif
18041814
18051815
18061816#ifndef max
@@ -1836,14 +1846,29 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
18361846
18371847 WOLFSSL_ENTER ("DoMonitor" );
18381848
1839- crl -> mfd = eventfd (0 , 0 ); /* our custom shutdown event */
1849+ crl -> mfd = eventfd (0 , EFD_CLOEXEC ); /* our custom shutdown event */
1850+ #ifdef FD_CLOEXEC
1851+ if (crl -> mfd < 0 && errno == EINVAL ) {
1852+ crl -> mfd = eventfd (0 , 0 );
1853+ wc_set_cloexec (crl -> mfd );
1854+ }
1855+ #endif
18401856 if (crl -> mfd < 0 ) {
18411857 WOLFSSL_MSG ("eventfd failed" );
18421858 SignalSetup (crl , MONITOR_SETUP_E );
18431859 return NULL ;
18441860 }
18451861
1862+ #ifdef IN_CLOEXEC
1863+ notifyFd = inotify_init1 (IN_CLOEXEC );
1864+ if (notifyFd < 0 && (errno == ENOSYS || errno == EINVAL )) {
1865+ notifyFd = inotify_init ();
1866+ wc_set_cloexec (notifyFd );
1867+ }
1868+ #else
18461869 notifyFd = inotify_init ();
1870+ wc_set_cloexec (notifyFd );
1871+ #endif
18471872 if (notifyFd < 0 ) {
18481873 WOLFSSL_MSG ("inotify failed" );
18491874 (void )close (crl -> mfd );
0 commit comments