From 8a58792df28b311240280a40538a4711bc44946a Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Fri, 2 Nov 2007 20:11:19 +0000 Subject: [PATCH 1/3] 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.0.3