[rrd-developers] threadsafe problems
Christian Magnusson
mag at mag.cx
Thu Feb 3 18:50:20 CET 2011
I try to use librrd in a multithreaded application, and it seems like
most/all functions at not thread-safe due to getopt().
I use rrdcached which handle all rrd-files separately, and I mostly use
librrd to execute command to the destination "--daemon 127.0.0.1".
Below you can find some stack-trace where two threads of my threads call
rrd_flushcached() at the same time, and it ends up with seg-fault.
Would it be necessary to protect all getopt() calls with a mutex inside
librrd to get rid of the problem, or do you have any other good idea?
/Christian
(gdb) bt
#0 0x00007fe4e1e0dc90 in strlen () from /lib/libc.so.6
#1 0x00007fe4e1e0d9c6 in strdup () from /lib/libc.so.6
#2 0x00007fe4e3d4b3f4 in rrd_flushcached (argc=4, argv=0x7fe4c4ff8e70)
at rrd_flushcached.c:54
#3 0x00000000004542a6 in flush_cached (file=<value optimized out>)
at controller_rrd.c:338
#4 0x0000000000454999 in xport_sensor_values (
sensor_ids=<value optimized out>, num_sensors=1, start=0x7fe4c4ff8fa0,
end=0x7fe4c4ff8f98, step=0x7fe4c4ff8f90, data=0x7fe4c4ff8f88)
at controller_rrd.c:433
#5 0x0000000000448c29 in Read_Sensor_Log_Handler (hd=0x42a5070,
cm=0x7fe4c4ff9020) at sensor.c:433
#6 0x0000000000425491 in DataHandler (v=0x7fe4c57fa000) at data.c:327
#7 0x00007fe4e21063ba in start_thread () from /lib/libpthread.so.0
#8 0x00007fe4e1e7302d in clone () from /lib/libc.so.6
#9 0x0000000000000000 in ?? ()
(gdb) frame 2
#2 0x00007fe4e3d4b3f4 in rrd_flushcached (argc=4, argv=0x7fe4c4ff8e70)
at rrd_flushcached.c:54
54 opt_daemon = strdup (optarg);
(gdb) print optarg
$1 = 0x0
(gdb) print argv
$2 = (char **) 0x7fe4c4ff8e70
(gdb) print argv[0]
$4 = 0x45898b ""
(gdb) print argv[1]
$5 = 0x45d657 "--daemon"
(gdb) print argv[2]
$6 = 0x45b533 "127.0.0.1"
(gdb) print argv[3]
$7 = 0x42bb710 "rrd/00_26_18_5C_F8_6D_10000_OSB1_0_SUN2.rrd"
(gdb) print argc
$10 = 4
(gdb) frame 3
#3 0x00000000004542a6 in flush_cached (file=<value optimized out>)
at controller_rrd.c:338
338 if (rrd_flushcached(argc, argv) != 0) {
(gdb) print file
$11 = <value optimized out>
(gdb) print argv
$12 = {0x45898b "", 0x45d657 "--daemon", 0x45b533 "127.0.0.1",
0x42bb710 "rrd/00_26_18_5C_F8_6D_10000_OSB1_0_SUN2.rrd"}
(gdb) print argc
No symbol "argc" in current context.
Thread 27 (process 26521):
#0 0x00007fe4e1e64ffb in write () from /lib/libc.so.6
#1 0x00007fe4e1e0087a in _IO_file_write () from /lib/libc.so.6
#2 0x00007fe4e1e01759 in _IO_do_write () from /lib/libc.so.6
#3 0x00007fe4e1e01098 in _IO_file_sync () from /lib/libc.so.6
#4 0x00007fe4e1df5262 in fflush () from /lib/libc.so.6
#5 0x00007fe4e3d53698 in request (buffer=<value optimized out>,
buffer_size=<value optimized out>, ret_response=0x7fe4c47f5dc8)
at rrd_client.c:324
#6 0x00007fe4e3d53c41 in rrdc_flush (filename=0x45898b "") at
rrd_client.c:679
#7 0x00007fe4e3d4b495 in rrd_flushcached (argc=4, argv=<value optimized
out>)
at rrd_flushcached.c:92
#8 0x00000000004542a6 in flush_cached (file=<value optimized out>)
at controller_rrd.c:338
#9 0x0000000000454999 in xport_sensor_values (
sensor_ids=<value optimized out>, num_sensors=1, start=0x7fe4c47f7fa0,
end=0x7fe4c47f7f98, step=0x7fe4c47f7f90, data=0x7fe4c47f7f88)
at controller_rrd.c:433
#10 0x0000000000448c29 in Read_Sensor_Log_Handler (hd=0x7fe4c8014750,
cm=0x7fe4c47f8020) at sensor.c:433
#11 0x0000000000425491 in DataHandler (v=0x7fe4c6ffd000) at data.c:327
#12 0x00007fe4e21063ba in start_thread () from /lib/libpthread.so.0
#13 0x00007fe4e1e7302d in clone () from /lib/libc.so.6
#14 0x0000000000000000 in ?? ()
Thread 1 (process 26522):
#0 0x00007fe4e1e0dc90 in strlen () from /lib/libc.so.6
#1 0x00007fe4e1e0d9c6 in strdup () from /lib/libc.so.6
#2 0x00007fe4e3d4b3f4 in rrd_flushcached (argc=4, argv=0x7fe4c4ff8e70)
at rrd_flushcached.c:54
#3 0x00000000004542a6 in flush_cached (file=<value optimized out>)
at controller_rrd.c:338
#4 0x0000000000454999 in xport_sensor_values (
sensor_ids=<value optimized out>, num_sensors=1, start=0x7fe4c4ff8fa0,
end=0x7fe4c4ff8f98, step=0x7fe4c4ff8f90, data=0x7fe4c4ff8f88)
at controller_rrd.c:433
#5 0x0000000000448c29 in Read_Sensor_Log_Handler (hd=0x42a5070,
cm=0x7fe4c4ff9020) at sensor.c:433
#6 0x0000000000425491 in DataHandler (v=0x7fe4c57fa000) at data.c:327
#7 0x00007fe4e21063ba in start_thread () from /lib/libpthread.so.0
#8 0x00007fe4e1e7302d in clone () from /lib/libc.so.6
#9 0x0000000000000000 in ?? ()
__________ Information fran ESET NOD32 Antivirus, version av
virussignaturdatabas 5843 (20110203) __________
Meddelandet har kontrollerats av ESET NOD32 Antivirus.
http://www.esetscandinavia.com
More information about the rrd-developers
mailing list