Cron sends mails with ASCII charset while running tasks in UTF-8

Bug #1321227 reported by Walter
54
This bug affects 11 people
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://bugs.launchpad.net/ubuntu/+source/cron/+bug/140896

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=ANSI_X3.4-1968

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/cron.override
    # stop cron; start cron

(Or alternately, the CONTENT_TYPE= setting in crontab as suggested in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=410057 )

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/locale.

.. 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=en_US.UTF-8
    rm: cannot remove `/tmp/abc': No such file or directory

    ubuntu trusty
    # locale | grep ^LANG=; rm /tmp/abc
    LANG=en_US.UTF-8
    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

Revision history for this message
Walter (wdoekes) wrote :

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.)

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "lp1321227-cron_does_not_read_default_locale.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
tags: added: trusty
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in cron (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.