summaryrefslogtreecommitdiff
path: root/wrapper.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-05-21 19:10:20 -0400
committerJunio C Hamano <gitster@pobox.com>2012-05-22 09:08:20 -0700
commit2f70587502b6b5a8cfda5a3eff54392f48e2db8d (patch)
tree444e6b44d4b083958ba642b9217dacecb32ef382 /wrapper.c
parent8587ead78ad3d2af760270b21035ffe48fde3e7b (diff)
downloadgit-2f70587502b6b5a8cfda5a3eff54392f48e2db8d.tar.gz
ident: report passwd errors with a more friendly message
When getpwuid fails, we give a cute but cryptic message. While it makes sense if you know that getpwuid or identity functions are being called, this code is triggered behind the scenes by quite a few git commands these days (e.g., receive-pack on a remote server might use it for a reflog; the current message is hard to distinguish from an authentication error). Let's switch to something that gives a little more context. While we're at it, we can factor out all of the cut-and-pastes of the "you don't exist" message into a wrapper function. Rather than provide xgetpwuid, let's make it even more specific to just getting the passwd entry for the current uid. That's the only way we use getpwuid anyway, and it lets us make an even more specific error message. The current message also fails to mention errno. While the usual cause for getpwuid failing is that the user does not exist, mentioning errno makes it easier to diagnose these problems. Note that POSIX specifies that errno remain untouched if the passwd entry does not exist (but will be set on actual errors), whereas some systems will return ENOENT or similar for a missing entry. We handle both cases in our wrapper. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/wrapper.c b/wrapper.c
index 6ccd0595f4..b5e33e49c7 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -402,3 +402,15 @@ int remove_or_warn(unsigned int mode, const char *file)
{
return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
}
+
+struct passwd *xgetpwuid_self(void)
+{
+ struct passwd *pw;
+
+ errno = 0;
+ pw = getpwuid(getuid());
+ if (!pw)
+ die(_("unable to look up current user in the passwd file: %s"),
+ errno ? strerror(errno) : _("no such user"));
+ return pw;
+}