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

[PATCH] post-receive-email: do not call sendmail if no mail was generated

From
Lars Noschinski <lars@public.noschinski.de>
Date
Aug 28, 2009, 17:39 UTC
Message-ID
<1251481187-6361-1-git-send-email-lars@public.noschinski.de>

contrib/hooks/post-receive-email used to call the send_mail function (and thus, /usr/sbin/sendmail), even if generate_mail returned an error. This is problematic, as the sendmail binary provided by exim4 generates an error mail if provided with an empty input.

Therefore, this commit changes post-receive-email to only call sendmail if generate_mail returned without error.

Signed-off-by: Lars Noschinski <lars@public.noschinski.de>
---
 contrib/hooks/post-receive-email |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

Obvious drawback of this solution is that the mails are kept in memory as a whole. But the mails should be small enough, so that this does not hurt.

I'm not sure how to write a test for this bug, as the hook (correctly) uses an absolute path to call sendmail.

diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 2a66063..818a270 100755
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -684,6 +684,9 @@ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
 else
 	while read oldrev newrev refname
 	do
-		generate_email $oldrev $newrev $refname | send_mail
+		mail="$(generate_email $oldrev $newrev $refname)"
+		if [ $? -eq 0 ]; then
+			printf '%s' "$mail" | send_mail
+		fi
 	done
 fi
-- 
1.6.3.3
Next: Lars Noschinski
Message 1 of 3 in “post-receive-email: do not call sendmail if no mail was generated”
  1. post-receive-email: do not call sendmail if no mail was generatedLars Noschinski, Aug 28, 2009
  2. Lars NoschinskiSep 8, 2009
  3. Junio C HamanoSep 8, 2009

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.