diff options
author | Rob Austein <sra@hactrn.net> | 2012-05-09 13:25:55 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2012-05-09 13:25:55 +0000 |
commit | 9383dbe4d8826b94b48f7bb162e313207bc05de6 (patch) | |
tree | 7e15beb61e84f38649d6a0ded581355d6d33c3ae | |
parent | 4cc0c85d84818fee822ff5be9f3d79d0ecfa83b0 (diff) |
Fail gracefully if we can't initialize or write to DeadDrop mailbox.
svn path=/trunk/; revision=4480
-rw-r--r-- | rpkid/rpki/config.py | 4 | ||||
-rw-r--r-- | rpkid/rpki/x509.py | 28 |
2 files changed, 22 insertions, 10 deletions
diff --git a/rpkid/rpki/config.py b/rpkid/rpki/config.py index f0129573..bba4a62c 100644 --- a/rpkid/rpki/config.py +++ b/rpkid/rpki/config.py @@ -249,11 +249,15 @@ class parser(object): try: rpki.x509.XML_CMS_object.dump_outbound_cms = rpki.x509.DeadDrop(self.get("dump_outbound_cms")) + except OSError, e: + rpki.log.warn("Couldn't initialize mailbox %s: %s" % (self.get("dump_outbound_cms"), e)) except ConfigParser.NoOptionError: pass try: rpki.x509.XML_CMS_object.dump_inbound_cms = rpki.x509.DeadDrop(self.get("dump_inbound_cms")) + except OSError, e: + rpki.log.warn("Couldn't initialize mailbox %s: %s" % (self.get("dump_inbound_cms"), e)) except ConfigParser.NoOptionError: pass diff --git a/rpkid/rpki/x509.py b/rpkid/rpki/x509.py index 955b8d97..d6981b12 100644 --- a/rpkid/rpki/x509.py +++ b/rpkid/rpki/x509.py @@ -1380,19 +1380,27 @@ class DeadDrop(object): """ def __init__(self, name): - self.maildir = mailbox.Maildir(name, factory = None, create = True) + self.name = name self.pid = os.getpid() + self.maildir = mailbox.Maildir(name, factory = None, create = True) + self.warned = False def dump(self, obj): - now = time.time() - msg = email.mime.application.MIMEApplication(obj.get_DER(), "x-rpki") - msg["Date"] = email.utils.formatdate(now) - msg["Subject"] = "Process %s dump of %r" % (self.pid, obj) - msg["Message-ID"] = email.utils.make_msgid() - msg["X-RPKI-PID"] = str(self.pid) - msg["X-RPKI-Object"] = repr(obj) - msg["X-RPKI-Timestamp"] = "%f" % now - self.maildir.add(msg) + try: + now = time.time() + msg = email.mime.application.MIMEApplication(obj.get_DER(), "x-rpki") + msg["Date"] = email.utils.formatdate(now) + msg["Subject"] = "Process %s dump of %r" % (self.pid, obj) + msg["Message-ID"] = email.utils.make_msgid() + msg["X-RPKI-PID"] = str(self.pid) + msg["X-RPKI-Object"] = repr(obj) + msg["X-RPKI-Timestamp"] = "%f" % now + self.maildir.add(msg) + self.warned = False + except OSError, e: + if not self.warned: + rpki.log.warn("Could not write to mailbox %s: %e" % (self.name, e)) + self.warned = True class XML_CMS_object(CMS_object): """ |