Search code examples
linuxcentosmmaprrdtoolbus-error

rrdtool gives bus error when an attempt is made to create an rrd database


I'm having problems getting rrdtool (version 1.4.8) create a database on my system (x86_64 CentOS 4.1, kernel 2.6.18.128, and ext3 filesystem type).

I tried running a simple command to create a database as shown this tutorial, but I get a SIGBUS error and it seems to be related to memcpy(). I've shown the backtrace from gdb below.

(gdb) run create test.rrd --start 920804400 DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:1:24 RRA:AVERAGE:0.5:6:10
Starting program: rrdtool-1.4.8/src/.libs/rrdtool create test.rrd --start 920804400 DS:speed:COUNTER:600:U:U RRA:AVERAGE:0.5:1:24 RRA:AVERAGE:0.5:6:10
(no debugging symbols found)

Program received signal SIGBUS, Bus error.
0x00002acb298da7d3 in memcpy () from /lib64/tls/libc.so.6
(gdb) bt
#0  0x00002b46e74ae7d3 in memcpy () from /lib64/tls/libc.so.6
#1  0x00002b46e731d612 in rrd_write (rrd_file=0x1c46e230, buf=0x1c46e0a0, count=128) at rrd_open.c:716
#2  0x00002b46e731515e in rrd_create_fn (file_name=0x7fffc38b9a3f "test.rrd", rrd=0x7fffc38b8b60) at rrd_create.c:727
#3  0x00002b46e7314a28 in rrd_create_r (filename=0x7fffc38b9a3f "test.rrd", pdp_step=300, last_up=920804400, argc=3, argv=0x7fffc38b9070) at rrd_create.c:580
#4  0x00002b46e731330e in rrd_create (argc=7, argv=0x7fffc38b9050) at rrd_create.c:113
#5  0x00000000004028db in HandleInputLine (argc=8, argv=0x7fffc38b9048, out=0x2b46e766a680) at rrd_tool.c:646
#6  0x00000000004023a2 in main (argc=8, argv=0x7fffc38b9048) at rrd_tool.c:521
(gdb) up
#1  0x00002b46e731d612 in rrd_write (rrd_file=0x1c46e230, buf=0x1c46e0a0, count=128) at rrd_open.c:716
716     memcpy(rrd_simple_file->file_start + rrd_file->pos, buf, count);
(gdb) p rrd_file->pos
$21 = 0
(gdb) p (char *)buf
$25 = 0x1c46e0a0 "RRD"
(gdb) p rrd_simple_file->file_start
$22 = 0x2b46ea64b000 "RRD"
(gdb) p count
$23 = 128

What is the problem here and how do I fix it?


Solution

  • This problem may be related to some mmap bug of your old Centos distribution.
    If upgrading to a newer version is not an option, you could try to compile your rrdtool with the following option:

    ./configure --disable-mmap
    

    By doing so, the faulty memcpy at line 716 in the rrd_write() function (shown below) should not be executed:

    /* Write count bytes from buffer buf to the current position
     * rrd_file->pos of rrd_simple_file->fd.
     * Returns the number of bytes written or <0 on error.  */
    
    ssize_t rrd_write(
        rrd_file_t *rrd_file,
        const void *buf,
        size_t count)
    {
        rrd_simple_file_t *rrd_simple_file = (rrd_simple_file_t *)rrd_file->pvt;
    #ifdef HAVE_MMAP
        size_t old_size = rrd_file->file_len;
        if (count == 0)
            return 0;
        if (buf == NULL)
            return -1;      /* EINVAL */
    
        if((rrd_file->pos + count) > old_size)
        {
            rrd_set_error("attempting to write beyond end of file");
            return -1;
        }
        memcpy(rrd_simple_file->file_start + rrd_file->pos, buf, count);
        rrd_file->pos += count;
        return count;       /* mimmic write() semantics */
    #else
        ssize_t   _sz = write(rrd_simple_file->fd, buf, count);
    
        if (_sz > 0)
            rrd_file->pos += _sz;
        return _sz;
    #endif
    }