Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 32471 - apcupsd sends mail with an error in the headers
Summary: apcupsd sends mail with an error in the headers
Status: VERIFIED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Michael Imhof (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-11-01 08:36 UTC by Sylvain Demers
Modified: 2009-04-02 13:06 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch for my suggestions (apcupsd.patch,2.60 KB, patch)
2003-11-01 08:44 UTC, Sylvain Demers
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvain Demers 2003-11-01 08:36:39 UTC
apcupsd 3.10.5 (up to and including -r3) and 3.10.6 
 
When a power event occurs, scripts in the /etc/apcupsd directory are executed. 
Those scripts send mail, but they add an extra CRLF after the subject line of 
the headers, so we end up with something like this: 
 
  Return-Path: <root@blackbox.linux> 
  X-Original-To: black 
  Delivered-To: black@blackbox.linux 
  Received: by blackbox.linux (Postfix, from userid 0) 
  	id 81C7210CC0E; Sat,  1 Nov 2003 10:41:41 -0500 (EST) 
  Subject: blackbox.linux Power has returned 
    
  Message-Id: <20031101154141.81C7210CC0E@blackbox.linux> 
  Date: Sat,  1 Nov 2003 10:41:41 -0500 (EST) 
  From: root@blackbox.linux (root) 
  To: undisclosed-recipients:; 
 
The extra line makes the following part of the message rather than part of the 
headers, so Date, From and To are, in effect, missing. 
 
The problem comes from the scripts in /etc/apcupsd. For example, mainsback 
contains this: 
  HOSTNAME=`hostname` 
  MSG="$HOSTNAME Power has returned" 
  # 
  ( 
     echo "Subject: $MSG" 
     echo " " 
     echo "$MSG" 
     echo " " 
     /usr/sbin/apcaccess status 
  ) | $APCUPSD_MAIL $SYSADMIN 
 
(Note: the last line is $APCUPSD_MAIL -s $MSG $SYSDAMIN in 3.10.6, see below 
as it causes problems with Postfix on my system) 
 
The problem here is that the headers should be separated from the message body 
with a blank line, but the above script sends a line with a single space after 
the "Subject" line.  To correct, change to this: 
   echo "Subject: $MSG" 
   echo 
   echo "$MSG" 
 
Echo alone will output the required blank line. 
 
Also, I suggest adding the following line just before or after the subject: 
   echo "To: $SYSADMIN" 
 
This will prevent postfix/sendmail from adding "To: Undisclosed recipients" 
which in turn triggers a SpamAssassin rule. 
 
Finally, with 3.10.6, the sendmail command is called with the -s parameter to 
set the subject. Postfix doesn't seem to like this and thus fails to send the 
mail. Is this required for SendMail? If so, maybe we could add a parameter 
somewhere so that this switch isn't used when using Postfix. Or we could have 
the Postfix team just ignore that switch! :) 
 

Reproducible: Always
Steps to Reproduce:
Comment 1 Sylvain Demers 2003-11-01 08:44:54 UTC
Created attachment 20062 [details, diff]
Patch for my suggestions

Note: this is the first time I create a patch, so I'd like somebody to check
if
it's done ok first.

I made a directory called "old" with the original files and a "new" directory
with my modified files, the called "diff -u old new > apcupsd.patch".

I tried applying patches with "patch -p1 < apcupsd.patch" while in the
/etc/apcupsd directory, and it seems to work.

This patch removes the changes 'echo " "' to 'echo', adds a "To" line and
removes the -s switch to the sendmail command because Postfix doesn't like
it.
Comment 2 Scott Taylor (RETIRED) gentoo-dev 2003-11-01 11:02:01 UTC
qmail will not even send any email when the -s "$MSG" is in the command line.
Isn't that redundant anyway since the message itself contains the "Subject:"
header? I'm all in favor of adding more complete headers too.

Please! strip the -s "$MSG" from the scripts, and while you're at it, copy
or symlink the /etc/apcupsd/onbattery to also run as /etc/apcupsd/powerout
- apparently different models send different signals for a power failure.
Comment 3 Michael Imhof (RETIRED) gentoo-dev 2003-11-01 12:04:30 UTC
I checked in an corrected ebuild (the 3.10.6.ebuild one) with
-the patch and with
-ln -s onbattery powerout.

Please check if everything is fine.
Comment 4 Scott Taylor (RETIRED) gentoo-dev 2003-11-01 13:06:45 UTC
Thanks! It peacefully coexists with qmail now. After several simulated power
outages, I actually got one onbattery alert (the first one I've ever seen
here) but it never missed the powerout alerts. This closes #30716 as well.

Here's the scripts that actually got called. Getting an occasional extra
email updating the status from powerout to onbattery is far better in my
book than getting a mystery email that power has returned without having
a power failure to match it up with...
/etc/apcupsd/powerout BERTHOUD 1 0
/etc/apcupsd/mainsback BERTHOUD 1 0
/etc/apcupsd/powerout BERTHOUD 1 0
/etc/apcupsd/mainsback BERTHOUD 1 0
/etc/apcupsd/powerout BERTHOUD 1 0
/etc/apcupsd/onbattery BERTHOUD 1 0
/etc/apcupsd/mainsback BERTHOUD 1 0

Comment 5 Sylvain Demers 2003-11-01 15:30:24 UTC
I'm happy with that! Case closed as far as I'm concerned!

Thanks!
Comment 6 Michael Imhof (RETIRED) gentoo-dev 2003-11-02 02:30:14 UTC
Good news for me :)

I closes #30716 and will close this one now.
Thanks for your testing. Feel free to report any other bugs you find within
apcupsd.