From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [94.100.177.109]) (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 021A04696CB for ; Fri, 10 Apr 2020 05:51:20 +0300 (MSK) From: Alexander Turenko Date: Fri, 10 Apr 2020 05:50:47 +0300 Message-Id: <5e80540e9231da5f073016e53f133cf14ca01a64.1586486220.git.alexander.turenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 09/13] popen: remove redundant fd check before perform 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 The function already checks flags to find out whether the file descriptor should be available for reading / writing. When it is so, the corresponding fd is great or equal to zero. The further commits will add missed diagnostics for IO functions and it is hard to write a meaningful error message for a situation that is not possible. Moreover, we would obligated to document the error as one of possible failures in a function contract (while it can't occur). Part of #4031 --- src/lib/core/popen.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c index 660ace0d5..c54e0b211 100644 --- a/src/lib/core/popen.c +++ b/src/lib/core/popen.c @@ -194,8 +194,7 @@ handle_free(struct popen_handle *handle) * Test if the handle can run io operation. */ static inline bool -popen_may_io(struct popen_handle *handle, unsigned int idx, - unsigned int io_flags) +popen_may_io(struct popen_handle *handle, unsigned int io_flags) { if (!handle) { errno = ESRCH; @@ -207,11 +206,6 @@ popen_may_io(struct popen_handle *handle, unsigned int idx, return false; } - if (handle->ios[idx].fd < 0) { - errno = EPIPE; - return false; - } - return true; } @@ -294,7 +288,7 @@ popen_write_timeout(struct popen_handle *handle, const void *buf, return -1; } - if (!popen_may_io(handle, STDIN_FILENO, flags)) + if (!popen_may_io(handle, flags)) return -1; if (count > (size_t)SSIZE_MAX) { @@ -329,7 +323,7 @@ popen_read_timeout(struct popen_handle *handle, void *buf, return -1; } - if (!popen_may_io(handle, idx, flags)) + if (!popen_may_io(handle, flags)) return -1; if (count > (size_t)SSIZE_MAX) { -- 2.25.0