fancontrol Error message if INTERVAL not an integer, bug if INTERVAL a negative non-integer

Bug #1572777 reported by Randy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lm-sensors (Ubuntu)
New
Undecided
Unassigned

Bug Description

Found in fancontrol 1:3.3.4-2ubuntu1 (fancontrol script Version 0.70, also exists in Version 0.71).

If the config file has an INTERVAL that's NOT an integer (found with INTERVAL=0.25) then bash's [ ] test (currently on line 77: if [ "$INTERVAL" -le 0 ] ) will fail (since -le expects integers) and output an error message, but fancontrol continues.

Fancontrol seems to work correctly with a non-integer positive INTERVAL, since "GNU `sleep' accepts arbitrary floating point numbers."

If INTERVAL is a negative non-integer (like -0.5) then the test for negative numbers will fail, fancontrol will NOT exit, but sleep will fail/crash. Fancontrol will still run, but with no sleep, using much more CPU resources/time.

Output of fancontrol with INTERVAL=0.25

    Loading configuration from /etc/fancontrol ...
    /usr/sbin/fancontrol: line 77: [: 0.25: integer expression expected

    Common settings:
      INTERVAL=0.25

    Settings for hwmon2/device/pwm3:
      Depends on hwmon2/device/temp2_input
      Controls hwmon2/device/fan3_input
      MINTEMP=30
      MAXTEMP=45
      MINSTART=150
      MINSTOP=70
      MINPWM=70
      MAXPWM=175

    Settings for hwmon2/device/pwm1:
      Depends on hwmon1/device/temp1_input
      Controls hwmon2/device/fan1_input
      MINTEMP=5
      MAXTEMP=25
      MINSTART=110
      MINSTOP=110
      MINPWM=110
      MAXPWM=255

    Enabling PWM on fans...
    Starting automatic fan control...

Output if INTERVAL=-1.5

    Loading configuration from /etc/fancontrol ...
    /usr/sbin/fancontrol: line 77: [: -1.5: integer expression expected

    Common settings:
      INTERVAL=-1.5

    Settings for hwmon2/device/pwm3:
      Depends on hwmon2/device/temp2_input
      Controls hwmon2/device/fan3_input
      MINTEMP=30
      MAXTEMP=45
      MINSTART=150
      MINSTOP=70
      MINPWM=70
      MAXPWM=175

    Settings for hwmon2/device/pwm1:
      Depends on hwmon1/device/temp1_input
      Controls hwmon2/device/fan1_input
      MINTEMP=5
      MAXTEMP=25
      MINSTART=110
      MINSTOP=110
      MINPWM=110
      MAXPWM=255

    Enabling PWM on fans...
    Starting automatic fan control...
    sleep: invalid option -- '1'
    Try 'sleep --help' for more information.
    sleep: invalid option -- '1'
    Try 'sleep --help' for more information.
    sleep: invalid option -- '1'

[sleep error repeats until fancontrol killed]

Originally found/tested in Linux Mint 17.2, package from the Ubuntu (universe) repository, but it's a bash error so should exist on any system fancontrol runs on.

Revision history for this message
Randy (xen2050) wrote :

I think I've got a fix, by changing the test for a negative number to use [[ ]] and a regex to check for only positive numbers (with or without a decimal), and not zero (matching non-zero real numbers in one regex was getting messy). Using this:

if ! [[ "$INTERVAL" != "0" && "$INTERVAL" =~ ^[0-9]+([.][0-9]+)?$ ]]

It will match non-numbers, double-decimals (2.5.3), and any negative signs, and 0. It will also match decimal numbers without a leading zero like .5 , but maybe that's good enough.

It will let fancontrol work with a floating point/decimal INTERVAL without the error message.

I'll attach a patch file for the fancontrol script (not sure if the file names/paths at the top are correct though)

(Another idea was to change the sed call when INTERVAL is assigned, but that wouldn't allow error checking/reporting)

# If earlier patch & my previous 2 comments still appear, please delete them, had errors. Delete this line too :-)

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.