Find the answer to your Linux question:
Results 1 to 2 of 2
Hi All, I am facing a problem in one of the live implementaion. I am getting segmentation fault on a moderaletly loaded system. The problem is that it is generating ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    9

    Segmentation fault on fflush

    Hi All,

    I am facing a problem in one of the live implementaion. I am getting segmentation
    fault on a moderaletly loaded system. The problem is that it is generating coredump after approx 2 days.

    The code is written in c++.

    Back tace of the dump:-

    #0 0x00b677a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
    #1 0x00c3fd3b in __write_nocancel () from /lib/tls/libc.so.6
    #2 0x00be439f in _IO_new_file_write () from /lib/tls/libc.so.6
    #3 0x00be2dfb in _IO_new_do_write () from /lib/tls/libc.so.6
    #4 0x00be3aa2 in _IO_new_file_sync () from /lib/tls/libc.so.6
    #5 0x00bd8df2 in fflush () from /lib/tls/libc.so.6
    #6 0x0805a08a in CLogger::Logger (this=0x81275c0, aeLogLevel=IMP,
    aeLogType=GEN, acpModuleName=0x80ceba8 "SlHd",
    acpFuncName=0x80cedc4 "processMediaPlay",
    acpFormatSpecifier=0x80ceee4 "[%d], [MGC_MEDIA_PLAY_ACK (Sent [RespCode {%d}])] ") at Logger.cpp:616
    #7 0x080501f0 in processMediaPlay (aSlEvt=0xb49a11d0)
    at src/SlHandler/SlEventHandler.cpp:484
    #8 0x0804f616 in processSLEvents (aSlEvt=0xb49a11d0)
    at src/SlHandler/SlEventHandler.cpp:44
    #9 0x08058e67 in Receiver () at src/SyncManager/sync.cpp:993
    #10 0x00dd73cc in start_thread () from /lib/tls/libpthread.so.0
    #11 0x00c4ec3e in clone () from /lib/tls/libc.so.6


    The logger code is :-

    void CLogger::Logger (eLogLevel aeLogLevel, eLogType aeLogType, const S8 *acpModuleName, const S8 *acpFuncName, const S8 *acpFormatSpecifier, ...)
    {
    va_list st_argumentList;
    S8 sz_buffer [LOG_MAX_LOG_BUFFER_SIZE] = {'\0',};
    S8 llog_buffer [LOG_MAX_LOG_BUFFER_SIZE+100] = {'\0',};
    S8 sz_strTime [LOG_MAX_TIME_STR_LEN] = {'\0',};
    S8 loglevelbuffer[LOG_LEVEL_LEN]= {0,};
    time_t st_longTime;
    struct tm *st_time_p = NULL;
    struct timeval t;
    SL32 i_size = 0;
    S8 sz_day [LOG_MAX_BUFF] = {0,};
    S8 sz_month [LOG_MAX_BUFF] = {0,};
    S8 sz_fileName[LOG_PATH_LEN] = {0,};
    S8 *cp_dateString;

    //Adding Date Field
    time_t curtime = time(0);
    struct tm tmDate = *localtime(&curtime);
    S8 szTmpBuff [20]= {0};


    sprintf (szTmpBuff, "%d_%d_%d", tmDate.tm_mday,
    tmDate.tm_mon + 1, tmDate.tm_year + 1900);


    #ifdef LOG
    printf ("<%s,%d> Start\n",__FUNCTION__,__LINE__);
    #endif

    if ((NULL == acpFuncName) || (NULL == acpFormatSpecifier))
    return;

    if (0 != pthread_mutex_lock (&m_Mutex))
    {
    #ifdef LOG
    printf ("<%s,%d> Fail to Lock Mutex \n",__FUNCTION__,__LINE__);
    #endif
    }
    else
    {
    #ifdef LOG
    printf ("<%s,%d> Acquired \n",__FUNCTION__,__LINE__);
    #endif
    }


    #ifdef LOG
    printf ("<%s,%d> Initializing Time\n",__FUNCTION__,__LINE__);
    #endif
    time (&st_longTime);
    st_time_p = (struct tm *)localtime (&st_longTime);

    cp_dateString = ctime (&st_longTime);
    sscanf (cp_dateString, "%s %s", sz_day, sz_month);

    if ((GEN == aeLogType) || (CDR == aeLogType))
    {

    if (mbLogLevel >= aeLogLevel)
    {
    #ifdef LOG
    printf ("<%s,%d> Making Function cater dynamic arguments\n",__FUNCTION__,__LINE__);
    #endif


    /*Creating dynamic argumnet list*/
    va_start(st_argumentList, acpFormatSpecifier);
    vsprintf(sz_buffer, acpFormatSpecifier, st_argumentList);
    va_end(st_argumentList);


    /*Creating Time Stamp*/
    if (NULL != sz_strTime)
    {
    #ifdef LOG
    printf ("<%s,%d> Creating Time String\n",__FUNCTION__,__LINE__);
    #endif
    gettimeofday(&t,NULL);
    sprintf (sz_strTime, "%02d_%02d_%02d_%02d", (st_time_p->tm_hour),
    (st_time_p->tm_min), (st_time_p->tm_sec), (t.tv_usec / 1000) );

    }


    #ifdef LOG
    printf ("<%s,%d> Converting log level Enum values to Character buffer\n",__FUNCTION__,__LINE__);
    #endif
    /*Converting log level Enum values to Character buffer*/
    if (aeLogLevel == 1)
    {
    strcpy(loglevelbuffer, "ERR");
    }
    else if (aeLogLevel == 2)
    {
    strcpy(loglevelbuffer, "IMP");
    }
    else if (aeLogLevel == 3)
    {
    strcpy(loglevelbuffer, "INF");
    }
    else
    {
    strcpy(loglevelbuffer, "DEB");
    }

    /*Printing it over console, Used printf instead of cout, because printf provides formatting ease*/
    #ifdef LOG
    printf ("<%s,%d> Value of Write to console Flag:[%d]\n",__FUNCTION__,__LINE__,mbWriteToConsole);
    #endif
    if(mbWriteToConsole)
    {
    printf ("[%3s] [%10s] [%13s] [%5s] [%17s]: %s\n", loglevelbuffer, szTmpBuff, sz_strTime,
    acpModuleName, acpFuncName, sz_buffer);
    }

    //Making Buffer printing on the txt file
    if (GEN == aeLogType )
    {

    sprintf (llog_buffer, "[%3s] [%10s] [%13s] [%5s] [%17s]: %s\n",loglevelbuffer, szTmpBuff, sz_strTime,
    acpModuleName, acpFuncName, sz_buffer);
    }
    else if (CDR == aeLogType)
    {
    sprintf (llog_buffer, "[%3s] [%10s] [%13s] [%4s]: %s\n", "CDR", szTmpBuff, sz_strTime,
    acpModuleName, sz_buffer);

    }

    #ifdef LOG
    printf ("<%s,%d> Making log buffer:size [%d]\n",__FUNCTION__,__LINE__,sizeof(llog_buffer));
    #endif

    //Handling Logging operation

    if (CDR == aeLogType)
    {

    #ifdef LOG
    printf ("<%s,%d> Inside Summary Log \n",__FUNCTION__,__LINE__);
    #endif
    //It is Summary Log.
    if (mSumLogDet.i_CurrentFileCount <= MAX_NO_SUMMARY_LOG_FILES )
    {
    #ifdef LOG
    printf ("<%s,%d> Current File count [%d] \n",__FUNCTION__,__LINE__,mSumLogDet.i_CurrentFile Count);
    #endif

    if (mSumLogDet.l_CurrentFileSize/(1024 * 1024) <= mlMaxFileSize )
    {
    #ifdef LOG
    printf ("<%s,%d>Writing in the file\n", __FUNCTION__,__LINE__);
    printf ("<%s,%d> current File size [%d] \n",__FUNCTION__,__LINE__,mSumLogDet.l_CurrentFile Size);
    #endif
    }
    else
    {
    //4th Cycle should not entre
    if (mSumLogDet.i_CurrentFileCount != MAX_NO_SUMMARY_LOG_FILES)
    {
    //Open a New File with count
    /*Making Summary file Name*/
    //Closing the earlier opened file
    #ifdef LOG
    printf ("<%s,%d> Closing the earlier opened file \n",__FUNCTION__,__LINE__);
    #endif
    if (mSumLogDet.Pfile != NULL)
    {
    fclose (mSumLogDet.Pfile);
    mSumLogDet.Pfile = NULL;

    #ifdef LOG
    printf ("<%s,%d> Summary Log file successfully Closed \n",__FUNCTION__,__LINE__);
    #endif
    }
    memset(sz_fileName,0, LOG_PATH_LEN);
    sprintf (sz_fileName, "%s/%s.txt.%d",
    gSummaryLogPath,"SummaryLog",mSumLogDet.i_CurrentF ileCount);

    /*Opening Summary log file */
    #ifdef LOG
    printf ("<%s,%d>Open a new Summary Log file:[%s]\n",__FUNCTION__,__LINE__,sz_fileName);
    #endif
    mSumLogDet.Pfile = fopen (sz_fileName, "w+");
    #ifdef LOG
    printf ("<%s,%d> Opening a next file as Fie size has reached thresold value\n",
    __FUNCTION__,__LINE__);
    #endif
    if (mSumLogDet.Pfile == NULL)
    {
    #ifdef LOG
    printf("<%s,%d>Failed to open file ...after reaching thresold value\n",
    __FUNCTION__,__LINE__);
    #endif
    }
    mSumLogDet.i_CurrentFileCount++;
    mSumLogDet.l_CurrentFileSize = 0;
    #ifdef LOG
    printf("<%s,%d>Incrementing summary log file count:%d\n",
    __FUNCTION__,__LINE__,mSumLogDet.i_CurrentFileCoun t);

    #endif
    }
    else
    {
    mSumLogDet.i_CurrentFileCount++;
    mSumLogDet.l_CurrentFileSize = 0;


    }

    }
    }
    else
    {
    //overwrite the oldest file
    //closing the earlier file
    #ifdef LOG
    printf ("<%s,%d> Closing the earlier opened file \n",__FUNCTION__,__LINE__);
    #endif
    if (mSumLogDet.Pfile != NULL)
    {
    fclose (mSumLogDet.Pfile);
    mSumLogDet.Pfile = NULL;
    #ifdef LOG

    printf ("<%s,%d> Summary Log file successfully Closed \n",__FUNCTION__,__LINE__);
    #endif
    }

    memset(sz_fileName,0, LOG_PATH_LEN);
    sprintf (sz_fileName, "%s/%s.txt",
    gSummaryLogPath,"SummaryLog");

    /*Opening Summary log file */
    mSumLogDet.Pfile = fopen (sz_fileName, "w+");
    #ifdef LOG
    printf ("<%s,%d> Opening a next file as File ..overwriting:file name [%s]\n",
    __FUNCTION__,__LINE__,sz_fileName);
    #endif
    if (mSumLogDet.Pfile == NULL)
    {
    #ifdef LOG
    printf ("<%s,%d> Failed to open file ...after reaching thresold value:name[%s]\n",
    __FUNCTION__,__LINE__,sz_fileName);
    #endif
    }
    mSumLogDet.i_CurrentFileCount = 1;
    mSumLogDet.l_CurrentFileSize = 0;
    #ifdef LOG
    printf ("<%s,%d> Overwrite: summary log file count:%d\n",
    __FUNCTION__,__LINE__,mSumLogDet.i_CurrentFileCoun t);
    #endif

    }
    i_size = fprintf (mSumLogDet.Pfile, "%s",
    llog_buffer);
    fflush (mSumLogDet.Pfile);
    if (i_size < 0)
    {
    //unsure about its handling
    #ifdef LOG
    printf ("<%s,%d> File write Failure\n",
    __FUNCTION__,__LINE__);
    #endif

    }
    else
    {
    mSumLogDet.l_CurrentFileSize += i_size;
    #ifdef LOG
    printf ("<%s,%d> File size:%d\n",
    __FUNCTION__,__LINE__, mSumLogDet.l_CurrentFileSize);
    #endif
    }




    }
    else
    {

    #ifdef LOG
    printf ("<%s,%d> Inside General Log \n",__FUNCTION__,__LINE__);
    #endif
    //It is general Log.
    if (mGenLogDet.i_CurrentFileCount <= MAX_NO_GENERAL_LOG_FILES )
    {
    #ifdef LOG
    printf ("<%s,%d> Current File count [%d] \n",__FUNCTION__,__LINE__,mGenLogDet.i_CurrentFile Count);
    #endif

    if (mGenLogDet.l_CurrentFileSize/(1024 * 1024) <= mlMaxFileSize )
    {
    #ifdef LOG
    printf ("<%s,%d>Writing in the file\n", __FUNCTION__,__LINE__);
    printf ("<%s,%d> current File size [%d] \n",__FUNCTION__,__LINE__,mGenLogDet.l_CurrentFile Size);
    #endif
    }
    else
    {
    //4th Cycle should not entre
    if (mGenLogDet.i_CurrentFileCount != MAX_NO_GENERAL_LOG_FILES)
    {
    //Open a New File with count
    /*Making Summary file Name*/
    //Closing the earlier opened file
    #ifdef LOG
    printf ("<%s,%d> Closing the earlier opened file \n",__FUNCTION__,__LINE__);
    #endif
    if (mGenLogDet.Pfile != NULL)
    {
    fclose (mGenLogDet.Pfile);
    mGenLogDet.Pfile = NULL;

    #ifdef LOG
    printf ("<%s,%d> General Log file successfully Closed \n",__FUNCTION__,__LINE__);
    #endif
    }
    memset(sz_fileName,0, LOG_PATH_LEN);
    sprintf (sz_fileName, "%s/%s.txt.%d",
    gGeneralLogPath,"GeneralLog",mGenLogDet.i_CurrentF ileCount);

    /*Opening Summary log file */
    #ifdef LOG
    printf ("<%s,%d>Open a new general Log file:[%s]\n",__FUNCTION__,__LINE__,sz_fileName);
    #endif
    mGenLogDet.Pfile = fopen (sz_fileName, "w+");
    #ifdef LOG
    printf ("<%s,%d> Opening a next file as Fie size has reached thresold value\n",
    __FUNCTION__,__LINE__);
    #endif
    if (mGenLogDet.Pfile == NULL)
    {
    #ifdef LOG
    printf("<%s,%d>Failed to open file ...after reaching thresold value\n",
    __FUNCTION__,__LINE__);
    #endif
    }
    mGenLogDet.i_CurrentFileCount++;
    mGenLogDet.l_CurrentFileSize = 0;
    #ifdef LOG
    printf("<%s,%d>Incrementing general log file count:%d\n",
    __FUNCTION__,__LINE__,mGenLogDet.i_CurrentFileCoun t);

    #endif
    }
    else
    {
    mGenLogDet.i_CurrentFileCount++;
    mGenLogDet.l_CurrentFileSize = 0;


    }

    }
    }
    else
    {
    //overwrite the oldest file
    //closing the earlier file
    #ifdef LOG
    printf ("<%s,%d> Closing the earlier opened file \n",__FUNCTION__,__LINE__);
    #endif
    if (mGenLogDet.Pfile != NULL)
    {
    fclose (mGenLogDet.Pfile);
    mGenLogDet.Pfile = NULL;
    #ifdef LOG

    printf ("<%s,%d> General Log file successfully Closed \n",__FUNCTION__,__LINE__);
    #endif
    }

    memset(sz_fileName,0, LOG_PATH_LEN);
    sprintf (sz_fileName, "%s/%s.txt",
    gGeneralLogPath,"GeneralLog");

    /*Opening Summary log file */
    mGenLogDet.Pfile = fopen (sz_fileName, "w+");
    #ifdef LOG
    printf ("<%s,%d> Opening a next file as File ..overwriting:file name [%s]\n",
    __FUNCTION__,__LINE__,sz_fileName);
    #endif
    if (mGenLogDet.Pfile == NULL)
    {
    #ifdef LOG
    printf ("<%s,%d> Failed to open file ...after reaching thresold value:name[%s]\n",
    __FUNCTION__,__LINE__,sz_fileName);
    #endif
    }
    mGenLogDet.i_CurrentFileCount = 1;
    mGenLogDet.l_CurrentFileSize = 0;
    #ifdef LOG
    printf ("<%s,%d> Overwrite: General log file count:%d\n",
    __FUNCTION__,__LINE__,mGenLogDet.i_CurrentFileCoun t);
    #endif

    }
    i_size = fprintf (mGenLogDet.Pfile, "%s",
    llog_buffer);
    fflush (mGenLogDet.Pfile);
    if (i_size < 0)
    {
    //unsure about its handling
    #ifdef LOG
    printf ("<%s,%d> File write Failure\n",
    __FUNCTION__,__LINE__);
    #endif

    }
    else
    {
    mGenLogDet.l_CurrentFileSize += i_size;
    #ifdef LOG
    printf ("<%s,%d> File size:%d\n",
    __FUNCTION__,__LINE__, mGenLogDet.l_CurrentFileSize);
    #endif
    }



    }

    }//loglevel
    else
    {
    #ifdef LOG
    printf ("<%s,%d> Log level is more that expected.\n",
    __FUNCTION__,__LINE__);
    #endif

    }


    }
    else
    {
    #ifdef LOG
    printf ("<%s,%d> Log Type is Invalid\n",
    __FUNCTION__,__LINE__);
    #endif

    }
    if (0 != pthread_mutex_unlock (&m_Mutex))
    {
    #ifdef LOG
    printf ("<%s,%d> Fail to Lock Mutex\n",__FUNCTION__,__LINE__);
    #endif
    }
    else
    {
    #ifdef LOG
    printf("Released\n");
    #endif
    }
    }




    Segmentation fault in the above code-:Logger.cpp:616:

    i_size = fprintf (mGenLogDet.Pfile, "%s", llog_buffer);
    fflush (mGenLogDet.Pfile);





    SlEventHandler.cpp code:---


    bool processMediaPlay (MGMessage *aSlEvt)
    {

    MediaPlay_st* apstEvent = NULL;
    MediaPlayAck_st astRespEvnt;
    RESOURCEDB_st* pResDB = NULL;
    bool bRetVal = true;
    U32 aResIndex = 0;
    S32 iRetVal = MRCP_SUCCESS;
    bool bSendAckFlag = true;

    apstEvent = (MediaPlay_st *)aSlEvt->GetData ();

    memset (&astRespEvnt, 0, sizeof(MediaPlayAck_st));
    astRespEvnt.respCode = SDP_OK;

    printAppEvents (aSlEvt);
    aResIndex = aSlEvt->GetMediaID();

    bRetVal= validateAppEvents(aSlEvt);
    if(bRetVal != true)
    {
    ::gLogger.Logger (ERR, GEN, MODNAM, FUNC, "[%d], [MGC_MEDIA_PLAY (Malformed Msg)]",
    aResIndex);
    astRespEvnt.respCode = SDP_ERROR;

    bRetVal = false;
    }
    else
    {

    pResDB = getResource(aResIndex);
    if (pResDB == NULL)
    {
    ::gLogger.Logger (ERR, GEN, MODNAM, FUNC, "[%d], DB Operation Error",
    aResIndex);
    return false;
    }
    else
    {
    //Restting DB Reset flags
    pResDB->bSndStopSessResp = false;
    pResDB->bDtmfPatchFlag = false;
    pResDB->bMrcpFlag = false;

    strcpy(pResDB->audFile, apstEvent->audFile);

    if (pResDB->callStateBMsk == READY)
    {

    if (apstEvent->isMRCP != false)
    {

    iRetVal = MrcpClientLib::Instance ()->OpenSession(aResIndex,
    cfg.stackIp, cfg.mrcpServerIp);
    if (iRetVal != MRCP_FAIL)
    {

    ::gLogger.Logger (IMP, GEN, MODNAM, FUNC, "[%d], [OpenSession (SUCCESS)]",
    aResIndex);
    pResDB->bMrcpFlag = true;
    ::gLogger.Logger (IMP, GEN, MODNAM, FUNC, "[%d], [Mrcp Flag (Active)]",
    aResIndex);
    UpdateCallState(pResDB, PLAY_REQ); //Only for MRCP
    bSendAckFlag = false;
    }
    else
    {
    ::gLogger.Logger (ERR, GEN, MODNAM, FUNC, "[%d], [OpenSession (Fail)]",
    aResIndex);
    astRespEvnt.respCode = SDP_ERROR;
    }
    }
    else
    {

    bRetVal = Play (pResDB, apstEvent);
    if (bRetVal != false)
    {
    UpdateCallState(pResDB, PLAYING);
    }
    else
    {
    bRetVal = false;
    astRespEvnt.respCode = SDP_ERROR;
    ::gLogger.Logger (ERR, GEN, MODNAM, FUNC, "[%d], [PlayMedia (Fail)]",
    aResIndex);
    }

    }
    }
    else
    {
    ::gLogger.Logger (ERR, GEN, MODNAM, FUNC, "[%d], [MGC_MEDIA_PLAY (Recvd In Invalid state)] ",
    aResIndex);
    astRespEvnt.respCode = SDP_ERROR;
    bRetVal = false;

    }


    }

    }//end



    if (bSendAckFlag != false)
    {

    MGMessage OMedPlay (aResIndex, MGMessage:: MGC_MEDIA_PLAY_ACK);
    OMedPlay.FillData ((MediaPlayAck_st*)&astRespEvnt);

    bRetVal = SndToSL(OMedPlay);
    if (bRetVal == false)
    {
    ::gLogger.Logger (ERR, GEN, MODNAM, FUNC, "[%d], [MGC_MEDIA_PLAY_ACK (Send Fail)]",
    aResIndex);
    return false;
    }

    ::gLogger.Logger (IMP, GEN, MODNAM, FUNC, "[%d], [MGC_MEDIA_PLAY_ACK (Sent [RespCode {%d}])] ",
    aResIndex, astRespEvnt.respCode);

    }

    return bRetVal;

    }



    segmentation fault in the code:SlEventHandler.cpp:484


    ::gLogger.Logger (IMP, GEN, MODNAM, FUNC, "[%d], [MGC_MEDIA_PLAY_AC (Sent [RespCode {%d}])] ", aResIndex, astRespEvnt.respCode);


    Please help?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    This is a lot of information, mostly useless to us... First, we need the distribution+version of the LiveCD you are running. Next, we need some information about your hardware (make, model, CPU, RAM, video). Finally, have you reported this to the bug tracker for the distribution?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...