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

Re: [PATCH 5/6] git_mkstemps_mode: don't set errno to EINVAL for any error.

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 20, 2010, 18:13 UTC
Message-ID
<7v4olbpyh3.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1266621718-4879-5-git-send-email-Matthieu.Moy@imag.fr>
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
Show 19 quoted lines
> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
> ---
>  path.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/path.c b/path.c
> index 005b836..2886eb6 100644
> --- a/path.c
> +++ b/path.c
> @@ -222,7 +222,9 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
>  	}
>  	/* We return the null string if we can't find a unique file name.  */
>  	pattern[0] = '\0';
> -	errno = EINVAL;
> +	/* Make sure errno signals an error on failure */
> +	if (errno <= 0)
> +		errno = EINVAL;
>  	return -1;
>  }
Please explain this change a bit better.

A successful call into system library does not have to clear errno (POSIX even says "no function in ... POSIX ... shall set errno to 0"), and you do not clear errno to zero anywhere in this function either, so it looks as if you are reading an undefined errno and basing your action on that result.

Because TMP_MAX is non-zero, you are always reading from errno left by open() in the loop, so the above paragraph is a misunderstanding. But that needs to be in the log message, no?

I think you are trying to avoid stomping on the errno when we broke out of the loop early, due to getting an error. But errno is always valid at this point in this codepath, and errno.h macros shall expand to integer constant expressions with type int, distinct positive values. So I think you can safely remove the assignment without "if (errno <= 0)". Returning EINVAL from a variant of mkstemp when the error is anything but "The last six characters were not XXXXXX" is wrong.

Previous: Matthieu MoyNext: Matthieu Moy
Message 8 of 11 in “Re: [PATCH 4/4] Use git_mkstemp_mode and xmkstemp_mode in odb_mkstemp, not chmod later.”
  1. Matthieu MoyFeb 19, 2010
  2. 1/6 Add a testcase for ACL with restrictive umask.Matthieu Moy, Feb 19, 2010
  3. 2/6 Move gitmkstemps to path.cMatthieu Moy, Feb 19, 2010
  4. 3/6 git_mkstemp_mode, xmkstemp_mode: variants of gitmkstemps with mode argument.Matthieu Moy, Feb 19, 2010
  5. Junio C HamanoFeb 20, 2010
  6. 4/6 Use git_mkstemp_mode and xmkstemp_mode in odb_mkstemp, not chmod later.Matthieu Moy, Feb 19, 2010
  7. 5/6 git_mkstemps_mode: don't set errno to EINVAL for any error.Matthieu Moy, Feb 19, 2010
  8. Junio C HamanoFeb 20, 2010
  9. Matthieu MoyFeb 22, 2010
  10. Junio C HamanoFeb 22, 2010
  11. 6/6 Use git_mkstemp_mode instead of plain mkstemp to create object filesMatthieu Moy, Feb 19, 2010

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.