Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/index.php/Reporting_Bug_Guidelines

Do NOT report bugs when a package is just outdated, or it is in Unsupported. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#49809 - [smartmontools] needs "User=root" in systemd service unit for email notifications with s-nail

Attached to Project: Arch Linux
Opened by Christopher Singley (csingley) - Wednesday, 22 June 2016, 17:26 GMT
Last edited by Doug Newgard (Scimmia) - Thursday, 23 June 2016, 05:35 GMT
Task Type Bug Report
Category Upstream Bugs
Status Assigned
Assigned To Giovanni Scafora (giovanni)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 1
Private No

Details

Description: Contrary to the documentation in the Arch wiki for S.M.A.R.T., it is not possible simply to configure core/s-nail to deliver email warnings generated by smartd. This is because the [Service] stanza in the smartd.service unit file neglects to set "User=root". As a result, $HOME remains unset in smartd's environment. When the daemon invokes /usr/bin/mail, s-nail cannot find ~/.mailrc, it remains unconfigured, and mail service fails.

The cleanest fix for this is to add "User=root" to the [Service] stanza in /usr/lib/systemd/system/smartd.service, which should have no undesirable side effects.

Other possible solutions are:
1. Patch /usr/share/smartmontools/smartd_warning.sh in order to add "export HOME=~". Maintaining such a patch seems undesirable when upstream's code is correct and the bug is internal to Arch's distribution package.
2. Change the wiki documentation and ask users to set all login information in /etc/mail.rc . This is obviously a terrible idea - poor security, inflexible (especially in a multi-user environment) and destined to be clobbered by package updates.
3. Ask users to configure /etc/smartd.conf to override the default "mail" command with a nonstandard wrapper script that sets $HOME before calling /usr/bin/mail. This seems cumbersome and obscure (at odds with upstream's own excellent documentation).

So if we want smartmontools to work with s-nail, I think we need to patch the smartd.service unit file.


Additional info:
* extra/smartmontools 6.5-1
* core/s-nail 14.8.8-1

Steps to reproduce:
1. Create a config for root user at /root/.mailrc. Verify it's working by using /usr/bin/mail to send a test email as root.

2. Install smartmontools and configure /etc/smartd.conf to include "-m someuser@somedomain.tld -M test".

3. systemctl start smartd.

4. Observe the delivery failure of the test email. Note that `journalctl -xe -u smartd` shows that mail delivery fails with the error message from s-nail "No mail for root".

5. Edit /usr/lib/systemd/system/smartd.service to include [Service]\nUser=root. Repeat steps 1-3 above, and observe the successful mail delivery.

Thank you!
This task depends upon

Comment by Dave Reisner (falconindy) - Wednesday, 22 June 2016, 17:32 GMT
> The cleanest fix for this is to add "User=root" to the [Service] stanza in /usr/lib/systemd/system/smartd.service, which should have no undesirable side effects.
It should have no effect of any kind. System services already run as the root user.
Comment by Christopher Singley (csingley) - Wednesday, 22 June 2016, 17:36 GMT
The service runs as the root user, but absent a declaration in the service unit, $HOME remains unset.

"$USER, $LOGNAME, $HOME, $SHELL

User name (twice), home directory, and the login shell. The variables are set for the units that have User= set, which includes user systemd instances. See passwd(5)."

http://0pointer.de/public/systemd-man/systemd.exec.html#Environment%20variables%20in%20spawned%20processes

So for operations which rely on $HOME being set (such as s-nail with ~/.mailrc), the User needs to be set in the unit file.

I can verify that setting User=root resolves the bug I am reporting. Try it out and see.

Thanks.
Comment by Gerardo Exequiel Pozzi (djgera) - Thursday, 23 June 2016, 04:32 GMT
or just set MAILRC= ;)

> the bug is internal to Arch's distribution package.

service file is provided by upstream.
Comment by Christopher Singley (csingley) - Thursday, 23 June 2016, 15:49 GMT
Should I report upstream then?
Comment by Gerardo Exequiel Pozzi (djgera) - Thursday, 23 June 2016, 22:21 GMT
Yes, also .service file uses a really old-age and non-existent syslog.target. In any case, seting MAILRC is just sufficient, like for other services, for example apcupsd.

Loading...