From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp3.mail.ru (smtp3.mail.ru [94.100.179.58]) (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 308564696C7 for ; Tue, 14 Apr 2020 14:38:46 +0300 (MSK) From: Alexander Turenko Date: Tue, 14 Apr 2020 14:38:13 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 04/12] popen: add missed diag_set() in popen_new() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov Cc: tarantool-patches@dev.tarantool.org See the previous similar commits: * popen: add missed diag_set() in popen IO functions * popen: add missed diag_set in popen_signal/delete Part of #4031 --- src/lib/core/popen.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c index fddcbae8f..c74ac17c7 100644 --- a/src/lib/core/popen.c +++ b/src/lib/core/popen.c @@ -803,7 +803,18 @@ signal_reset(void) * process will run with all files inherited from a parent. * * Returns pointer to a new popen handle on success, - * otherwise NULL returned setting @a errno. + * otherwise NULL returned and an error is set to the + * diagnostics area. + * + * Possible errors: + * + * - IllegalParams: a parameter check fails: + * - group signal is set, while setsid is not. + * - SystemError: dup(), fcntl(), pipe(), vfork() or close() fails + * in the parent process. + * - SystemError: (temporary restriction) one of std{in,out,err} + * is closed in the parent process. + * - OutOfMemory: unable to allocate handle. */ struct popen_handle * popen_new(struct popen_opts *opts) @@ -972,6 +983,7 @@ popen_new(struct popen_opts *opts) */ handle->pid = vfork(); if (handle->pid < 0) { + diag_set(SystemError, "vfork() fails"); goto out_err; } else if (handle->pid == 0) { /* @@ -1180,6 +1192,16 @@ exit_child: out_err: diag_log(); saved_errno = errno; + + /* + * Save a reason of failure, because popen_delete() may + * clobber the diagnostics area. + */ + struct diag *diag = diag_get(); + struct error *e = diag_last_error(diag); + assert(e != NULL); + error_ref(e); + popen_delete(handle); for (i = 0; i < lengthof(pfd); i++) { if (pfd[i][0] != -1) @@ -1189,6 +1211,11 @@ out_err: } if (log_fd >= 0) close(log_fd); + + /* Restore the diagnostics area entry. */ + diag_set_error(diag, e); + error_unref(e); + errno = saved_errno; return NULL; } -- 2.25.0