Bug 140012 - Error in sysutils/heartbeat 2.1.4_3, find_interface_bsd
Error in sysutils/heartbeat 2.1.4_3, find_interface_bsd
Status: Closed FIXED
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s)
Any Any
: Normal Affects Only Me
Assigned To: Boris Samorodov
Depends on:
  Show dependency treegraph
Reported: 2009-10-27 10:10 UTC by mark.round
Modified: 2009-11-16 09:00 UTC (History)
0 users

See Also:

file.diff (538 bytes, patch)
2009-10-27 10:10 UTC, mark.round
no flags Details | Diff
heartbeat-140012.diff.txt (644 bytes, text/plain; charset=US-ASCII)
2009-10-31 16:10 UTC, ports
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description mark.round 2009-10-27 10:10:03 UTC
I am using the heartbeat-2.1.4_3 package, built from ports. There is a problem with the /usr/local/etc/ocf/resource.d/heartbeat/IPaddr script. Inside this file, there is a find_interface_bsd function, which contains a typo in a regex. 

The end result is that it returns true for an IP address, even if it's only a partial match (a substring match). This means that in some circumstances, heartbeat will not start, with an error similar to the following :

2009/10/25_10:20:48 CRITICAL: Resource IPaddr:: is active, and should not be!
2009/10/25_10:20:48 CRITICAL: Non-idle resources can affect data integrity!

Fix: This is a problem with the way find_interface_bsd parses the output of ifconfig. By adding a space to the end of the regex, it only then finds exact matches :

Simply patch /usr/local/etc/ocf/resource.d/heartbeat/IPaddr with the following (also attached as a .txt file to this report)

*** IPaddr.orig Tue Oct 27 09:43:11 2009
--- IPaddr      Tue Oct 27 09:43:37 2009
*** 334,338 ****
                      $if_status = ( /UP/ ) ? 1 : 0;
!                 if ( /^\s+inet\s+${ip}/ ) {
                      if ( $if_status ) {
                          print $if_name;
--- 334,338 ----
                      $if_status = ( /UP/ ) ? 1 : 0;
!                 if ( /^\s+inet\s+${ip} / ) {
                      if ( $if_status ) {
                          print $if_name;

Patch attached with submission follows:
How-To-Repeat: - Install heartbeat-2.1.4_3 from ports

- Configure an IP address on an interface, e.g:

ifconfig bge0 netmask

Now try using the IPaddr script to check for the presence of an IP address that would be matched. As the faulty regex does not include a space at the end, it will return true if the IP address is a _substring_ of the configured ip address :

# /usr/local/etc/ha.d/resource.d/IPaddr status
2009/10/27_10:00:00 INFO:  Running OK
INFO:  Running OK

# /usr/local/etc/ha.d/resource.d/IPaddr status
2009/10/27_10:00:03 INFO:  Running OK
INFO:  Running OK

Neither of the or IP addresses are actually being handled by that interface, but as they are substrings of the IP address that _is_ being handled, they return true.
Comment 1 Edwin Groothuis freebsd_committer 2009-10-27 12:04:58 UTC
Maintainer of sysutils/heartbeat,

Please note that PR ports/140012 has just been submitted.

If it contains a patch for an upgrade, an enhancement or a bug fix
you agree on, reply to this email stating that you approve the patch
and a committer will take care of it.

The full text of the PR can be found at:

Edwin Groothuis via the GNATS Auto Assign Tool
Comment 2 Edwin Groothuis freebsd_committer 2009-10-27 12:05:00 UTC
State Changed
From-To: open->feedback

Awaiting maintainers feedback (via the GNATS Auto Assign Tool)
Comment 3 mark.round 2009-10-28 09:10:47 UTC
Couple of follow-up points :

- My test case had a cut'n'paste typo - I configured the interface on
bge0, but then tested it using em0. If you test this, both interfaces
should be the same.
- My alteration added a space at the end of the regex. To keep with the
original function's style, this could also be "\s+" marker (Perl
whitespsace marker, one or more times). E.g. /^\s+inet\s+${ip}\s+/
- It looks like this function was added as a patch in ports/137865.
Comment 4 ports 2009-10-31 16:10:46 UTC
Attached is an update to the current port patch located at
files/patch-resources-OCF-IPaddr.  It includes the requester's update
as well as a few updates i made to tighten up the regex matching.

Tested and it does fix the requester's problem description.

- Justin
Comment 5 ports 2009-10-31 17:23:27 UTC
I don't understand why my simple text files can never seem to show
correctly through FreeBSD's bug tool.  I send attachments just fine to
everywhere else.

Here is a paste below.

- Justin


--- files/patch-resources-OCF-IPaddr.orig       2009-08-21
03:55:41.000000000 -0500
+++ files/patch-resources-OCF-IPaddr    2009-10-31 10:02:44.000000000 -0500
@@ -41,11 +41,11 @@
 +            while (<STDIN>) {
 +                chomp();
-+                if ( /^(\w+):\s+flags=/ ) {
++                if ( /^(\w+):\sflags=/ ) {
 +                    $if_name = $1;
 +                    $if_status = ( /UP/ ) ? 1 : 0;
 +                }
-+                if ( /^\s+inet\s+${ip}/ ) {
++                if ( /^\tinet\s${ip}\s/ ) {
 +                    if ( $if_status ) {
 +                        print $if_name;
 +                        exit(0)
Comment 6 mark.round 2009-11-02 11:24:17 UTC
Great stuff. I applied your patch and rebuilt heartbeat from ports. The
patched resource gets installed properly, and I can confirm this fixes
the problem.=20
Comment 7 Boris Samorodov freebsd_committer 2009-11-16 08:20:24 UTC
Responsible Changed
From-To: freebsd-ports-bugs->bsam

Comment 8 dfilter freebsd_committer 2009-11-16 08:51:42 UTC
bsam        2009-11-16 08:51:33 UTC

  FreeBSD ports repository

  Modified files:
    sysutils/heartbeat   Makefile 
    sysutils/heartbeat/files patch-resources-OCF-IPaddr 
  . fix some regexps for ip address detection;  [1]
  PR:             ports/140012  [1]
  Submitted by:   Mark Round <mark.round at ahc.uk.com>  [1]
  Final patch by: maintainer (Justin Head <ports at encarnate.com>)  [1]
  Revision  Changes    Path
  1.23      +1 -1      ports/sysutils/heartbeat/Makefile
  1.2       +2 -2      ports/sysutils/heartbeat/files/patch-resources-OCF-IPaddr
cvs-all@freebsd.org mailing list
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 9 Boris Samorodov freebsd_committer 2009-11-16 08:51:53 UTC
State Changed
From-To: feedback->closed

Committed, thanks!