commit 83a86be948420f7bd902ceee9d661fc208eec1cd
parent 302d381133a26e6223766eea094a784993022fc4
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 8 Apr 2019 15:12:20 +0200
fix close() checks
Diffstat:
5 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/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
diff --git a/src/lib/internal.h b/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)
/**
diff --git a/src/lib/mhd_itc.h b/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.
diff --git a/src/microhttpd/internal.h b/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)
/**
diff --git a/src/microhttpd/mhd_itc.h b/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.