"Update April 2012

Ubuntu versions 12.04 and up includes a more recent version of thinkfan (0.7.3-1) which should not need this patch.

Introduction

Due to Ubuntu bug #751689 and Debian bug 610722 your ThinkPad can easily overheat and do an emergency shutdown. To fix this, you can use the thinkfan daemon to control your fan speeds. Unfortunately, it comes with a bug (at the time of writing) and it actually slows down your fan when it should be at full speed. Here's how to patch the Ubuntu package.

Ubuntu and Debian are known to be affected, including Debian Squeeze, Ubuntu 9.10, 10.04, 10.10, 11.04 and 11.10. At the time of writing a fix was released upstream 0.7.3 on 2011-09-20, but it wasn't yet incorporated in the stable release channel of Debian/Ubuntu. Rather than upgrading to 0.7.3 which might introduce other bugs, this is how to patch the stable version shipped with your OS.

Heads up!

In order to download, patch and build the new thinkfan package, you don't have to become root. Only when installing the the required packages for building (and the resulting package), you need to be root.

Prerequisites

First, install the packages we need to be able to compile the package.

sudo apt-get install debhelper build-essential dpkg-dev
sudo apt-get build-dep thinkfan

In the last part we will build a Debian/Ubuntu package.

Download source and patch

Now, somewere in your homedir, create a directory to work in. I chose ~/thinkfan and start working in here:

mkdir ~/thinkfan; cd ~/thinkfan

Download the original Ubuntu package (yes, we apt-get as user):

apt-get source thinkfan

You should end up with similar files:

drwxrwxr-x  4 gert gert  4096 2011-10-01 18:26 thinkfan-0.7.1
-rw-rw-r--  1 gert gert  8326 2010-08-12 23:05 thinkfan_0.7.1-2.diff.gz
-rw-rw-r--  1 gert gert  1124 2010-08-12 23:05 thinkfan_0.7.1-2.dsc
-rw-rw-r--  1 gert gert 21413 2010-08-12 23:05 thinkfan_0.7.1.orig.tar.gz

Now change the file thinkfan-0.7.1/system.c with this patch:

--- thinkfan-0.7.1.orig/system.c
+++ thinkfan-0.7.1/system.c
@@ -83,7 +83,7 @@
        else {
                if (unlikely(cur_lvl == INT_MIN)) strcpy(buf, "level disengaged\n");
                else snprintf(buf, 10, "level %d\n", cur_lvl);
-               if (unlikely(write(ibm_fan, buf, 8) != 8)) {
+               if (unlikely(write(ibm_fan, buf, strlen(buf)) != strlen(buf))) {
                        showerr(IBM_FAN);
                        message(LOG_ERR, MSG_ERR_FANCTRL);
                        errcnt++;

Basically, the hardcoded length of 8 of the string buf is now variable. This fixes the issue that level 127 is cut to level 1 and actually slows down the fan instead of getting it to the highest level.

You can either apply this patch manually by editing the file on line 86, or apply it with patch.

Updating the changelog

Before we can build a new package, it is mandatory to update the changelog with an entry explaining what's changed. It will be used to update more metadata as well including the version number. That is important for the package manager to identify this as a new version.

The changelog file is located in thinkfan-0.7.1/debian/changelog. Prepend the following (example):

thinkfan (0.7.1-2+gert) unstable; urgency=high

* patch from debian bug #610722 applied

-- Gert van Dijk <gert@gertvandijk.net>  Wed, 25 May 2011 19:10:00 +0200

Note the exact formatting of the entry (the package builder is very strict in its checks) and the version number suffix.

Building patched version

Now we move to the actual source directory:

cd thinkfan-0.7.1

And start building the package:

dpkg-buildpackage

After some time of compiling and packaging, we should have the following file in the original working directory (one level lower):

drwxrwxr-x  4 gert gert  4096 2011-10-01 18:40 thinkfan-0.7.1
-rw-rw-r--  1 gert gert  8326 2010-08-12 23:05 thinkfan_0.7.1-2.diff.gz
-rw-rw-r--  1 gert gert  1124 2010-08-12 23:05 thinkfan_0.7.1-2.dsc
-rw-rw-r--  1 gert gert  1250 2011-10-01 18:40 thinkfan_0.7.1-2+gert_amd64.changes
-rw-r--r--  1 gert gert 34308 2011-10-01 18:40 thinkfan_0.7.1-2+gert_amd64.deb
-rw-rw-r--  1 gert gert  8640 2011-10-01 18:40 thinkfan_0.7.1-2+gert.diff.gz
-rw-rw-r--  1 gert gert   898 2011-10-01 18:40 thinkfan_0.7.1-2+gert.dsc
-rw-rw-r--  1 gert gert 21413 2010-08-12 23:05 thinkfan_0.7.1.orig.tar.gz

Et voilà: we have thinkfan_0.7.1-2+gert_amd64.deb!

Installing the package

Install it using dpkg:

sudo dpkg -i thinkfan_0.7.1-2+gert_amd64.deb

Don't forget to configure thinkfan.

See also

Share on: TwitterHacker NewsFacebookLinkedInRedditEmail


Related Posts


Published

Last Updated

Category

Miscellaneous

Tags

Connect with me on...