Răsfoiți Sursa

fix close() checks

Christian Grothoff 6 ani în urmă
părinte
comite
83a86be948
5 a modificat fișierele cu 18 adăugiri și 10 ștergeri
  1. 4 0
      ChangeLog
  2. 3 3
      src/lib/internal.h
  3. 4 2
      src/lib/mhd_itc.h
  4. 3 3
      src/microhttpd/internal.h
  5. 4 2
      src/microhttpd/mhd_itc.h

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+Mon 08 Apr 2019 03:06:05 PM CEST
+	Fix close() checks as suggested by MK on the mailinglist
+        (#3926). -MK/CG
+
 Tue Jan  8 02:57:21 BRT 2019
 	Added minimal example for how to compress HTTP response. -SC
 

+ 3 - 3
src/lib/internal.h

@@ -92,9 +92,9 @@ MHD_DLOG (const struct MHD_Daemon *daemon,
  * Close FD and abort execution if error is detected.
  * @param fd the FD to close
  */
-#define MHD_fd_close_chk_(fd) do {             \
-    if (0 == close ((fd)) && (EBADF == errno)) \
-      MHD_PANIC(_("Failed to close FD.\n"));   \
+#define MHD_fd_close_chk_(fd) do {                      \
+    if ( (0 != close ((fd)) && (EBADF == errno)) )	\
+      MHD_PANIC(_("Failed to close FD.\n"));            \
   } while(0)
 
 /**

+ 4 - 2
src/lib/mhd_itc.h

@@ -108,11 +108,13 @@ static const uint64_t _MHD_itc_wr_data = 1;
        (void)__r; } while(0)
 
 /**
- * Destroy previously initialised ITC
+ * Destroy previously initialised ITC.  Note that close()
+ * on some platforms returns odd errors, so we ONLY fail
+ * if the errno is EBADF.
  * @param itc the itc to destroy
  * @return non-zero if succeeded, zero otherwise
  */
-#define MHD_itc_destroy_(itc) ((0 != close ((itc).fd)) || (EBADF != errno))
+#define MHD_itc_destroy_(itc) ((0 == close ((itc).fd)) || (EBADF != errno))
 
 /**
  * Check whether ITC has valid value.

+ 3 - 3
src/microhttpd/internal.h

@@ -77,9 +77,9 @@
  * Close FD and abort execution if error is detected.
  * @param fd the FD to close
  */
-#define MHD_fd_close_chk_(fd) do {             \
-    if (0 == close ((fd)) && (EBADF == errno)) \
-      MHD_PANIC(_("Failed to close FD.\n"));   \
+#define MHD_fd_close_chk_(fd) do {                      \
+    if ( (0 != close ((fd)) && (EBADF == errno)) )	\
+      MHD_PANIC(_("Failed to close FD.\n"));            \
   } while(0)
 
 /**

+ 4 - 2
src/microhttpd/mhd_itc.h

@@ -108,11 +108,13 @@ static const uint64_t _MHD_itc_wr_data = 1;
        (void)__r; } while(0)
 
 /**
- * Destroy previously initialised ITC
+ * Destroy previously initialised ITC.  Note that close()
+ * on some platforms returns odd errors, so we ONLY fail
+ * if the errno is EBADF.
  * @param itc the itc to destroy
  * @return non-zero if succeeded, zero otherwise
  */
-#define MHD_itc_destroy_(itc) ((0 != close ((itc).fd)) || (EBADF != errno))
+#define MHD_itc_destroy_(itc) ((0 == close ((itc).fd)) || (EBADF != errno))
 
 /**
  * Check whether ITC has valid value.