summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhmeland1999-07-01 14:31:30 +0000
committerhmeland1999-07-01 14:31:30 +0000
commit42c4de31ebf4e8926e64171948142afb0babb5e6 (patch)
tree78afc60ca0fe02613eadfd36f9aed2d23b4f5ada
parent706a475b6c4cbbd89086ec548a25224c55a1b511 (diff)
downloadmailman-42c4de31ebf4e8926e64171948142afb0babb5e6.tar.gz
mailman-42c4de31ebf4e8926e64171948142afb0babb5e6.tar.zst
mailman-42c4de31ebf4e8926e64171948142afb0babb5e6.zip
DeliverToUser(): I believe the forking done in here is no longer
needed. For now, however (trying to move towards 1.0), I've merely reduced the amount of work done in the child, and wrapped it in a try: clause for catching fork() failures.
-rw-r--r--Mailman/Utils.py54
1 files changed, 34 insertions, 20 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py
index ca734135f..31bf852bc 100644
--- a/Mailman/Utils.py
+++ b/Mailman/Utils.py
@@ -137,6 +137,12 @@ def DeliverToUser(msg, recipient, add_headers=[]):
Optional argument add_headers should be a list of headers to be added
to the message, e.g. for Errors-To and X-No-Archive."""
+ # HM: I don't think the deadlock comment below really applies
+ # anymore (because we now send mail with SMTP, not by invoking some
+ # binary). Thus the forking should probably go away (eventually,
+ # i.e. when we're sure that won't break stuff). For now, trying to
+ # approach 1.0, I've only moved the forking down a bit.
+ #
# We fork to ensure no deadlock. Otherwise, even if sendmail is
# invoked in forking mode, if it eg detects a bad address before
# forking, then it will try deliver to the errorsto addr *in the
@@ -144,28 +150,36 @@ def DeliverToUser(msg, recipient, add_headers=[]):
# that is doing the send - and holding a lock - then the delivery will
# hang pending release of the lock - deadlock.
- if not os.fork():
- # child
- sender = msg.GetSender()
- try:
- try:
- msg.headers.remove('\n')
- except ValueError:
- pass
- if not msg.getheader('to'):
- msg.headers.append('To: %s\n' % recipient)
- for i in add_headers:
- if i and i[-1] != '\n':
- i = i + '\n'
- msg.headers.append(i)
+ sender = msg.GetSender()
+ try:
+ msg.headers.remove('\n')
+ except ValueError:
+ pass
+ if not msg.getheader('to'):
+ msg.headers.append('To: %s\n' % recipient)
+ if not msg.getheader('date'):
+ msg.SetDate()
+ for i in add_headers:
+ if i and i[-1] != '\n':
+ i = i + '\n'
+ msg.headers.append(i)
- text = string.join(msg.headers, '')+ '\n'+ QuotePeriods(msg.body)
- import OutgoingQueue
- queue_id = OutgoingQueue.enqueueMessage(sender, recipient, text)
- TrySMTPDelivery(recipient,sender,text,queue_id)
- finally:
- os._exit(0)
+ text = string.join(msg.headers, '') + '\n' + QuotePeriods(msg.body)
+ import OutgoingQueue
+ queue_id = OutgoingQueue.enqueueMessage(sender, recipient, text)
+ # If the fork (or anything the child does) fails and raises an
+ # exception, e.g. due to memory exhaustion, the queue runner
+ # will pick up the queue file.
+ try:
+ if not os.fork():
+ # child
+ try:
+ TrySMTPDelivery(recipient,sender,text,queue_id)
+ finally:
+ os._exit(0)
+ except:
+ OutgoingQueue.deferMessage(queue_id)
def TrySMTPDelivery(recipient, sender, text, queue_entry):
import socket