On Jan 5, 5:43*pm, cerr <ron.egg...@gmail.com> wrote:
> On Jan 5, 2:30*pm, cerr <ron.egg...@gmail.com> wrote:
>
>
>
> > On Jan 5, 1:23*pm, David Resnick <lndresn...@gmail.com> wrote:
>
> > > On Jan 5, 2:40*pm, cerr <ron.egg...@gmail.com> wrote:
>
> > > > Hi There,
>
> > > > My daemon app keeps terminating and i'm trying to figure out why and
> > > > where. I have a good idea tho. I'm using a push - pop FIFO system for
> > > > log messages. I have a syslog message after the push and after the pop
> > > > function and see both appearingh all the time and hence i think that
> > > > both, push() and pop() works fine. However, the messages get popped
> > > > off in a thread from where i send the data off. I'm using following
> > > > code:
>
> > > > pthread_mutex_lock(&log_mtx);
> > > > * * * Qstr=pop(&msglist, &locLen);
> > > > * * * syslog(LOG_ERR, "DUBUG: popped succesfully!");
> > > > * * * strncpy(res,Qstr,LOG_BUF_SIZE);
> > > > * * * res[LOG_BUF_SIZE]='\0';
> > > > * * * strcat(res,"\n");
> > > > * * * pthread_mutex_unlock(&log_mtx);
> > > > * * * if (log_sock>-1) {
> > > > * * * * sndlen=strlen(res);
> > > > * * * * reclen=send(log_sock, res, sndlen, 0);
> > > > * * * * if (reclen != sndlen) {
> > > > * * * * * if (reclen==-1){
> > > > * * * * * * syslog(LOG_ERR, "nlog: send failed...,errno: %s!", strerror
> > > > ( errno ));
> > > > * * * * * }
> > > > * * * * * syslog(LOG_ERR, "nlog: \"%s\" not sent, strlen(%d) - sent %d",res,
> > > > sndlen, reclen);
> > > > * * * * }
> > > > * * * * else {
> > > > * * * * * syslog(LOG_ERR, "DEBUG: sent okay, receive ack");
>
> > > > The last message I see in syslog before my app crashes is "DUBUG:
> > > > popped succesfully!"
> > > > Now the declaration of those variables are as follows:
> > > > * char res[LOG_BUF_SIZE+2]={0};
> > > > * char *Qstr;
> > > > * int locLen;
> > > > * int sndlen;
> > > > while msglist is from type char** and QLen from type int and declared
> > > > globally.
> > > > LOG_BUF_SIZE is a define and set to 512.
>
> > > > Does anyone have a clue where my app is terminating and or should i be
> > > > looking somewhere else all together? The system worked fine before i
> > > > implemented this new FIFO system...
> > > > Thanks for hints and suggestions!
> > > > Ron
>
> > > I'd check the return value of pop. *Is it a reasonable pointer? *NULL?
>
> > Yep as Beej had suggested, I included a check for NULL:
> > * * * if (Qstr!=NULL)
> > * * * * syslog(LOG_ERR, "DUBUG: popped succesfully!");
> > * * * else {
> > * * * * syslog(LOG_ERR, "DUBUG: popped not succesful!");
> > * * * * break;
> > * * * }
>
> > > If that doesn't solve it, I'd try tools, like valgrind. *Or running in
> > > a debugger, or enabling cores.
>
> > will try to use valgrind - don't know if it will run on my embedded
> > platform tho...
>
> I just compiled valgrind on our dev system but no way i'll be able to
> copy it onto our target system as the /opt/valgrind-3.2.3 directory is
> 81MB big...
... ah, i'm getting desperate.... what can i do?
> Other hints, recommodations and suggestions are highly appreciated!
>
> Thanks!
> Ron
I assumed you were on a linux flavor. Enabling cores means usually
setting ulimit to allow cores to dump on fatal signals, probably not
relevant to your embedded system. Umm, add more syslogs, repeat as
needed, to narrow down your problem seems like a good bet. You should
be able to figure out exactly what bad pointer causes the segfault,
and trace the problem that way.
You could crash on push if the malloc failed, which I assume is
possible on your limited memory embedded system. You could be messed
up on pop if somehow a shrinking realloc fails.
-David