From: Alexander Turenko <alexander.turenko@tarantool.org> To: Cyrill Gorcunov <gorcunov@gmail.com> Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH 04/12] popen: add missed diag_set() in popen_new() Date: Tue, 14 Apr 2020 14:38:13 +0300 [thread overview] Message-ID: <c48a139757895f4ecaf02a62d2cc02dd4495eafb.1586862436.git.alexander.turenko@tarantool.org> (raw) In-Reply-To: <cover.1586862436.git.alexander.turenko@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
next prev parent reply other threads:[~2020-04-14 11:38 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-14 11:38 [Tarantool-patches] [PATCH 00/12] Popen Lua API: preliminary patches 2 Alexander Turenko 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 01/12] popen: allow to kill process group Alexander Turenko 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 02/12] popen: add ability to keep child on deletion Alexander Turenko 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 03/12] popen: log a reason of close inherited fds failure Alexander Turenko 2020-04-14 11:52 ` Cyrill Gorcunov 2020-04-14 11:38 ` Alexander Turenko [this message] 2020-04-14 11:54 ` [Tarantool-patches] [PATCH 04/12] popen: add missed diag_set() in popen_new() Cyrill Gorcunov 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 05/12] popen: remove retval from popen_stat() Alexander Turenko 2020-04-14 11:54 ` Cyrill Gorcunov 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 06/12] popen: quote multiword command arguments Alexander Turenko 2020-04-14 11:58 ` Cyrill Gorcunov 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 07/12] popen: add logging of duplicated logger fd Alexander Turenko 2020-04-14 11:58 ` Cyrill Gorcunov 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 08/12] popen: fix close-on-exec flag setting Alexander Turenko 2020-04-14 12:03 ` Cyrill Gorcunov 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 09/12] popen: clarify popen_{signal, delete} contract Alexander Turenko 2020-04-14 12:29 ` Cyrill Gorcunov 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 10/12] popen: add FIXME re group signal flaw Alexander Turenko 2020-04-14 13:19 ` Cyrill Gorcunov 2020-04-15 4:21 ` Alexander Turenko 2020-04-15 7:27 ` Cyrill Gorcunov 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 11/12] popen: clarify popen_read_timeout error message Alexander Turenko 2020-04-14 12:32 ` Cyrill Gorcunov 2020-04-15 4:21 ` Alexander Turenko 2020-04-15 7:39 ` Cyrill Gorcunov 2020-04-15 21:45 ` Alexander Turenko 2020-04-14 11:38 ` [Tarantool-patches] [PATCH 12/12] popen: allow to close parent's end of std* fds Alexander Turenko 2020-04-14 13:05 ` Cyrill Gorcunov 2020-04-15 4:21 ` Alexander Turenko 2020-04-15 7:43 ` Cyrill Gorcunov 2020-04-15 21:45 ` Alexander Turenko 2020-04-15 4:25 ` [Tarantool-patches] [PATCH 13/13] popen: add caution comment for popen_may_io() Alexander Turenko 2020-04-15 7:44 ` Cyrill Gorcunov 2020-04-15 4:52 ` [Tarantool-patches] [PATCH 14/14] popen: fix popen_write_timeout retval type Alexander Turenko 2020-04-15 23:57 ` [Tarantool-patches] [PATCH 00/12] Popen Lua API: preliminary patches 2 Alexander Turenko 2020-04-16 0:00 ` Alexander Turenko 2020-04-16 11:52 ` Cyrill Gorcunov 2020-04-17 6:58 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=c48a139757895f4ecaf02a62d2cc02dd4495eafb.1586862436.git.alexander.turenko@tarantool.org \ --to=alexander.turenko@tarantool.org \ --cc=gorcunov@gmail.com \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 04/12] popen: add missed diag_set() in popen_new()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox