git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 6/7] trace: disable key after write error

From
Jeff King <peff@peff.net>
Date
Aug 5, 2016, 07:58 UTC
Message-ID
<20160805075838.zkwoyorvdc4ljn6l@sigill.intra.peff.net>
In-Reply-To
<20160804212244.cilov7i2uelg7lnh@sigill.intra.peff.net>
On Thu, Aug 04, 2016 at 05:22:44PM -0400, Jeff King wrote:
Show 28 quoted lines
> On Thu, Aug 04, 2016 at 01:45:11PM -0700, Junio C Hamano wrote:
> 
> > Jeff King <peff@peff.net> writes:
> > 
> > > If we get a write error writing to a trace descriptor, the
> > > error isn't likely to go away if we keep writing. Instead,
> > > you'll just get the same error over and over. E.g., try:
> > >
> > >   GIT_TRACE_PACKET=42 git ls-remote >/dev/null
> > >
> > > You don't really need to see:
> > >
> > >   warning: unable to write trace for GIT_TRACE_PACKET: Bad file descriptor
> > >
> > > hundreds of times. We could fallback to tracing to stderr,
> > > as we do in the error code-path for open(), but there's not
> > > much point. If the user fed us a bogus descriptor, they're
> > > probably better off fixing their invocation. And if they
> > > didn't, and we saw a transient error (e.g., ENOSPC writing
> > > to a file), it probably doesn't help anybody to have half of
> > > the trace in a file, and half on stderr.
> > 
> > Yes, I think I like this better than "we cannot open the named file,
> > so let's trace into standard error stream" that is done in the code
> > in the context of [3/7].  We should do the same over there.
> 
> Yeah, I was tempted to strip that out, too. I'll look into preparing a
> patch on top.
Here's a patch that can go on the tip of jk/trace-fixup.
-- >8 --
Subject: [PATCH] trace: do not fall back to stderr

If the trace code cannot open a specified file, or does not understand the contents of the GIT_TRACE variable, it falls back to printing trace output to stderr.

This is an attempt to be helpful, but in practice it just ends up annoying. The user was trying to get the output to go somewhere else, so spewing it to stderr does not really accomplish that. And as it's intended for debugging, they can presumably re-run the command with their error corrected.

So instead of falling back, this patch disables bogus trace keys for the rest of the program, just as we do for write errors. We can drop the "Defaulting to..." part of the error message entirely; after seeing "cannot open '/foo'", the user can assume that tracing is skipped.

Signed-off-by: Jeff King <peff@peff.net>
---
 trace.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/trace.c b/trace.c
index 083eb98..7508aea 100644
--- a/trace.c
+++ b/trace.c
@@ -61,10 +61,9 @@ static int get_trace_fd(struct trace_key *key)
 	else if (is_absolute_path(trace)) {
 		int fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);
 		if (fd == -1) {
-			warning("could not open '%s' for tracing: %s\n"
-				"         Defaulting to tracing on stderr...",
+			warning("could not open '%s' for tracing: %s",
 				trace, strerror(errno));
-			key->fd = STDERR_FILENO;
+			trace_disable(key);
 		} else {
 			key->fd = fd;
 			key->need_close = 1;
@@ -72,10 +71,9 @@ static int get_trace_fd(struct trace_key *key)
 	} else {
 		warning("unknown trace value for '%s': %s\n"
 			"         If you want to trace into a file, then please set %s\n"
-			"         to an absolute pathname (starting with /)\n"
-			"         Defaulting to tracing on stderr...",
+			"         to an absolute pathname (starting with /)",
 			key->key, trace, key->key);
-		key->fd = STDERR_FILENO;
+		trace_disable(key);
 	}
 
 	key->initialized = 1;
-- 
2.9.2.707.g48ee8b7
Previous: Jeff KingNext: Jeff King
Message 13 of 20 in “minor trace fixes and cosmetic improvements”
  1. 0/7 minor trace fixes and cosmetic improvementsJeff King, Aug 3, 2016
  2. 2/7 trace: stop using write_or_whine_pipe()Jeff King, Aug 3, 2016
  3. 3/7 trace: use warning() for printing trace errorsJeff King, Aug 3, 2016
  4. Junio C HamanoAug 4, 2016
  5. Jeff KingAug 4, 2016
  6. Junio C HamanoAug 4, 2016
  7. Jeff KingAug 5, 2016
  8. Christian CouderAug 5, 2016
  9. Junio C HamanoAug 5, 2016
  10. 6/7 trace: disable key after write errorJeff King, Aug 3, 2016
  11. Junio C HamanoAug 4, 2016
  12. Jeff KingAug 4, 2016
  13. Jeff KingAug 5, 2016
  14. 7/7 write_or_die: drop write_or_whine_pipe()Jeff King, Aug 3, 2016
  15. 1/7 trace: handle NULL argument in trace_disable()Jeff King, Aug 3, 2016
  16. Jeff KingAug 3, 2016
  17. 4/7 trace: cosmetic fixes for error messagesJeff King, Aug 3, 2016
  18. Junio C HamanoAug 4, 2016
  19. Jeff KingAug 5, 2016
  20. 5/7 trace: correct variable name in write() error messageJeff King, Aug 3, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.