Warning: iconv failed to convert degree sign

After updating the office desktop to Slackware 15.0, a system email was received every time the weekly cron jobs ran. The email contained the text line 0: warning: iconv failed to convert degree sign. There was no clue about the root cause and the email repeated the warning message four times. The email never happened previously when running Slackware 14.2 on the office desktop.

Searching the web found possible culprits such as gnuplot, s-nail/mailx, or anything that uses the iconv command from the glibc package. From the man page, the iconv command is used to “convert text from one character encoding to another.”

The gnuplot command seemed to be the likely culprit because the error message is found verbatim in the source code. In Slackware 15.0, which provides gnuplot 5.4.3, the error string is found in src/encoding.c at line 238. In Slackware 14.2, which provides gnuplot 5.0.3, the same error string is found in src/set.c at line 1638. The src/encoding.c file is new and not part of 5.0.3.

The weekly cron jobs include launching a shell script that uses gnuplot to generate four ISP speedtest plots. The four plots match the number of warnings in the email. The related data do not include the degree symbol. The sensors and hddtemp commands seem to be more appropriate suspects, but none of the weekly cron jobs use those commands.

A common problem with cron jobs is not having a full user environment. If the LANG environment variable is not defined then this kind of error message could be possible with gnuplot. Yet the environment variable LANG=en_US.UTF-8 has remained untouched between Slackware 14.2 and 15.0.

In both versions of gnuplot related language and locale environment variables are queried in src/set.c.

Not wanting to curtail troubleshooting to once a week, the /etc/cron.d/0weekly cron job was duplicated as a daily cron job for the same time of day but without the weekly limitation. The weekly cron jobs all are designed to log events and none are configured to run as background tasks. Comparing time stamps in the logs to the time stamp of the cryptic email hopefully would provide a clue.

The shell script used to create the gnuplot graphs was modified temporarily not to delete any temporary working files. The idea was to search the raw data for anything resembling degree symbols. The script was modified to send an additional email listing environment variables.

The temporary daily cron job and temporary environment variables emails showed the LANG environment variable was not defined. Yet this also would have been true under Slackware 14.2. A plausible explanation is something changed in gnuplot. Something related to the way environment variables are sourced.

To resolve the problem the following snippet was added to the beginning of the affected shell script:


    if [ "$LANG" = "" ]; then
      if [ -r /etc/profile.d/lang.sh ]; then
        . /etc/profile.d/lang.sh
      fi
    fi
    

At which point the annoying emails ceased.

The conundrum is this quirk has nothing to do with actual degree symbols.

Newer is not always better.

Problem solved but Yet Another Example why updating computers is so frustrating.

Something always breaks. Always.

Posted: Category: Usability Tagged: Slackware

Next: Exploring Desktop Environments — 8

Previous: Conky CPU Frequency Display