Cron sends mails with ASCII charset while running tasks in UTF-8
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cron (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
Seeing that #140896 is closed and fixed, I'm rereporting this bug here for Trusty (and earlier).
https:/
This issue is that:
(A) The cron daemon starts with no LANG (LANG=C)
(B) The processes start with the lang environment from /etc/default/locale (LANG=en_US.UTF-8)
Now the processes will print stuff like:
rm: cannot remove ‘abc’ <-- note the non-ascii characters, because it has LANG=...UTF-8
But the cron mail with that error, will use:
Content-Type: text/plain; charset=
instead of:
Content-Type: text/plain; charset=UTF-8
That causes mail clients to get UTF-8 while it is told that it gets ASCII, resulting in a crappy reading experience.
A working fix for me is to add the LANG variable to /etc/init/cron.conf so the cron process gets
# echo 'env LANG=en_US.UTF-8' > /etc/init/
# stop cron; start cron
(Or alternately, the CONTENT_TYPE= setting in crontab as suggested in https:/
I believe this bug got introduced by using upstart instead of the init script:
- the processes get the environment from /etc/pam.d/cron (LANG=en_US.UTF-8)
- cron gets the environment from /etc/default/locale BUT ONLY if it was started from /etc/init.d/cron. the upstart script does not load /etc/environment nor /etc/default/
.. so .. that should probably mean that this is a ubuntu/cron bug, not an ubuntu/+source/cron bug.
And it first starts showing in Trusty because the tools use fancier tokens when unicode is available:
ubuntu precise:
# locale | grep ^LANG=; rm /tmp/abc
LANG=
rm: cannot remove `/tmp/abc': No such file or directory
ubuntu trusty
# locale | grep ^LANG=; rm /tmp/abc
LANG=
rm: cannot remove ‘/tmp/abc’: No such file or directory <-- see the fancy quotes here
Cheers,
Walter Doekes
OSSO B.V.
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04 LTS
Release: 14.04
Codename: trusty
# dpkg -l cron | grep ^ii
ii cron 3.0pl1-124ubuntu2
tags: | added: trusty |
The attached patch lp1321227- cron_does_ not_read_ default_ locale. patch is a workaround that loads /etc/default/locale like it should.
With upstart, this was the best I could do. And it's not great.
- expect doesn't take more than 2 forks
- there is no way to load /etc/default/locale without hardcoding its values or using a script
(While working on this I had the joys of kernel panics with upstart, but that's a different matter.)