1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
From 5054e66756efb96dd6efe0aa4f7f19ccc262397b Mon Sep 17 00:00:00 2001
From: Gerrit Pape <pape@smarden.org>
Date: Fri, 2 Nov 2007 20:11:19 +0000
Subject: bug#448655: check /etc/mailname if author email is unknown
Before falling back to gethostname(), check /etc/mailname on Debian if
GIT_AUTHOR_EMAIL is not set in the environment or through config files;
only fallback if /etc/mailname cannot be opened or read.
---
ident.c | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/ident.c b/ident.c
index 9e24388..03e7d7b 100644
--- a/ident.c
+++ b/ident.c
@@ -45,6 +45,8 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
static void copy_email(const struct passwd *pw)
{
+ FILE *mailname;
+
/*
* Make up a fake email address
* (name + '@' + hostname [+ '.' + domainname])
@@ -54,7 +56,25 @@ static void copy_email(const struct passwd *pw)
die("Your sysadmin must hate you!");
memcpy(git_default_email, pw->pw_name, len);
git_default_email[len++] = '@';
- gethostname(git_default_email + len, sizeof(git_default_email) - len);
+
+ /* On Debian check /etc/mailname before using gethostname */
+ mailname = fopen("/etc/mailname", "r");
+ if (mailname && fgets(git_default_email + len,
+ sizeof(git_default_email) - len, mailname)) {
+ int l = strlen(git_default_email + len);
+ if (git_default_email[len+l] == '\n')
+ git_default_email[len+l] = 0;
+ }
+ else {
+ if (errno != ENOENT)
+ warning("unable to read /etc/mailname: %s\n",
+ strerror(errno));
+ gethostname(git_default_email + len,
+ sizeof(git_default_email) - len);
+ }
+ if (mailname)
+ fclose(mailname);
+
if (!strchr(git_default_email+len, '.')) {
struct hostent *he = gethostbyname(git_default_email + len);
char *domainname;
--
1.7.2.2
|