From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Enzo Matsumiya <ematsumiya@suse.de>, git@vger.kernel.org
Subject: Re: [PATCH v2] pager: fix crash when pager program doesn't exist
Date: Sun, 21 Nov 2021 23:35:51 -0500 [thread overview]
Message-ID: <YZseJ4jOVIK3+bUD@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqfsrplz3z.fsf@gitster.g>
On Sun, Nov 21, 2021 at 06:10:08PM -0800, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > We'd usually leave of "Reviewed-by" until the reviewer has had a chance
> > to see _this_ version of the patch. I.e., usually it would not be added
> > by the submitter, but by the maintainer (unless you are resending
> > verbatim a patch that already got review).
> >
> >> diff --git a/run-command.c b/run-command.c
> >> index f329391154ae..a7bf81025afb 100644
> >> --- a/run-command.c
> >> +++ b/run-command.c
> >> @@ -19,6 +19,7 @@ void child_process_clear(struct child_process *child)
> >> {
> >> strvec_clear(&child->args);
> >> strvec_clear(&child->env_array);
> >> + child_process_init(child);
> >> }
> >
> > And naturally I agree that the patch itself looks good. :)
>
> Well, not to me X-<. This is way too aggressive a change to be made
> lightly without auditing the current users of run_command API.
Yikes. Thanks for a dose of sanity. I was looking too much at just the
pager tests.
> It is rather common for us to reuse "struct child_process" in a code
> path, e.g. builtin/worktree.c::add_worktree() prepares a single
> instance of such a struct, sets cp.git_cmd to true, and runs either
> "update-ref" or "symbolic-ref" to update "HEAD". After successful
> invocation of such a git subcommand, it then runs "git reset --hard",
> with this piece of code:
>
> cp.git_cmd = 1;
>
> if (!is_branch)
> strvec_pushl(&cp.args, "update-ref", "HEAD",
> oid_to_hex(&commit->object.oid), NULL);
> else {
> strvec_pushl(&cp.args, "symbolic-ref", "HEAD",
> symref.buf, NULL);
> if (opts->quiet)
> strvec_push(&cp.args, "--quiet");
> }
>
> cp.env = child_env.v;
> ret = run_command(&cp);
> if (ret)
> goto done;
>
> if (opts->checkout) {
> cp.argv = NULL;
> strvec_clear(&cp.args);
> strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL);
> if (opts->quiet)
> strvec_push(&cp.args, "--quiet");
> cp.env = child_env.v;
> ret = run_command(&cp);
> if (ret)
> goto done;
> }
This is a pretty horrid interface, in that the caller has to understand
which bits of "cp" need to be adjusted: setting cp.argv to NULL, but
also potentially cp.env (if cp.env_array was used), and clearing any
stdin/out/err descriptors created as pipes in the previous command. And
probably more; that's just off the top of my head.
But clearly there's a bunch of code relying on the current state of
affairs.
> Now, we could argue that this existing caller is too lazy to assume
> that cp.git_cmd bit will be retained after run_command()
> successfully finishes and can reuse the structure without setting
> the bit again, and it should be more defensive. And "successful
> run_command() clears the child process so that you'll get a clean
> slate" may even be a better API in the longer term.
>
> But then a change like this one that changes the world order to make
> it a better place is also responsible to ensure that the callers are
> already following the new world order.
Yep. But I do worry a bit about changing the interface in such a subtle
way, as nothing would catch topics in flight.
> When merged to 'seen', this literally destroys tons of tests (the
> first and easiest one to observe may be t0002).
Forget 'seen'. Applying it on master shows plenty of breakages. :)
I think we should probably punt on this direction, and just make sure
that setup_pager() either reinitializes the child_process as appropriate
(as in the patch I showed in the earlier thread) or just refuses to try
running the pager twice (I didn't show a patch, but it should just be a
matter of setting a static flag).
-Peff
next prev parent reply other threads:[~2021-11-22 4:35 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-20 19:40 [PATCH v2] pager: fix crash when pager program doesn't exist Enzo Matsumiya
2021-11-21 18:37 ` Jeff King
2021-11-22 2:10 ` Junio C Hamano
2021-11-22 4:35 ` Jeff King [this message]
2021-11-22 14:52 ` Enzo Matsumiya
2021-11-22 17:05 ` Junio C Hamano
2021-11-23 16:40 ` Enzo Matsumiya
2021-11-24 1:55 ` Ævar Arnfjörð Bjarmason
2021-11-24 15:51 ` Jeff King
2021-11-22 16:04 ` [PATCH 0/5] run-command API: get rid of "argv" Ævar Arnfjörð Bjarmason
2021-11-22 16:04 ` [PATCH 1/5] archive-tar: use our own cmd.buf in error message Ævar Arnfjörð Bjarmason
2021-11-22 21:04 ` Junio C Hamano
2021-11-22 16:04 ` [PATCH 2/5] upload-archive: use regular "struct child_process" pattern Ævar Arnfjörð Bjarmason
2021-11-22 17:02 ` Jeff King
2021-11-22 20:53 ` Ævar Arnfjörð Bjarmason
2021-11-22 21:10 ` Jeff King
2021-11-22 21:36 ` Ævar Arnfjörð Bjarmason
2021-11-22 16:04 ` [PATCH 3/5] run-command API users: use strvec_pushv(), not argv assignment Ævar Arnfjörð Bjarmason
2021-11-22 21:19 ` Junio C Hamano
2021-11-22 21:30 ` Ævar Arnfjörð Bjarmason
2021-11-22 16:04 ` [PATCH 4/5] run-command API users: use strvec_pushl(), not argv construction Ævar Arnfjörð Bjarmason
2021-11-22 16:04 ` [PATCH 5/5] run-command API: remove "argv" member, always use "args" Ævar Arnfjörð Bjarmason
2021-11-22 17:32 ` Jeff King
2021-11-22 18:19 ` Ævar Arnfjörð Bjarmason
2021-11-22 18:47 ` Jeff King
2021-11-22 17:52 ` [PATCH 0/5] run-command API: get rid of "argv" Jeff King
2021-11-22 18:11 ` Junio C Hamano
2021-11-22 18:33 ` Ævar Arnfjörð Bjarmason
2021-11-22 18:49 ` Jeff King
2021-11-22 18:26 ` Ævar Arnfjörð Bjarmason
2021-11-23 12:06 ` [PATCH v2 0/9] run-command API: get rid of "argv" and "env" Ævar Arnfjörð Bjarmason
2021-11-23 12:06 ` [PATCH v2 1/9] worktree: remove redundant NULL-ing of "cp.argv Ævar Arnfjörð Bjarmason
2021-11-23 15:26 ` Eric Sunshine
2021-11-24 1:54 ` Junio C Hamano
2021-11-24 6:00 ` Eric Sunshine
2021-11-24 6:12 ` Eric Sunshine
2021-11-24 5:44 ` Eric Sunshine
2021-11-23 12:06 ` [PATCH v2 2/9] upload-archive: use regular "struct child_process" pattern Ævar Arnfjörð Bjarmason
2021-11-23 12:06 ` [PATCH v2 3/9] run-command API users: use strvec_pushv(), not argv assignment Ævar Arnfjörð Bjarmason
2021-11-23 12:06 ` [PATCH v2 4/9] run-command tests: " Ævar Arnfjörð Bjarmason
2021-11-24 1:33 ` Eric Sunshine
2021-11-23 12:06 ` [PATCH v2 5/9] run-command API users: use strvec_pushl(), not argv construction Ævar Arnfjörð Bjarmason
2021-11-23 12:06 ` [PATCH v2 6/9] run-command API users: use strvec_push(), " Ævar Arnfjörð Bjarmason
2021-11-23 12:06 ` [PATCH v2 7/9] run-command API: remove "argv" member, always use "args" Ævar Arnfjörð Bjarmason
2021-11-23 12:06 ` [PATCH v2 8/9] difftool: use "env_array" to simplify memory management Ævar Arnfjörð Bjarmason
2021-11-23 12:06 ` [PATCH v2 9/9] run-command API: remove "env" member, always use "env_array" Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 0/9] run-command API: get rid of "argv" and "env" Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 1/9] worktree: stop being overly intimate with run_command() internals Ævar Arnfjörð Bjarmason
2021-11-26 9:48 ` Eric Sunshine
2021-11-25 22:52 ` [PATCH v3 2/9] upload-archive: use regular "struct child_process" pattern Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 3/9] run-command API users: use strvec_pushv(), not argv assignment Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 4/9] run-command tests: " Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 5/9] run-command API users: use strvec_pushl(), not argv construction Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 6/9] run-command API users: use strvec_push(), " Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 7/9] run-command API: remove "argv" member, always use "args" Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 8/9] difftool: use "env_array" to simplify memory management Ævar Arnfjörð Bjarmason
2021-11-25 22:52 ` [PATCH v3 9/9] run-command API: remove "env" member, always use "env_array" Ævar Arnfjörð Bjarmason
2021-11-22 15:31 ` [PATCH v2] pager: fix crash when pager program doesn't exist Enzo Matsumiya
2021-11-22 16:22 ` Ævar Arnfjörð Bjarmason
2021-11-22 16:46 ` Enzo Matsumiya
2021-11-22 17:10 ` Ævar Arnfjörð Bjarmason
2021-11-22 17:41 ` Jeff King
2021-11-22 18:00 ` Junio C Hamano
2021-11-22 18:26 ` Jeff King
2021-11-22 17:55 ` Junio C Hamano
2021-11-22 18:19 ` Junio C Hamano
2021-11-22 18:37 ` Jeff King
2021-11-22 20:39 ` Junio C Hamano
2021-11-22 17:08 ` Junio C Hamano
2021-11-22 18:35 ` Ævar Arnfjörð Bjarmason
2021-11-22 16:30 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YZseJ4jOVIK3+bUD@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=ematsumiya@suse.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).