Bug 1172119

Summary: packagekit-background.cron sends empty body emails causing anacron to send error message from mail program.
Product: Red Hat Enterprise Linux 6 Reporter: Eskil Brun <eskil>
Component: PackageKitAssignee: Richard Hughes <rhughes>
Status: CLOSED ERRATA QA Contact: Desktop QE <desktop-qa-list>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.7CC: lkolacek, mnavrati, tpelka
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: PackageKit-0.5.8-25.el6 Doc Type: Bug Fix
Doc Text:
Previously, when MAILTO recipients were set in the /etc/sysconfig/packagekit-background file, the /etc/cron.daily/packagekit-background.cron script only checked for the return value from the pkcon command before trying to send email reports. As a consequence, two unnecessary empty emails were sent under certain circumstances. With this update, the $PKTMP file is not attempted to be sent by email if the files is empty, and only emails with useful information are now sent in the described scenario.
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-07-22 06:59:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
patch to ensure that the $PKTMP file is not attempted to be sent by mail if the files is empty none

Description Eskil Brun 2014-12-09 12:37:32 UTC
Created attachment 966217 [details]
patch to ensure that the $PKTMP file is not attempted to be sent by mail if the files is empty

Description of problem:

When setting MAILTO recipients in /etc/sysconfig/packagekit-background /etc/cron.daily/packagekit-background will only check for the return value from the pkcon command before trying to send email reports. In the case that the pkcon has not output any message(s) to the temporary file named by $PKTMP in the script, the mail command is invoked trying to send a null message body as a report. Anacron will also send a mail with the warning from the mail command, " 
Null message body; hope that's ok".

In short, if MAILTO is set in /etc/sysconfig/packagekit-background and if pkcon returns anything else but return value 5 (nothing useful done) and at the same time does not output any warnings or error messages, two unneccessary emails are sent. 

Version-Release number of selected component (if applicable):

PackageKit-cron-0.5.8-23.el6.x86_64

How reproducible:
Daily.

Steps to Reproduce:
1. Set MAILTO in /etc/sysconfig/packagekit-background
2. Wait
3. Two emails are sent, from /etc/cron.daily/packagekit-background and anacron. None of these carry any useful information.

Actual results:
Useless unneccessary emails are sent

Expected results:
Only email with useful info should be sent from /etc/cron.daily/packagekit-background.cron

Additional info:

patch to use bash built-in test -s to check if $PKTMP actually contains information:

--- /etc/cron.daily/packagekit-background.cron	2014-05-20 15:31:02.000000000 +0200
+++ /etc/cron.daily/packagekit-background.cron.fix	2014-12-09 13:13:48.067878542 +0100
@@ -36,13 +36,16 @@
 
 # this is when seomthing useful was done
 if [ $PKCON_RETVAL -ne 5 ]; then
+    # Do we actually have something to report? Is $PKTMP non-empty?
+    if [ -s $PKTMP ]; then 
 	# send email
 	if [ -n "$MAILTO" ]; then
-		mail -s "System updates available: $SYSTEMNAME" $MAILTO < $PKTMP
+	    mail -s "System updates available: $SYSTEMNAME" $MAILTO < $PKTMP
 	else
 		# default behavior is to use cron's internal mailing of output from cron-script
-		cat $PKTMP
+	    cat $PKTMP
 	fi
+    fi
 fi

Comment 2 Richard Hughes 2014-12-09 13:39:38 UTC
Seems logical enough to me.

Comment 5 Ladislav Kolacek 2015-04-07 17:10:04 UTC
I found and filled new similar bug: https://bugzilla.redhat.com/show_bug.cgi?id=1206196

Comment 7 errata-xmlrpc 2015-07-22 06:59:32 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-1352.html