From: Derrick Stolee <derrickstolee@github.com>
To: Kevin Locke <kevin@kevinlocke.name>, git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v4] setup: don't die if realpath(3) fails on getcwd(3)
Date: Tue, 24 May 2022 16:40:17 -0400 [thread overview]
Message-ID: <e311a560-0606-e5f7-0c41-a6b0f42062cf@github.com> (raw)
In-Reply-To: <8b20840014d214023c50ee62439147f798e6f9cc.1653419993.git.kevin@kevinlocke.name>
On 5/24/2022 3:20 PM, Kevin Locke wrote:
> Changes since v3:
> * Free tmp_original_cwd in both codepaths.
> * Return after strbuf_realpath() fails, rather than jumping to
> no_prevention_needed, to avoid unnecessary free(NULL) and NULL
> reassignment.
> * Invert the condition and remove the else block to match the
> return-on-error code style for better readability.
> * Stop adding "Try" to comment, since strbuf_realpath() hasn't
> been optional since v1.
...
> /* Normalize the directory */
> - strbuf_realpath(&tmp, tmp_original_cwd, 1);
> + if (!strbuf_realpath(&tmp, tmp_original_cwd, 0)) {
> + trace2_data_string("setup", the_repository,
> + "realpath-path", tmp_original_cwd);
> + trace2_data_string("setup", the_repository,
> + "realpath-failure", strerror(errno));
> + free((char*)tmp_original_cwd);
> + tmp_original_cwd = NULL;
> + return;
> + }
This is much easier to reason about.
> free((char*)tmp_original_cwd);
> tmp_original_cwd = NULL;
> startup_info->original_cwd = strbuf_detach(&tmp, NULL);
I had considered trying to remove this duplicate code freeing
temp_original_cwd. It requires adding a variable storing the
return from strbuf_realpath() _or_ knowing that tmp will have
zero length if strbuf_realpath() fails. It would look gross,
though:
strbuf_realpath(&tmp, tmp_original_cwd, 0);
if (!tmp->len) {
trace2_data_string("setup", the_repository,
"realpath-path", tmp_original_cwd);
trace2_data_string("setup", the_repository,
"realpath-failure", strerror(errno));
}
free((char*)tmp_original_cwd);
tmp_original_cwd = NULL;
if (!tmp->len)
return;
startup_info->original_cwd = strbuf_detach(&tmp, NULL);
...and that doesn't look very good at all. Thus, I think your v4
is ready to merge. Thanks for working on it!
Thanks,
-Stolee
next prev parent reply other threads:[~2022-05-24 20:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-19 23:39 [PATCH] setup: don't die if realpath(3) fails on getcwd(3) Kevin Locke
2022-05-20 18:38 ` Junio C Hamano
2022-05-21 0:14 ` Elijah Newren
2022-05-21 13:02 ` Kevin Locke
2022-05-23 18:44 ` Derrick Stolee
2022-05-21 13:53 ` [PATCH v2] " Kevin Locke
2022-05-23 18:57 ` Derrick Stolee
2022-05-24 14:02 ` Kevin Locke
2022-05-24 15:20 ` Elijah Newren
2022-05-24 17:38 ` Derrick Stolee
2022-05-25 3:47 ` Elijah Newren
2022-05-27 7:48 ` Ævar Arnfjörð Bjarmason
2022-05-28 1:27 ` Elijah Newren
2022-05-24 14:51 ` [PATCH v3] " Kevin Locke
2022-05-24 15:21 ` Elijah Newren
2022-05-24 17:41 ` Derrick Stolee
2022-05-24 18:00 ` Kevin Locke
2022-05-24 19:20 ` [PATCH v4] " Kevin Locke
2022-05-24 20:40 ` Derrick Stolee [this message]
2022-05-24 21:25 ` Junio C Hamano
2022-05-25 3:51 ` Elijah Newren
2022-05-25 5:11 ` Junio C Hamano
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=e311a560-0606-e5f7-0c41-a6b0f42062cf@github.com \
--to=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kevin@kevinlocke.name \
--cc=newren@gmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.