Changeset 681

Show
Ignore:
Timestamp:
11/01/07 14:53:23 (15 years ago)
Author:
ppalmers
Message:

move truncated warning to the message itself instead of printf on stdout

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/debugmodule/debugmodule.cpp

    r671 r681  
    343343DebugModuleManager::showBackLog() 
    344344{ 
    345     DebugModuleManager *m=DebugModuleManager::instance(); 
    346345    fprintf(stderr, "=====================================================\n"); 
    347346    fprintf(stderr, "* BEGIN OF BACKLOG PRINT\n"); 
     
    353352    } 
    354353    fprintf(stderr, "\n"); 
    355      
     354 
    356355    fprintf(stderr, "=====================================================\n"); 
    357356    fprintf(stderr, "* END OF BACKLOG PRINT\n"); 
     
    386385DebugModuleManager::backlog_print(const char *fmt, ...) 
    387386{ 
     387    const char *warning = "WARNING: message truncated!\n"; 
     388    const int warning_size = 32; 
    388389    char msg[MB_BUFFERSIZE]; 
    389390    va_list ap; 
     
    394395    /* format the message first */ 
    395396    va_start(ap, fmt); 
    396     if (vsnprintf(msg, MB_BUFFERSIZE, fmt, ap) >= MB_BUFFERSIZE) { 
    397         print("WARNING: message truncated!\n"); 
     397    if (vsnprintf(msg, BACKLOG_MB_BUFFERSIZE-warning_size, fmt, ap)  
     398        >= (BACKLOG_MB_BUFFERSIZE-warning_size)) { 
     399        // output a warning if the message was truncated 
     400        snprintf(msg+BACKLOG_MB_BUFFERSIZE-warning_size, warning_size, "%s", warning); 
    398401    } 
    399402    va_end(ap); 
     
    418421DebugModuleManager::print(const char *fmt, ...) 
    419422{ 
     423    const char *warning = "WARNING: message truncated!\n"; 
     424    const int warning_size = 32; 
    420425    char msg[MB_BUFFERSIZE]; 
    421426    va_list ap; 
     
    428433    /* format the message first, to reduce lock contention */ 
    429434    va_start(ap, fmt); 
    430     if (vsnprintf(msg, MB_BUFFERSIZE, fmt, ap) >= MB_BUFFERSIZE) { 
    431         print("WARNING: message truncated!\n"); 
     435    if (vsnprintf(msg, MB_BUFFERSIZE-warning_size, fmt, ap) >= MB_BUFFERSIZE-warning_size) { 
     436        // output a warning if the message was truncated 
     437        snprintf(msg+MB_BUFFERSIZE-warning_size, warning_size, "%s", warning); 
    432438    } 
    433439    va_end(ap); 
     
    440446        return; 
    441447    } 
    442      
    443     // the backlog 
    444     strncpy(bl_mb_buffers[bl_mb_inbuffer], msg, BACKLOG_MB_BUFFERSIZE); 
    445     bl_mb_inbuffer = BACKLOG_MB_NEXT(bl_mb_inbuffer); 
    446      
     448 
    447449#ifdef DO_MESSAGE_BUFFER_PRINT 
    448450    ntries=5; 
     
    472474DebugModuleManager::backlog_va_print (const char *fmt, va_list ap) 
    473475{ 
     476    const char *warning = "WARNING: message truncated!\n"; 
     477    const int warning_size = 32; 
    474478    char msg[MB_BUFFERSIZE]; 
    475479    unsigned int ntries; 
     
    477481 
    478482    /* format the message first */ 
    479     if (vsnprintf(msg, MB_BUFFERSIZE, fmt, ap) >= MB_BUFFERSIZE) { 
    480         print("WARNING: message truncated!\n"); 
     483    if (vsnprintf(msg, BACKLOG_MB_BUFFERSIZE-warning_size, fmt, ap)  
     484        >= BACKLOG_MB_BUFFERSIZE-warning_size) { 
     485        // output a warning if the message was truncated 
     486        snprintf(msg+BACKLOG_MB_BUFFERSIZE-warning_size, warning_size, "%s", warning); 
    481487    } 
    482488 
     
    500506DebugModuleManager::va_print (const char *fmt, va_list ap) 
    501507{ 
     508    const char *warning = "WARNING: message truncated!\n"; 
     509    const int warning_size = 32; 
    502510    char msg[MB_BUFFERSIZE]; 
    503511 
     
    508516 
    509517    /* format the message first, to reduce lock contention */ 
    510     if (vsnprintf(msg, MB_BUFFERSIZE, fmt, ap) >= MB_BUFFERSIZE) { 
    511         print("WARNING: message truncated!\n"); 
    512     } 
    513      
     518    if (vsnprintf(msg, MB_BUFFERSIZE-warning_size, fmt, ap) >= MB_BUFFERSIZE-warning_size) { 
     519        // output a warning if the message was truncated 
     520        snprintf(msg+MB_BUFFERSIZE-warning_size, warning_size, "%s", warning); 
     521    } 
     522 
    514523    if (!mb_initialized) { 
    515524        /* Unable to print message with realtime safety. 
     
    519528        return; 
    520529    } 
    521      
    522     // the backlog 
    523     strncpy(bl_mb_buffers[bl_mb_inbuffer], msg, BACKLOG_MB_BUFFERSIZE); 
    524     bl_mb_inbuffer = BACKLOG_MB_NEXT(bl_mb_inbuffer); 
    525530 
    526531#ifdef DO_MESSAGE_BUFFER_PRINT