Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Farid Zakaria <farid.m.zakaria@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Jeff King <peff@peff.net>, M Hickford <mirth.hickford@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Jeff Hostetler <jeffhostetler@github.com>
Subject: Re: [PATCH 1/2] credential-cache--daemon: allow a concurrently created socket dir
Date: Tue, 3 Nov 2026 09:01:08 +0100	[thread overview]
Message-ID: <aumUxF1uVtVC4qYj@pks.im> (raw)
In-Reply-To: <20261101-fz-credential-cache-race-v1-1-28f0bac51e11@gmail.com>

On Sun, Nov 01, 2026 at 03:29:25PM -0800, Farid Zakaria wrote:
> diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c
> index 65cc619bec..0dfa11e2ec 100644
> --- a/builtin/credential-cache--daemon.c
> +++ b/builtin/credential-cache--daemon.c
> @@ -273,8 +273,18 @@ static void init_socket_directory(const char *path)
>  		 */
>  		if (safe_create_leading_directories_const(the_repository, dir) < 0)
>  			die_errno("unable to create directories for '%s'", dir);

It's quite curious that we use `safe_create_leading_directories()` here.
As documented in "path.h", the `safe_...()` functions should only ever
be used for creating directories in the ".git" directory itself. In
particular, applying "core.sharedRepostiory" to the leading directories
of our credential daemon is never going to result in anything good at
all.

So we should call `safe_create_leadingdirectories_no_share_const()`
instead, which does not apply "core.sharedRepository". I know that's not
introduced by your patch, but would you mind maybe fixing that in a
preparatory commit?

> -		if (mkdir(dir, 0700) < 0)
> -			die_errno("unable to mkdir '%s'", dir);
> +		if (mkdir(dir, 0700) < 0) {
> +			if (errno != EEXIST)
> +				die_errno("unable to mkdir '%s'", dir);

Makes sense.

> +			/*
> +			 * Another daemon created it first; check it like one
> +			 * that already existed.
> +			 */
> +			if (stat(dir, &st))
> +				die_errno("unable to stat '%s'", dir);
> +			if (st.st_mode & 077)
> +				die(_(permissions_advice), dir);
> +		}

A bit of a shame that we duplicate this logic, but I don't see an
obvious way for how to avoid that.

Patrick

  reply	other threads:[~2026-11-03  8:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 23:29 [PATCH 0/2] credential-cache: fix two races when daemons start at once Farid Zakaria
2026-11-01 23:29 ` [PATCH 1/2] credential-cache--daemon: allow a concurrently created socket dir Farid Zakaria
2026-11-03  8:01   ` Patrick Steinhardt [this message]
2026-11-04 18:25     ` Farid Zakaria
2026-11-04  2:58   ` Jeff King
2026-11-01 23:29 ` [PATCH 2/2] credential-cache--daemon: do not take over a running daemon's socket Farid Zakaria
2026-11-03  8:01   ` Patrick Steinhardt
2026-11-04 18:28     ` Farid Zakaria
2026-11-03 17:24   ` Junio C Hamano
2026-11-04  3:07   ` Jeff King
2026-11-04 19:53 ` [PATCH v2 0/3] credential-cache: fix two races when daemons start at once Farid Zakaria
2026-11-04 19:53   ` [PATCH v2 1/3] credential-cache--daemon: do not apply core.sharedRepository Farid Zakaria
2026-11-04 19:53   ` [PATCH v2 2/3] credential-cache--daemon: allow a concurrently created socket dir Farid Zakaria
2026-11-04 19:53   ` [PATCH v2 3/3] credential-cache--daemon: do not take over a running daemon's socket Farid Zakaria

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=aumUxF1uVtVC4qYj@pks.im \
    --to=ps@pks.im \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=farid.m.zakaria@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhostetler@github.com \
    --cc=mirth.hickford@gmail.com \
    --cc=peff@peff.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox