[Tarantool-patches] [PATCH 13/13] popen: add caution comment for popen_may_io()

Alexander Turenko alexander.turenko at tarantool.org
Wed Apr 15 07:25:50 MSK 2020


It was easy to misinterpret popen_may_io() contract. In fact, I made
this mistake recently and want to clarify how the function should be
called.

Part of #4031
---
 src/lib/core/popen.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c
index 1b564d0c2..cbf2fd690 100644
--- a/src/lib/core/popen.c
+++ b/src/lib/core/popen.c
@@ -259,12 +259,19 @@ popen_set_unsupported_io_error(void)
 /**
  * Test if the handle can run a requested IO operation.
  *
+ * NB: Expects @a io_flags to be a ..._FD_STDx flag rather
+ * then a mask with several flags: otherwise it'll check
+ * that one (any) of @a io_flags is set.
+ *
  * Returns 0 if so and -1 otherwise (and set a diag).
  */
 static inline int
 popen_may_io(struct popen_handle *handle, unsigned int idx,
 	     unsigned int io_flags)
 {
+	assert(io_flags == POPEN_FLAG_FD_STDIN	||
+	       io_flags == POPEN_FLAG_FD_STDOUT	||
+	       io_flags == POPEN_FLAG_FD_STDERR);
 	if (!(io_flags & handle->flags))
 		return popen_set_unsupported_io_error();
 
-- 
2.25.0



More information about the Tarantool-patches mailing list