[yum-cvs] yum-updatesd yum-updatesd-helper

Jeremy Katz katzj at linux.duke.edu
Mon Nov 26 16:17:09 UTC 2007


 yum-updatesd        |    3 +++
 yum-updatesd-helper |   25 +++++++++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)

New commits:
commit 9215d03dacf2e68ac18c5746eafa5e407d3288df
Author: Pierre Ossman <drzeus-bugzilla at drzeus.cx>
Date:   Mon Nov 26 11:13:54 2007 -0500

    Make yum-updatesd use sendmail (rh#397711)
    
    Almost every other program sends reports by calling /usr/bin/sendmail to the
    address "root". yum-updatesd, however, requires a SMTP server to submit its
    mail, something that usually also requires domain-decorated names.
    
    This patch allows yum-updatesd to submit mail reports using /usr/bin/sendmail
    like any other system monitoring program. The old code path is still there and
    is controlled by the value "use_sendmail" in the configuration.

diff --git a/yum-updatesd b/yum-updatesd
index edbe217..5faa6a5 100755
--- a/yum-updatesd
+++ b/yum-updatesd
@@ -57,6 +57,7 @@ class UDConfig(BaseConfig):
     email_to = ListOption(["root"])
     email_from = Option("root")
     smtp_server = Option("localhost:25")
+    use_sendmail = BoolOption(True)
     dbus_listener = BoolOption(True)
     do_update = BoolOption(False)
     do_download = BoolOption(False)
@@ -170,6 +171,8 @@ def checkUpdates(opts, wait = False):
         args.extend(["--email", "--email-from=%s" %(opts.email_from,),
                      "--email-to=%s" %(string.join(opts.email_to, ","),),
                      "--smtp-server=%s" %(opts.smtp_server)])
+        if opts.use_sendmail:
+            args.append("--sendmail")
     if "syslog" in opts.emit_via:
         args.extend(["--syslog", "--syslog-level=%s" %(opts.syslog_level,),
                      "--syslog-facility=%s" %(opts.syslog_facility,),
diff --git a/yum-updatesd-helper b/yum-updatesd-helper
index ad97c28..22b658c 100755
--- a/yum-updatesd-helper
+++ b/yum-updatesd-helper
@@ -26,6 +26,7 @@ from optparse import OptionParser
 from email.MIMEText import MIMEText
 import socket
 import rfc822
+import subprocess
 
 
 import yum
@@ -137,11 +138,12 @@ class SyslogUpdateEmitter(UpdateEmitter):
 
 
 class EmailUpdateEmitter(UpdateEmitter):
-    def __init__(self, sender, rcpts, smtp_server):
+    def __init__(self, sender, rcpts, smtp_server, sendmail):
         UpdateEmitter.__init__(self)        
         self.sender = sender
         self.rcpts = rcpts
         self.smtp_server = smtp_server
+        self.sendmail = sendmail
 
     def _msgGreeting(self):
         output = """Hi,
@@ -170,13 +172,18 @@ Your Computer
         msg['To'] = self.rcpts
         msg['Date'] = rfc822.formatdate()
 
-        s = smtplib.SMTP()
-        if self.smtp_server:
-            s.connect(self.smtp_server)
+        if self.sendmail:
+            p = subprocess.Popen("/usr/bin/sendmail", stdin=subprocess.PIPE)
+            p.stdin.write(str(msg))
+            p.communicate()
         else:
-            s.connect()
-        s.sendmail(self.sender, self.rcpts.split(','), msg.as_string())
-        s.close()
+            s = smtplib.SMTP()
+            if self.smtp_server:
+                s.connect(self.smtp_server)
+            else:
+                s.connect()
+            s.sendmail(self.sender, self.rcpts.split(','), msg.as_string())
+            s.close()
 
     def updatesAvailable(self, updateInfo):
         num = len(updateInfo)
@@ -334,7 +341,8 @@ class UpdatesDaemon(yum.YumBase):
         if self.options.email:
             self.emitters.append(EmailUpdateEmitter(self.options.emailfrom,
                                                     self.options.emailto,
-                                                    self.options.smtpserver))
+                                                    self.options.smtpserver,
+                                                    self.options.sendmail))
         if self.options.syslog:
             self.emitters.append(SyslogUpdateEmitter(self.options.logfacility,
                                                      self.options.logident,
@@ -588,6 +596,7 @@ def main(options = None):
         parser.add_option("", "--email-from", type="string", default="root", dest="emailfrom")
         parser.add_option("", "--email-to", type="string", default="root", dest="emailto")                
         parser.add_option("", "--smtp-server", type="string", default="localhost:25", dest="smtpserver")
+        parser.add_option("", "--sendmail", action="store_true", default=False, dest="sendmail")
         
         (options, args) = parser.parse_args()
 



More information about the Yum-cvs-commits mailing list