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

Re: [PATCH 4/4] config.c: rewrite ENODEV into EISDIR when mmap fails

From
Jeff King <peff@peff.net>
Date
May 28, 2015, 20:44 UTC
Message-ID
<20150528204436.GB29148@peff.net>
In-Reply-To
<xmqq7frsiq3o.fsf@gitster.dls.corp.google.com>
On Thu, May 28, 2015 at 10:11:55AM -0700, Junio C Hamano wrote:
Show 23 quoted lines
> >  		if (contents == MAP_FAILED) {
> > +			if (errno == ENODEV && S_ISDIR(st.st_mode))
> > +				errno = EISDIR;
> >  			error("unable to mmap '%s': %s",
> >  			      config_filename, strerror(errno));
> >  			ret = CONFIG_INVALID_FILE;
> 
> I think this patch places the "magic" at the right place, but I
> would have preferred to see something more like this:
> 
> 	if (contents == MAP_FAILED) {
>         	if (errno == ENODEV && S_ISDIR(st.st_mode))
> 			error("unable to mmap a directory '%s',
>                         	config_filename);
> 		else
>                 	error("unable to mmap '%s': %s",
>                         	config_filename, strerror(errno));
> 		ret = CONFIG_INVALID_FILE;
> 
> But that is a very minor preference.  I am OK with relying on our
> knowledge that strerror(EISDIR) would give something that says "the
> thing is a directory which is not appropriate for the operation", as
> nobody after that strerror() refers to 'errno' in this codepath.

I am OK if you want to switch it. Certainly EISDIR produces good output on my system, but I don't know if that is universal.

We also know S_ISDIR(st.st_mode) _before_ we actually mmap. So I was tempted to simply check it beforehand, under the assumption that the mmap cannot possibly work if we have a directory. But by doing it in the error code path, then we _know_ we are not affecting the outcome, only the error message. :)

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 20 in “Bug: .gitconfig folder”
  1. JorgeMay 27, 2015
  2. Junio C HamanoMay 27, 2015
  3. Jeff KingMay 27, 2015
  4. Stefan BellerMay 27, 2015
  5. Jeff KingMay 28, 2015
  6. Junio C HamanoMay 27, 2015
  7. Jeff KingMay 28, 2015
  8. 1/4 read-cache.c: drop PROT_WRITE from mmap of indexJeff King, May 28, 2015
  9. 2/4 config.c: fix mmap leak when writing configJeff King, May 28, 2015
  10. config.c: fix writing config files on Windows network sharesKarsten Blees, Jun 30, 2015
  11. Torsten BögershausenJun 30, 2015
  12. Jeff KingJun 30, 2015
  13. Johannes SchindelinJun 30, 2015
  14. Jeff KingJun 30, 2015
  15. 3/4 config.c: avoid xmmap error messagesJeff King, May 28, 2015
  16. 4/4 config.c: rewrite ENODEV into EISDIR when mmap failsJeff King, May 28, 2015
  17. Junio C HamanoMay 28, 2015
  18. Jeff KingMay 28, 2015
  19. Junio C HamanoMay 28, 2015
  20. Junio C HamanoMay 28, 2015

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.