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

Re: [PATCH] add strerror(errno) to die() calls where applicable

From
Thomas Rast <trast@student.ethz.ch>
Date
Jun 6, 2009, 13:09 UTC
Message-ID
<200906061509.15870.trast@student.ethz.ch>
In-Reply-To
<20090603015503.GA14166@coredump.intra.peff.net>

Sorry for not getting around to this again all week. I'll try to reroll later today...

Jeff King wrote:
>   1. How did you determine the set of callsites? Did you check that each
>      non-syscall function always sets errno? Are there are functions
>      which are setting errno which could also be included?

Basically by 'git grep die | grep -v errno' and then looking at the code immediately before the die(). Rather tedious, but I couldn't see an obvious way to automate the task.

As for the non-syscall functions, at first I had a longer list but I eventually settled with the ones mentioned, but I decided it was too risky and just stuck with those that are very clear:

> On Tue, Jun 02, 2009 at 11:34:33PM +0200, Thomas Rast wrote:
> >   odb_pack_keep

Tries open() in two ways, but can only return <0 by passing the return value of the second.

> >   read_ancestry
Only returns -1 if fopen() returned NULL.
> >   read_in_full

Only returns <=0 if xread() returned <=0, which in turn only happens if read() returned <0.

> >   strbuf_read
Returns -1 if xread() did so.
> >   strbuf_read_file
Returns -1 if open() or strbuf_read() failed.
> >   strbuf_readlink

Returns -1 if readlink() failed. (The other option, that the buffer was still too small at STRBUF_MAXLINK, would imply that readlink() wanted to return more than PATH_MAX chars.)

> >   write_buffer

I'll drop this one, I missed that it actually does its own errno reporting already. (Other than that it's just a thin wrapper around write_in_full.)

> >   write_in_full

Symmetric to read_in_full: only returns <=0 if xwrite() did, which in turn only happens if write() returned <0.

There were lots of cases that aren't quite as clear-cut. For example, there are many call sites where the index is written out that look like

	if (write_cache(fd, active_cache, active_nr) ||
	    close_lock_file(&index_lock))
		die("unable to write new_index file");

Dealing with those will be somewhat more complicated, as the error case is not all that clearly defined. But at least at a quick glance, write_cache does not even indicate what file it failed to write.

>   2. Extra error conditions may leak information about the filesystem to
>      people feeding bogus paths to upload-pack. I didn't see anything
>      obvious in your patch that would cause this, but it is something to
>      consider.
Good point.
Show 5 quoted lines
> > -		die("closing file %s: %s", path, strerror(errno));
> > +		die("closing file '%s': %s", path, strerror(errno));
> 
> This one is actually just a style change, though I think it is
> worthwhile (and there are a few others like it).

Yes, as I was already going through the calls I thought some consistency would be nice.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Jeff KingNext: Thomas Rast
Message 9 of 28 in “add strerror(errno) to die() calls where applicable”
  1. add strerror(errno) to die() calls where applicableThomas Rast, Jun 2, 2009
  2. Jeff KingJun 3, 2009
  3. diesys calls die and also reports strerror(errno)Alexander Potashev, Jun 4, 2009
  4. Jeff KingJun 4, 2009
  5. Junio C HamanoJun 4, 2009
  6. Johannes SixtJun 5, 2009
  7. Junio C HamanoJun 5, 2009
  8. Jeff KingJun 6, 2009
  9. Thomas RastJun 6, 2009
  10. 0/3 Thomas Rast <trast@student.ethz.ch>Thomas Rast, Jun 6, 2009
  11. 1/3 Introduce die_errno() that appends strerror(errno) to die()Thomas Rast, Jun 6, 2009
  12. 2/3 Convert existing die(..., strerror(errno)) to die_errno()Thomas Rast, Jun 6, 2009
  13. 3/3 Use die_errno() instead of die() when checking syscallsThomas Rast, Jun 6, 2009
  14. Johannes SixtJun 6, 2009
  15. Thomas RastJun 6, 2009
  16. Johannes SixtJun 6, 2009
  17. Johannes SixtJun 6, 2009
  18. Thomas RastJun 6, 2009
  19. Johannes SixtJun 6, 2009
  20. Jeff KingJun 6, 2009
  21. Jeff KingJun 6, 2009
  22. Alexander PotashevJun 7, 2009
  23. Junio C HamanoJun 7, 2009
  24. Jeff KingJun 8, 2009
  25. Alexander PotashevJun 8, 2009
  26. Jeff KingJun 8, 2009
  27. Alexander PotashevJun 4, 2009
  28. Jeff KingJun 4, 2009

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.