diff mbox series

refs: print errno for read_raw_ref if GIT_TRACE_REFS is set

Message ID pull.1002.git.git.1618255954484.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series refs: print errno for read_raw_ref if GIT_TRACE_REFS is set | expand

Commit Message

Han-Wen Nienhuys April 12, 2021, 7:32 p.m. UTC
From: Han-Wen Nienhuys <hanwen@google.com>

The ref backend API uses errno as a sideband error channel.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
    refs: print errno for read_raw_ref if GIT_TRACE_REFS is set
    
    The ref backend API uses errno as a sideband error channel.
    
    Signed-off-by: Han-Wen Nienhuys hanwen@google.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1002%2Fhanwen%2Ferrno-debug-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1002/hanwen/errno-debug-v1
Pull-Request: https://github.com/git/git/pull/1002

 refs/debug.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)


base-commit: 89b43f80a514aee58b662ad606e6352e03eaeee4

Comments

Junio C Hamano April 12, 2021, 9:45 p.m. UTC | #1
"Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:

> diff --git a/refs/debug.c b/refs/debug.c
> index 922e64fa6ad9..576bf98e74ae 100644
> --- a/refs/debug.c
> +++ b/refs/debug.c
> @@ -244,6 +244,7 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
>  	int res = 0;
>  
>  	oidcpy(oid, &null_oid);
> +	errno = 0;
>  	res = drefs->refs->be->read_raw_ref(drefs->refs, refname, oid, referent,
>  					    type);
>  
> @@ -251,7 +252,9 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
>  		trace_printf_key(&trace_refs, "read_raw_ref: %s: %s (=> %s) type %x: %d\n",
>  			refname, oid_to_hex(oid), referent->buf, *type, res);
>  	} else {
> -		trace_printf_key(&trace_refs, "read_raw_ref: %s: %d\n", refname, res);
> +		trace_printf_key(&trace_refs,
> +				 "read_raw_ref: %s: %d (errno %d)\n", refname,
> +				 res, errno);
>  	}

OK.  Between trace_printf_key() and the return of the call to
read_raw_ref() method of the ref backend is only an "if (res == 0)"
condition and I do not see anything that might clobber errno.

I do wonder if we want strerror(errno) instead of the number, but I
can go either way (it's just a trace output).

Thanks, will queue.
Han-Wen Nienhuys April 13, 2021, 11:58 a.m. UTC | #2
On Mon, Apr 12, 2021 at 11:45 PM Junio C Hamano <gitster@pobox.com> wrote:
> > @@ -251,7 +252,9 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
> >               trace_printf_key(&trace_refs, "read_raw_ref: %s: %s (=> %s) type %x: %d\n",
> >                       refname, oid_to_hex(oid), referent->buf, *type, res);
> >       } else {
> > -             trace_printf_key(&trace_refs, "read_raw_ref: %s: %d\n", refname, res);
> > +             trace_printf_key(&trace_refs,
> > +                              "read_raw_ref: %s: %d (errno %d)\n", refname,
> > +                              res, errno);
> >       }
>
> OK.  Between trace_printf_key() and the return of the call to
> read_raw_ref() method of the ref backend is only an "if (res == 0)"
> condition and I do not see anything that might clobber errno.

I don't want to bet on that. Let me send a second round.

> I do wonder if we want strerror(errno) instead of the number, but I
> can go either way (it's just a trace output).

For tracing, it would be most useful if we got the actual symbol (eg.
ENOENT). Is there a way to get at that?
Han-Wen Nienhuys April 13, 2021, 12:02 p.m. UTC | #3
On Tue, Apr 13, 2021 at 1:58 PM Han-Wen Nienhuys <hanwen@google.com> wrote:
>
> On Mon, Apr 12, 2021 at 11:45 PM Junio C Hamano <gitster@pobox.com> wrote:
> > > @@ -251,7 +252,9 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
> > >               trace_printf_key(&trace_refs, "read_raw_ref: %s: %s (=> %s) type %x: %d\n",
> > >                       refname, oid_to_hex(oid), referent->buf, *type, res);
> > >       } else {
> > > -             trace_printf_key(&trace_refs, "read_raw_ref: %s: %d\n", refname, res);
> > > +             trace_printf_key(&trace_refs,
> > > +                              "read_raw_ref: %s: %d (errno %d)\n", refname,
> > > +                              res, errno);
> > >       }
> >
> > OK.  Between trace_printf_key() and the return of the call to
> > read_raw_ref() method of the ref backend is only an "if (res == 0)"
> > condition and I do not see anything that might clobber errno.
>
> I don't want to bet on that. Let me send a second round.

oh, ugh.  In email, there are two calls, but one is prefixed with '-'.

Nevertheless, a bit of paranoia doesn't hurt here.
Junio C Hamano April 13, 2021, 8:08 p.m. UTC | #4
Han-Wen Nienhuys <hanwen@google.com> writes:

>> I do wonder if we want strerror(errno) instead of the number, but I
>> can go either way (it's just a trace output).
>
> For tracing, it would be most useful if we got the actual symbol (eg.
> ENOENT). Is there a way to get at that?

I do not think there is.

And that is the reason why we see everywhere calls to die_errno(),
error(..., strerror(errno)), etc.

As this is interpolated into trace with untranslated string,
I suspect that strerror() is not a good match, so let's live with %d
for now.

Thanks.
Han-Wen Nienhuys April 23, 2021, 8:34 a.m. UTC | #5
On Tue, Apr 13, 2021 at 10:08 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Han-Wen Nienhuys <hanwen@google.com> writes:
>
> >> I do wonder if we want strerror(errno) instead of the number, but I
> >> can go either way (it's just a trace output).
> >
> > For tracing, it would be most useful if we got the actual symbol (eg.
> > ENOENT). Is there a way to get at that?
>
> I do not think there is.
>
> And that is the reason why we see everywhere calls to die_errno(),
> error(..., strerror(errno)), etc.
>
> As this is interpolated into trace with untranslated string,
> I suspect that strerror() is not a good match, so let's live with %d
> for now.

Great!

This topic is marked as

Waiting for reviews to conclude.
cf. <xmqq4kgbb2ic.fsf@gitster.g>

but I don't know what is left to do. Oversight?
diff mbox series

Patch

diff --git a/refs/debug.c b/refs/debug.c
index 922e64fa6ad9..576bf98e74ae 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -244,6 +244,7 @@  static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
 	int res = 0;
 
 	oidcpy(oid, &null_oid);
+	errno = 0;
 	res = drefs->refs->be->read_raw_ref(drefs->refs, refname, oid, referent,
 					    type);
 
@@ -251,7 +252,9 @@  static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
 		trace_printf_key(&trace_refs, "read_raw_ref: %s: %s (=> %s) type %x: %d\n",
 			refname, oid_to_hex(oid), referent->buf, *type, res);
 	} else {
-		trace_printf_key(&trace_refs, "read_raw_ref: %s: %d\n", refname, res);
+		trace_printf_key(&trace_refs,
+				 "read_raw_ref: %s: %d (errno %d)\n", refname,
+				 res, errno);
 	}
 	return res;
 }