From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 0A3104696C3 for ; Wed, 15 Apr 2020 07:25:56 +0300 (MSK) From: Alexander Turenko Date: Wed, 15 Apr 2020 07:25:50 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 13/13] popen: add caution comment for popen_may_io() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov Cc: tarantool-patches@dev.tarantool.org 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