Related
I have a multithread application which accesses a DB from multiple thread, and randomically I fall in this error (not the same query)...
__GI___libc_free (mem=0x7fff00042660) at /build/glibc-vjB4T1/glibc-2.28/malloc/malloc.c:3093
QList<_RData>::node_destruct (this=0x7fffebffce08, from=0x7fffe4037fc0, to=0x7fffe4037fd8) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:494
QList<_RData>::dealloc (this=0x7fffebffce08, data=0x7fffe4037fb0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:865
QList<_RData>::~QList (this=0x7fffebffce08) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:827
QList<_RData>::operator= (this=0x55555565cd68, other=#0x7fffebffd880: {<QListSpecialMethods<_RoomData>> = {<No data fields>}, {p = {static shared_null = {ref = {atomic = {_q_value = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = -1}, <No data fields>}}}, alloc = 0, begin = 0, end = 0, array = {0x0}}, d = 0x7ffff6ff76c0 <QListData::shared_null>}, d = 0x7ffff6ff76c0 <QListData::shared_null>}}) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:159
AMProcess::doActionAM (this=0x55555565cc30) at /smart/software/AudioIO/AMProcess.cpp:453
QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (AMProcess::*)()>::call(void (AMProcess::*)(), AMProcess*, void**) (f=(void (AMProcess::*)(AMProcess * const)) 0x5555555b943c <AMProcess::doActionAM()>, o=0x55555565cc30, arg=0x7fffebffee40) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:134
QtPrivate::FunctionPointer<void (AMProcess::*)()>::call<QtPrivate::List<>, void>(void (AMProcess::*)(), AMProcess*, void**) (f=(void (AMProcess::*)(AMProcess * const)) 0x5555555b943c <AMProcess::doActionAM()>, o=0x55555565cc30, arg=0x7fffebffee40) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:167
QtPrivate::QSlotObject<void (AMProcess::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) (which=1, this_=0x555555661cf0, r=0x55555565cc30, a=0x7fffebffee40, ret=0x0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:396
QMetaObject::activate(QObject*, int, int, void**) () at null:
QThread::started(QThread::QPrivateSignal) () at null:
?? () at null:
start_thread (arg=<optimized out>) at /build/glibc-vjB4T1/glibc-2.28/nptl/pthread_create.c:486
clone () at /build/glibc-vjB4T1/glibc-2.28/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
This is some snippets of my code
rData = DBRManager::ReadRData("R", m_connName);
if (rData.size() > 0) {
}
...and this is the query
QList<_RData> DBRManager::ReadRData(QString tbName, QString dbName)
{
QList<_RData> records;
QSqlQuery query(QSqlDatabase::database(dbName));
query.setForwardOnly(true);
query.exec("DSQLITE_THREADSAFE=2");
query.exec("SELECT * FROM " + tbName);
while (query.next()) {
_RData data;
data.id = query.value("id").toInt();
data.type = query.value("type").toInt();
records.append(data);
}
query.finish();
return records;
}
Some pieces of my code crash randomly when call push_back or erase on std::list, the code is in a long time runing service . I removed the unimportant part and just keep the most relevant.
std::list<RxCCPReport> pendingSync;
size_t AnchorConnection::HandleCCPTxReport(const char *rxBytes, size_t length) {
if (!pendingSync.empty())
{
std::list<RxCCPReport>::iterator iter = pendingSync.begin();
while (iter != pendingSync.end())
{
if (condition1)
{
iter = pendingSync.erase(iter);
}
else
{
if (condition2)
{
++iter;
}
else if (condition3)
{
++iter;
}
else
{
iter = pendingSync.erase(iter);
}
}
}
}
return length; }
size_t AnchorConnection::HandleCCPRxReport(const char *rxBytes, size_t length) {
RxCCPReport rxCCP;
rxCCP.anc = anc;
rxCCP.rxTime = ccpRxTime;
rxCCP.seqNum = pCsMsg->seqNum;
pendingSync.push_back(rxCCP);
return length;
}
The two function runs on the same thread; code will crash at pendingSync.erase(iter) or pendingSync.push_back(rxCCP) sometimes, about 1 time a week.
the backtrace:
crashed at erase
#0 std::__detail::_List_node_base::_M_unhook (this=0x7fffcc024040) at ../../../../../libstdc++-v3/src/c++98/list.cc:142
__next_node = 0x0
__prev_node = 0x7fffcc024040
#1 0x00000000004db14a in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_erase (this=0x7fffdc011970, __position=...) at /usr/include/c++/4.8.2/bits/stl_list.h:1570
__n = 0x7fffe5ffad80
#2 0x00000000004daddb in std::list<RxCCPReport, std::allocator<RxCCPReport> >::erase (this=0x7fffdc011970, __position=...) at /usr/include/c++/4.8.2/bits/list.tcc:112
__ret = <error reading variable __ret (Cannot access memory at address 0x10)>
#3 0x00000000004e3d8b in AnchorConnection::HandleCCPTxReport (this=0x7fffdc009240, rxBytes=0x7fffc4022abb "0rl\206%M/\004\205O\263\002\216\356\003\002f", length=12)
at LE/Network/rtls_anchor_conn.cpp:731
rxCCP = {rxTime = 3.1943677384753104, seqNum = 114 'r', anc = }
cSeqRxCCP = 114 'r'
cs = 0x7fffdc016430
ccpTx = 203157767788
ccpTxTime = 3.1794272052158457
pCsMsg = 0x7fffc4022abb
cSeqTxCCP = 114 'r'
crashed at push_back another time
> #0 0x00007ffff6dff387 in __GI_raise (sig=sig#entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
resultvar = 0
pid = 5068
selftid = 5418
#1 0x00007ffff6e00a78 in __GI_abort () at abort.c:90
save_stage = 2
act = {__sigaction_handler = {sa_handler = 0x7ffff6ddb76d, sa_sigaction = 0x7ffff6ddb76d}, sa_mask = {__val = {5, 140737336646961, 3, 140737043728478, 2,
140737336643303, 1, 140737336652017, 3, 140737043728452, 12, 140737336652021, 2, 140737043729264, 140737043729264, 140737043731024}}, sa_flags = 16,
sa_restorer = 0x7fffe57f8d70}
sigs = {__val = {32, 0 <repeats 15 times>}}
#2 0x00007ffff6e41ed7 in __libc_message (do_abort=do_abort#entry=2, fmt=fmt#entry=0x7ffff6f54350 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/unix/sysv/linux/libc_fatal.c:196
ap = {{gp_offset = 40, fp_offset = 48, overflow_arg_area = 0x7fffe57f9260, reg_save_area = 0x7fffe57f9170}}
ap_copy = {{gp_offset = 16, fp_offset = 48, overflow_arg_area = 0x7fffe57f9260, reg_save_area = 0x7fffe57f9170}}
fd = 26
on_2 = <optimized out>
list = <optimized out>
nlist = <optimized out>
cp = <optimized out>
written = <optimized out>
#3 0x00007ffff6e483e4 in malloc_printerr (action=<optimized out>, str=0x7ffff6f54548 "malloc(): memory corruption (fast)", ptr=<optimized out>, ar_ptr=<optimized out>)
at malloc.c:4967
buf = "00007fffd8001570"
cp = <optimized out>
ar_ptr = <optimized out>
ptr = <optimized out>
str = 0x7ffff6f54548 "malloc(): memory corruption (fast)"
action = <optimized out>
#4 0x00007ffff6e4bb20 in _int_malloc (av=av#entry=0x7fffd0000020, bytes=bytes#entry=40) at malloc.c:3383
p = 0x7fffd8001560
fb = <optimized out>
pp = <optimized out>
nb = 48
idx = <optimized out>
bin = <optimized out>
victim = 0x7fffd8001560
size = <optimized out>
victim_index = <optimized out>
remainder = <optimized out>
remainder_size = <optimized out>
block = <optimized out>
bit = <optimized out>
map = <optimized out>
fwd = <optimized out>
bck = <optimized out>
errstr = <optimized out>
#5 0x00007ffff6e4e6fc in __GI___libc_malloc (bytes=40) at malloc.c:2905
ar_ptr = 0x7fffd0000020
victim = <optimized out>
hook = <optimized out>
#6 0x00007ffff7929ecd in operator new (sz=40) at ../../../../libstdc++-v3/libsupc++/new_op.cc:51
p = <optimized out>
#7 0x00000000004dc6f8 in __gnu_cxx::new_allocator<std::_List_node<RxCCPReport> >::allocate (this=0x7fffdc011930, __n=1) at /usr/include/c++/4.8.2/ext/new_allocator.h:104
No locals.
#8 0x00000000004dc006 in std::_List_base<RxCCPReport, std::allocator<RxCCPReport> >::_M_get_node (this=0x7fffdc011930) at /usr/include/c++/4.8.2/bits/stl_list.h:334
No locals.
#9 0x00000000004db699 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_create_node<RxCCPReport const&> (this=0x7fffdc011930)
at /usr/include/c++/4.8.2/bits/stl_list.h:502
__p = 0x0
#10 0x00000000004db1c2 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::_M_insert<RxCCPReport const&> (this=0x7fffdc011930, __position=...)
at /usr/include/c++/4.8.2/bits/stl_list.h:1561
__tmp = 0x0
#11 0x00000000004dae68 in std::list<RxCCPReport, std::allocator<RxCCPReport> >::push_back (this=0x7fffdc011930, __x=...) at /usr/include/c++/4.8.2/bits/stl_list.h:1016
No locals.
#12 0x00000000004e475b in AnchorConnection::HandleCCPRxReport (this=0x7fffdc01be90, rxBytes=0x7fffd004d7fb "1{\212\211D\021\006\061+\b\250\256i\227#ԺF(ú\002\005\003o\200#",
length=88) at LE/Network/rtls_anchor_conn.cpp:936
rxCCP = {rxTime = 4.3416058279497198, seqNum = 123 '{', anc = 0x7fffdc016320}
prevSeqNum = 122 'z'
master = 0x7fffdc0101a0
cs = 0x7fffdc016450
masterID = 588618078431250826
logNum = 45794088
pCsMsg = 0x7fffe57f9500
ccpRx = 277418192552
ccpRxTime = 4.3416058279497198
txTime = "0000000000\000\334\377\177\000\000\177\236", <incomplete sequence \345>
temp = "\000\000\000\000"
diagMsg2 = "0F000005036F8040001000000412C8A607120000086000BC07390AD806130000040000FC0114000005F9FF0700731500000EA8AE699740D4BA740800EC69974025000010A604C3FB4C07A3F7520743FE260538072E100002EF022700280491FE1F6D2E100"...
csmsg = {type = 49 '1', seqNum = 123 '{', masterID = "\212\211D\021\006\061+\b", csRxTime = "\250\256i\227#", {firstPath16 = 47828, firstPath = "Ժ"},
extLen = 70 'F', {
ext = "(ú\002\005\003o\200#\000\022Ȧ\a`\000\274\a9\n\330\006\000\000\374\001\371\377\a\000s\250\256i\227#Ժt\b\000\354i\227#\000\246\004\303\373L\a\243\367R\aC\376&\005\070\a\357\002\221\376\037m?\021", {{logNum32 = 45794088, logNum = "(ú\002"},
diagnostics = "\005\003o\200#\000\022Ȧ\a`\000\274\a9\n\330\006\000\000\374\001\371\377\a\000s\250\256i\227#Ժt\b\000\354i\227#\000\246\004\303\373L\a\243\367R\aC\376&\005\070\a\357\002\221\376\037m?\021"}}}
FP = 747
rxTime = "409769AEA8\000\345\377\177\000\000Н", <incomplete sequence \345>
I was nearly mad, any suggestion appreciated
Code that receive data over socket is as follows:
#define FRAME_HEADER_LEN (6)
#define FRAME_DATA_IDX (3)
virtual void Run()
{
unsigned int length = 0;
std::string rxBytes;
bool msgProcess;
uint8_t fcode;
unsigned int flen = 0;
while (shutdown_select_anc(socket) != -1)
{
int count = socket->ReceiveData();
if (count <= 0) // Something failed. Socket is probably closed.
{
break;
}
length += count;
rxBytes.append(socket->buf_, count);
/*
* the data coming from the anchor is framed:
*<STX><LENlsb><LENmsb><DATA:<FC><XX>.....><CRClsb><CRCmsb><ETX>
* STX = 0x2
* LEN is the length of data message(16 bits)
* CRC is the 16 - bit CRC of the data bytes
* ETX = 0x3
* FC = is the function code (API code)
*/
if (length <= FRAME_HEADER_LEN) //minimum length is 7 bytes (header + 1 byte function code)
{
continue;
}
do {
msgProcess = false;
crc_err_t pckt_crc = CRC_ERROR;
//search through the received data to find the start of frame
while (length > FRAME_HEADER_LEN)
{
if ((rxBytes.c_str())[0] == 0x2) //this is the start - check if length and end match
{
uint8_t hi = (rxBytes.c_str())[2];
uint8_t lo = (rxBytes.c_str())[1];
flen = lo + ((uint16_t)hi << 8);
if ((flen + FRAME_HEADER_LEN) > length) //we don't have all the frame yet
{
break;
}
if ((rxBytes.c_str())[flen + 5] == 0x3) //end of frame present
{
//received whole frame: check frame checksum here
pckt_crc = check_crc16((uint8_t *)&(rxBytes.c_str())[3], (flen + 2));
break;
}
else //no end of frame in the expected place - start byte was not real start
{
rxBytes.erase(0, 1);
length -= 1;
}
}
else //remove the byte and check if next is a start of frame
{
rxBytes.erase(0, 1);
length -= 1;
}
}
//check if we have a frame
if (((flen + FRAME_HEADER_LEN) > length) || (length <= FRAME_HEADER_LEN))
{
break;
}
if (pckt_crc != CRC_OKAY)
{
//frame packet fully received but it's CRC bad
DBG_PRINTF(DBG_DEFAULT, "ACHTUNG ACHTUNG : incompatible software without CRC or network CRC error\n");
//let incompatible software proceed at the moment
}
fcode = (rxBytes.c_str())[FRAME_DATA_IDX]; //get function code
typename std::map<uint8_t, std::pair<size_t, handler> >::iterator it = handlers.find(fcode);
if (it != handlers.end()) //we have found a handler for this function code
{
if (flen >= it->second.first)
{
handler f = it->second.second;
size_t n = (static_cast<Child*>(this)->*f)(&((rxBytes.c_str())[FRAME_DATA_IDX]), flen );
if (n > 0)
{
msgProcess = true;
rxBytes.erase(0, n + FRAME_HEADER_LEN);
length -= (unsigned int)(n + FRAME_HEADER_LEN);
}
else
{
//Unexpected Message
rxBytes.clear();
length = 0;
}
}
}
else
{
rxBytes.clear();
length = 0;
}
} while((length > 0) && msgProcess);
}
socket->Close();
}
In the push_back case you have
str = 0x7ffff6f54548 "malloc(): memory corruption (fast)"
Suggests that you have an memory corruption elsewhere, most likely shortly before calling HandleCCPRxReport.
I have a program which reads a 10 MByte file and processes the data as the data is being read in 4K chunks. The test usually takes 1 min - 2 min. But there are some instances when the program takes more than 10 min, at which point the test it killed and a core is generated. Following is the code that reads the file:
string filename("data.out");
ifstream ifs;
vector<char> buf(4096);
ifs.open(filename, ios::in | ios::binary);
if (!ifs.is_open()) {
cout << "ERROR : " << filename << "can't be opened." << endl;
VERIFY(ifs.is_open());
}
while (!ifs.eof()) {
ifs.read(buf.data(), buf.size()); <======== Line 1
process_data (buf.data(), ifs.gcount()); <======== Line 2
}
ifs.close();
I have two cores that show the program is stuck at Line 1 and Line 2.
Top of bt of core1 at Line 1:
#0 0x00007f942a462175 in std::istream::read (this=0x7fff4ce69de0,
__s=0x9120000 "\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324\324"..., __n=4096) at /home/packages/gcc/4.7/w/gcc-4.7-4.7.2/build/x86_64-linux-gnu/libstdc++-v3/include/bits/istream.tcc:651
Top of bt of core2 at Line 2:
#0 0x00000000004375f3 in std::__addressof<char> (__r=#0x7fa3176391a6: -128 '\200') at /usr/include/c++/4.7/bits/move.h:47
#1 0x0000000000436cd4 in std::vector<char, std::allocator<char> >::data (this=0x7fff346ad770)
at /usr/include/c++/4.7/bits/stl_vector.h:859
Initially, from core1, I thought the issue was with ifs.read() taking a long time. But after the second core, I am thinking the issue might be related to vector::data().
Is there a way I can tell if any part of the file has been read, by inspecting certain fields (e.g file offset) stored in ifstream.
I don't like posting dump of large structure, but here it is if someone can shed some light how I can figure out from this dump how much of the 10MB has been read.
(gdb) p ifs
$3 = warning: can't find linker symbol for virtual table for `std::basic_ifstream<char, std::char_traits<char> >' value
{
<std::basic_istream<char, std::char_traits<char> >> = {
<std::basic_ios<char, std::char_traits<char> >> = {
<std::ios_base> = {
_vptr.ios_base = 0xfbfcc0,
static boolalpha = std::_S_boolalpha,
static dec = std::_S_dec,
static fixed = std::_S_fixed,
static hex = std::_S_hex,
static internal = std::_S_internal,
static left = std::_S_left,
static oct = std::_S_oct,
static right = std::_S_right,
static scientific = std::_S_scientific,
static showbase = std::_S_showbase,
static showpoint = std::_S_showpoint,
static showpos = std::_S_showpos,
static skipws = std::_S_skipws,
static unitbuf = std::_S_unitbuf,
static uppercase = std::_S_uppercase,
static adjustfield = std::_S_adjustfield,
static basefield = std::_S_basefield,
static floatfield = std::_S_floatfield,
static badbit = std::_S_badbit,
static eofbit = std::_S_eofbit,
static failbit = std::_S_failbit,
static goodbit = std::_S_goodbit,
static app = std::_S_app,
static ate = std::_S_ate,
static binary = std::_S_bin,
static in = std::_S_in,
static out = std::_S_out,
static trunc = std::_S_trunc,
static beg = std::_S_beg,
static cur = std::_S_cur,
static end = std::_S_end,
_M_precision = 6,
_M_width = 0,
_M_flags = 4098,
_M_exception = std::_S_goodbit,
_M_streambuf_state = 5,
_M_callbacks = 0x0,
_M_word_zero = {
_M_pword = 0x0,
_M_iword = 0
},
_M_local_word = {{
_M_pword = 0x0,
_M_iword = 0
}, {
_M_pword = 0x0,
_M_iword = 0
}, {
_M_pword = 0x0,
_M_iword = 0
}, {
_M_pword = 0x0,
_M_iword = 0
}, {
_M_pword = 0x0,
_M_iword = 0
}, {
_M_pword = 0x0,
_M_iword = 0
}, {
_M_pword = 0x0,
_M_iword = 0
}, {
_M_pword = 0x0,
_M_iword = 0
}},
_M_word_size = 8,
_M_word = 0x7fff4ce69f20,
_M_ios_locale = {
static none = 0,
static ctype = 1,
static numeric = 2,
static collate = 4,
static time = 8,
static monetary = 16,
static messages = 32,
static all = 63,
_M_impl = 0x7f942a6e3aa0,
static _S_classic = 0x7f942a6e3aa0,
static _S_global = 0x7f942a6e3aa0,
static _S_categories = 0x7f942a6c86a0,
static _S_once = 2
}
},
members of std::basic_ios<char, std::char_traits<char> >:
_M_tie = 0x0,
_M_fill = 0 '\000',
_M_fill_init = false,
_M_streambuf = 0x7fff4ce69df0,
_M_ctype = 0x7f942a6e3d20,
_M_num_put = 0x7f942a6e4040,
_M_num_get = 0x7f942a6e4030
},
members of std::basic_istream<char, std::char_traits<char> >:
_vptr.basic_istream = 0xfbfc98,
_M_gcount = 0
},
members of std::basic_ifstream<char, std::char_traits<char> >:
_M_filebuf = warning: can't find linker symbol for virtual table for `std::basic_filebuf<char, std::char_traits<char> >' value
{
<std::basic_streambuf<char, std::char_traits<char> >> = {
_vptr.basic_streambuf = 0xfc0a70,
_M_in_beg = 0x6306000 "\317\317\317\......320\320\320\320"...,
_M_in_cur = 0x6307fff "",
_M_in_end = 0x6307fff "",
_M_out_beg = 0x0,
_M_out_cur = 0x0,
_M_out_end = 0x0,
_M_buf_locale = {
static none = 0,
static ctype = 1,
static numeric = 2,
static collate = 4,
static time = 8,
static monetary = 16,
static messages = 32,
static all = 63,
_M_impl = 0x7f942a6e3aa0,
static _S_classic = 0x7f942a6e3aa0,
static _S_global = 0x7f942a6e3aa0,
static _S_categories = 0x7f942a6c86a0,
static _S_once = 2
}
},
members of std::basic_filebuf<char, std::char_traits<char> >:
_M_lock = {
__data = {
__lock = 0,
__count = 0,
__owner = 0,
__nusers = 0,
__kind = 0,
__spins = 0,
__list = {
__prev = 0x0,
__next = 0x0
}
},
__size = '\000' <repeats 39 times>,
__align = 0
},
_M_file = {
_M_cfile = 0x70186c0,
_M_cfile_created = true
},
_M_mode = 12,
_M_state_beg = {
__count = 0,
__value = {
__wch = 0,
__wchb = "\000\000\000"
}
},
_M_state_cur = {
__count = 0,
__value = {
__wch = 0,
__wchb = "\000\000\000"
}
},
_M_state_last = {
__count = 0,
__value = {
__wch = 0,
__wchb = "\000\000\000"
}
},
_M_buf = 0x6306000 "\317\317\317\317\317\......320\320\320\320\320"...,
_M_buf_size = 8192,
_M_buf_allocated = true,
_M_reading = true,
_M_writing = false,
_M_pback = 0 '\000',
_M_pback_cur_save = 0x0,
_M_pback_end_save = 0x0,
_M_pback_init = false,
_M_codecvt = 0x7f942a6e3f60,
_M_ext_buf = 0x0,
_M_ext_buf_size = 0,
_M_ext_next = 0x0,
_M_ext_end = 0x0
}
}
(gdb)
Thank you,
Ahmed.
Do not loop on eof.
while (ifs.read(buf.data(), buf.size())) {
size_t read = ifs.gcount();
if(read==0) break; // don't trust passing `0` to `process_data`:
process_data(buf.data(), read);
if (read<buf.size()) break; // if we finished, end.
}
Finding the end of input is best done by attempting io, and noticing something went wrong. In this case, we read, count how many bytes we read, and when we read 0 bytes or have read fewer bytes than we expected to read, we decide there isn't any more data to come.
We also end if any failbit has been set on ifs by the IO operation.
any help ? using confbridge,conf as confbridge is way making conference same as meetme.conf
**=====================================================================
Asterisk-11.5.1 Centos6 app_confbridge.c
=====================================================================
APP: MyConfbridgeCount(Confbridgename,variablename)
it will return no of user in conference if conference is created or else zero.
Task: Using Dailplan user want to retrive no of user in conference
'6050' =>
1. Verbose(3,"testMyConfbridgeCount") [pbx_config]
2. MyConfbridgeCount(4000,count) [pbx_config]
3. verbose(3,"== ${count} ====") [pbx_config]
======================================================================
issue:Currently asterisk core dumped as soon as app2 load .
I want to load module as after join confbridge by any user , using MyConfbridgeCount() to know no of conference user count .
file: app/app_confbrige.c**
==========================================================================
partial code of app_confbridge.c:
=========================================================================
static const char *const app2 ="MyConfbridgeCount";
static int count_exec(struct ast_channel *chan, const char *data)
{
int res = 0;
struct conference_bridge *conf=NULL;
int count;
char *localdata;
char val[80] = "0";
struct ao2_iterator i;
//struct conference_bridge *bridge = NULL;
struct conference_bridge tmp;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(confno);
AST_APP_ARG(varname);
);
ast_verb(3,"\n============Inside count_exec =============\n");
if ( ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "MyConfbrigeCount requires an argument (conference number)\n");
ast_verb(3, "\n MyConfbrigeCount requires an argument (conference number\n ");
return -1;
}
if (!ao2_container_count(conference_bridges)) {
ast_verb(3, "No active conferences.");
ast_log(LOG_NOTICE, "No active conferences.");
return -1;
}
if (!(localdata = ast_strdupa(data))){
return -1;
}
AST_STANDARD_APP_ARGS(args, localdata);
ast_copy_string(tmp.name, args.confno, sizeof(tmp.name));
conf = ao2_find(conference_bridges, &tmp, OBJ_POINTER);
if (conf) {
ao2_lock(conf);
count = conf->markedusers;
ao2_unlock(conf);
}else{
count = 0;
}
if (!ast_strlen_zero(args.varname)) {
snprintf(val, sizeof(val), "%d", count);
pbx_builtin_setvar_helper(chan, args.varname, val);
} else {
if ( ast_channel_state(chan)!= AST_STATE_UP) {
ast_answer(chan);
}
res = ast_say_number(chan, count, "",ast_channel_language(chan),(char *) NULL);
}
return res;
}
static int load_module(void)
{
ast_verb(3 ,"==Inside load_module==");
res |= ast_register_application_xml(app2,count_exec);
return res;
}
static int unload_module(void)
{
res |= ast_unregister_application(app2);
return res;
}
static struct ast_cli_entry cli_confbridge[] = {
AST_CLI_DEFINE(count_exec, "MyConfbrigdeCount Show Number of adminUser(s) in Conference." ),
}
============core dump=================================================
Program terminated with signal 11, Segmentation fault.
#0 __strlen_ia32 () at ../sysdeps/i386/i586/strlen.S:56
56 cmpb %dh, (%eax) /* is byte NUL? *
(gdb) bt
#0 __strlen_ia32 () at ../sysdeps/i386/i586/strlen.S:56
#1 0x00c1b4df in _IO_vfprintf_internal (s=0xfffffffe, format=<value optimized out>, ap=<value optimized out>) at vfprintf.c:1641
#2 0x00c409f0 in _IO_vsnprintf (string=0x835af1c "\374 -- \n======== inside count_exec == data is at address:[0xbf918b64] data:[nnel)\n", maxlen=<value optimized out>,
format=0xbf9175c0 "\374 -- \n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n",
args=0xbf917724 "d\213\221\277\376\377\377\377\213\261\065\b") at vsnprintf.c:120
#3 0x081a0f94 in __ast_str_helper (buf=0xbf9176a8, max_len=0, append=0,
fmt=0xbf9175c0 "\374 -- \n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n",
ap=0xbf917724 "d\213\221\277\376\377\377\377\213\261\065\b") at strings.c:76
#4 0x081b17d0 in ast_str_set_va (buf=0xbf9176a8, max_len=0,
fmt=0xbf9175c0 "\374 -- \n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n",
ap=0xbf917724 "d\213\221\277\376\377\377\377\213\261\065\b") at /usr/src/My-asterisk/asterisk-11.5.1/include/asterisk/strings.h:803
#5 0x08134a6f in __ast_verbose_ap (file=0xe1ca74 "app_confbridge.c", line=2453, func=0xe20652 "count_exec", level=3, callid=0x0,
fmt=0xbf9175c0 "\374 -- \n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n",
ap=0xbf917724 "d\213\221\277\376\377\377\377\213\261\065\b") at logger.c:1818
#6 0x08134b0b in __ast_verbose (file=0xe1ca74 "app_confbridge.c", line=2453, func=0xe20652 "count_exec", level=3,
fmt=0xe1da30 "\n======== inside count_exec == data is at address:[%p] data:[%s] ", '=' <repeats 11 times>, "\n") at logger.c:1836
#7 0x00e09a45 in count_exec (chan=0xe23c18, data=0xfffffffe <Address 0xfffffffe out of bounds>) at app_confbridge.c:2453
#8 0x080d40eb in __ast_cli_register (e=0xe23c18, ed=0x0) at cli.c:2118
#9 0x080d4459 in ast_cli_register (e=0xe23c18) at cli.c:2178
#10 0x080d4482 in ast_cli_register_multiple (e=0xe237a0, len=13) at cli.c:2189
#11 0x00e11f7d in load_module () at app_confbridge.c:4771
#12 0x0812ba89 in start_resource (mod=0x87fa908) at loader.c:845
#13 0x0812c45c in load_resource_list (load_order=0xbf918e90, global_symbols=0, mod_count=0xbf918e88) at loader.c:1045
#14 0x0812ca5a in load_modules (preload_only=0) at loader.c:1198
#15 0x080895f7 in main (argc=4, argv=0xbf91a3a4) at asterisk.c:4180
As i underestand you created NEW application MyConfbridgeCount,right?
And you are not voip nor c++ expert.
If so, recommended way is use GROUP functions to calculate number of channels BEFORE confbridge. That can be done via pure dialplan.
Creating c/c++ app require very carefull coding and multithreaded debugging(which is extreamly complex thing).
If you realy care what is your error - your error is sending to printf function incorrect address of string.
My program appears to run just fine most of the time, but occasionally I get a segmentation fault.
boost version = 1.41.0
running on RHEL 4
compiled with GCC 3.4.6
Backtrace:
#0 0x08138546 in boost::asio::detail::posix_fd_set_adapter::is_set (this=0xb74ed020, descriptor=-1)
at /home/scottl/boost_1_41_0/boost/asio/detail/posix_fd_set_adapter.hpp:57
__result = -1 'ÿ'
#1 0x0813e1b0 in boost::asio::detail::reactor_op_queue::perform_operations_for_descriptors (this=0x97f3b6c, descriptors=#0xb74ed020, result=#0xb74ecec8)
at /home/scottl/boost_1_41_0/boost/asio/detail/reactor_op_queue.hpp:204
op_iter = {_M_node = 0xb4169aa0}
i = {_M_node = 0x97f3b74}
#2 0x081382ca in boost::asio::detail::select_reactor::run (this=0x97f3b08, block=true)
at /home/scottl/boost_1_41_0/boost/asio/detail/select_reactor.hpp:388
read_fds = {fd_set_ = {fds_bits = {16, 0 }}, max_descriptor_ = 65}
write_fds = {fd_set_ = {fds_bits = {0 }}, max_descriptor_ = -1}
retval = 1
lock = { = {}, mutex_ = #0x97f3b1c, locked_ = true}
except_fds = {fd_set_ = {fds_bits = {0 }}, max_descriptor_ = -1}
max_fd = 65
tv_buf = {tv_sec = 0, tv_usec = 710000}
tv = (timeval *) 0xb74ecf88
ec = {m_val = 0, m_cat = 0x81f2c24}
sb = { = {}, blocked_ = true, old_mask_ = {__val = {0, 0, 134590223,
3075395548, 3075395548, 3075395464, 134729792, 3075395360, 135890240, 3075395368, 134593920, 3075395544, 135890240,
3075395384, 134599542, 3020998404, 135890240, 3075395400, 134614095, 3075395544, 4, 3075395416, 134548135, 3021172996,
4294967295, 3075395432, 134692921, 3075395504, 0, 3075395448, 134548107, 3021172992}}}
#3 0x0812eb45 in boost::asio::detail::task_io_service >::do_one (this=0x97f3a70,
lock=#0xb74ed230, this_idle_thread=0xb74ed240, ec=#0xb74ed2c0)
at /home/scottl/boost_1_41_0/boost/asio/detail/task_io_service.hpp:260
more_handlers = false
c = {lock_ = #0xb74ed230, task_io_service_ = #0x97f3a70}
h = (boost::asio::detail::handler_queue::handler *) 0x97f3aa0
polling = false
task_has_run = true
#4 0x0812765f in boost::asio::detail::task_io_service >::run (this=0x97f3a70,
ec=#0xb74ed2c0) at /home/scottl/boost_1_41_0/boost/asio/detail/task_io_service.hpp:103
ctx = { = {}, owner_ = 0x97f3a70, next_ = 0x0}
this_idle_thread = {wakeup_event = { = {}, cond_ = {__c_lock = {
__status = 0, __spinlock = 22446}, __c_waiting = 0x2bd7,
__padding = "\000\000\000\000×+\000\000\000\000\000\000×+\000\000\000\000\000\000\204:\177\t\000\000\000", __align = 0},
signalled_ = true}, next = 0x0}
lock = { = {}, mutex_ = #0x97f3a84, locked_ = false}
n = 11420
#5 0x08125e99 in boost::asio::io_service::run (this=0x97ebbcc) at /home/scottl/boost_1_41_0/boost/asio/impl/io_service.ipp:58
ec = {m_val = 0, m_cat = 0x81f2c24}
s = 8
#6 0x08154424 in boost::_mfi::mf0::operator() (this=0x9800870, p=0x97ebbcc)
at /home/scottl/boost_1_41_0/boost/bind/mem_fn_template.hpp:49
No locals.
#7 0x08154331 in boost::_bi::list1 >::operator(), boost::_bi::list0> (this=0x9800878, f=#0x9800870, a=#0xb74ed337)
at /home/scottl/boost_1_41_0/boost/bind/bind.hpp:236
No locals.
#8 0x081541e5 in boost::_bi::bind_t, boost::_bi::list1 > >::operator() (this=0x9800870) at /home/scottl/boost_1_41_0/boost/bind/bind_template.hpp:20
a = {}
#9 0x08154075 in boost::detail::thread_data, boost::_bi::list1 > > >::run (this=0x98007a0)
at /home/scottl/boost_1_41_0/boost/thread/detail/thread.hpp:56
No locals.
#10 0x0816fefd in thread_proxy () at /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/locale_facets.tcc:2443
__ioinit = {static _S_refcount = , static _S_synced_with_stdio = }
---Type to continue, or q to quit---
typeinfo for common::RuntimeException = {}
typeinfo name for common::RuntimeException = "N6common16RuntimeExceptionE"
#11 0x00af23cc in start_thread () from /lib/tls/libpthread.so.0
No symbol table info available.
#12 0x00a5c96e in __init_misc () from /lib/tls/libc.so.6
No symbol table info available.
Without seeing the code in question, I can only guess, but I've had asio crash on several occasions due to the object whose method has been passed (via boost::bind) to asio has been deleted before asio calls the method.