Linux Watchdog Daemon

Back to PSC's home page
Back to Watchdog

Building

To build the watchdog from source then copy or GIT clone from the official repository, then change in to that directory and run the commands:

autoreconf -i
./configure
cd src
make

You need to have the appropriate tools installed, I think if you use "apt-get build-dep watchdog" on a Debian/Ubuntu machine (as root or using sudo as appropriate) it installs what you need. However, it seems you may need or want some extra tools installed:

apt-get install build-essential automake libtool manpages-dev

In addition you might want to install GIT and learn how to use it to make a clone of the official version later, so that you can try code changes, etc. Typically you would do this:

apt-get install git git-gui gitk

To run that version stop any current official package with "pkill watchdog" (as root or with sudo, but do not kill with -9 or you will reboot by surprise if hardware timer is in use). Don't use the usual "service watchdog stop" as that starts the wd_keepalive daemon in its place.

Then run the compiled version with "./watchdog -c test.conf -v" where test.conf is a local copy of your normal file edited to add any special options (e.g. the temperature devices). The -v option will result in lots of syslog messages about the temperature(s) and any other checks, etc, but will help you verify it looks OK.

See also the configuration page and the command-line options on this site.
[top of page]

Debugging Options

Makefile Build Options

The Makefile created by the 5.13-era of git clone has the compile settings:

CFLAGS = -g -O2

Which enabled debug symbols (-g) and normal levels of release code optimisation (-O2). This results in a larger binary than the "as shipped" version, but in the event of needing to use gdb for debugging, there is enough information to be usable. However, this is not optimal for release or debugging/development, so you might want to manually edit the Makefile and change the above line to one of the following choices. For release only:

CFLAGS = -O2 -Wall

If you keep the '-g' option for debug symbols you can use the 'strip' command to remove them later to make the binary smaller.

For debugging:

CFLAGS = -g -O0 -DDEBUG -Wall

In this case the "-DDEBUG" option results in the fatal_error() call in logmessage.c using an asert() call to cause a core-dump if such an error message is output. This is not recommended for production use or live testing! The use of "-Wall" for picking up coding errors is also strongly recommended, even if some of the warnings are pedantic, it is worth taking a careful look at any problems it finds.

Generally to enable the core dump for analysis by gdb you need to run the following bash command before you run the daemon:

ulimit -c unlimited

[top of page]

Memory Checking - Electric Fence

In addition, you might be interested in checking for memory errors to prevent leaks slowly using up system memory. One useful tool in this respect the Electric Fence library which replaces the normal glibc memory allocation and freeing routines by ones that use the hardware virtual memory manager to enforce checking. Make sure you install this with the command:

apt-get install electric-fence

Then edit the Makefile to change the "LIBS" line to add "-lefence":

LIBS = -lrt -lefence

If the program makes a mistake with access to dynamically allocated memory then it will simply core-dump. So if testing with this option you should disable the use of the hardware watchdog (by editing the config file) or use the --no-action command line to stop it from opening /dev/watchdog even when configured to do so.
Again, this is not for production use!

[top of page]

Memory Checking - Valgrind

Another tool for solving memory access problems is 'valgrind' which runs the program under test in what is essentially a virtual machine. An example of using valgrind is given here: http://www.cprogramming.com/debugging/valgrind.html

When I ran it I used this command:

valgrind --tool=memcheck --leak-check=full --show-reachable=yes --track-origins=yes \
            ./watchdog --config-file ../watchdog.conf --verbose --foreground \
            --no-action --force --loop-exit 5

One problem with this is you can't then easily send a signal to the watchdog as it is being tested to stop it normally. To deal with this type of test the '--loop-exit' command line option was added, with the above example running for 5 intervals.

[top of page]

Last Updated on 26-Aug-2019 by Paul Crawford
Copyright (c) 2014-19 by Paul S. Crawford. All rights reserved.
Email psc(at)sat(dot)dundee(dot)ac(dot)uk
Absolutely no warranty, use this information at your own risk.