Git development
 help / color / mirror / Atom feed
* [PATCH] Use /etc/mailname for the hostname part of the email address.
@ 2007-07-07  2:21 Matt Kraai
  2007-07-07  2:54 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Kraai @ 2007-07-07  2:21 UTC (permalink / raw)
  To: git; +Cc: Matt Kraai, Matt Kraai

From: Matt Kraai <kraai@asturias.ftbfs.org>

/etc/mailname contains the hostname to be used on outgoing email
messages generated locally on Debian systems (cf.
http://www.debian.org/doc/debian-policy/ch-customized-programs.html).
If it available, use it instead of gethostname or gethostbyname.

Signed-off-by: Matt Kraai <kraai@ftbfs.org>
---

	If this is only appropriate for the Debian package, I
	apologize.  Please let me know if this is the case and I'll
	submit it to the Debian maintainer.

 ident.c |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/ident.c b/ident.c
index 6612d17..3d05ae2 100644
--- a/ident.c
+++ b/ident.c
@@ -43,6 +43,27 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
 
 }
 
+static int getmailname(char *name, size_t len)
+{
+	FILE *f = fopen("/etc/mailname", "r");
+	int i;
+
+	if (!f)
+		return -1;
+	if (!fgets(name, len, f)) {
+		fclose(f);
+		return -1;
+	}
+	fclose(f);
+	for (i = 0; !isspace(name[i]); i++)
+		;
+	if (name[i - 1] != '.')
+		name[i] = '\0';
+	else
+		name[i - 1] = '\0';
+	return 0;
+}
+
 static void copy_email(const struct passwd *pw)
 {
 	/*
@@ -54,7 +75,10 @@ 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);
+	if (getmailname(git_default_email + len,
+			sizeof(git_default_email) - len) < 0)
+		gethostname(git_default_email + len,
+			    sizeof(git_default_email) - len);
 	if (!strchr(git_default_email+len, '.')) {
 		struct hostent *he = gethostbyname(git_default_email + len);
 		char *domainname;
-- 
1.5.2.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-07-07  6:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-07  2:21 [PATCH] Use /etc/mailname for the hostname part of the email address Matt Kraai
2007-07-07  2:54 ` Linus Torvalds
2007-07-07  6:07   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox