[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Cluster-devel] [PATCH] dlm_controld: fix name printing error in logging



On Fri, Apr 25, 2014 at 03:21:48PM +0800, Lidong Zhong wrote:
> When the length of name_in is NAME_ID_SIZE, the last byte of the name
> and a whitespace will get lost.

Thanks, I modified your patch to handle longer names also...

commit 4283123f0b13eafc46d825050c5142cf44be79c3
Author: Lidong Zhong <lzhong suse com>
Date:   Fri Apr 25 10:52:52 2014 -0500

    dlm_controld: fix long name in log entry
    
    When the length of name_in is NAME_ID_SIZE, the last byte of the name
    and a whitespace will get lost.
    
    (Modified by teigland redhat com to also
    handle names longer than NAME_ID_SIZE.)
    
    Signed-off-by: Lidong Zhong <lzhong suse com>

diff --git a/dlm_controld/logging.c b/dlm_controld/logging.c
index 9347e43186cd..4aa3406c0725 100644
--- a/dlm_controld/logging.c
+++ b/dlm_controld/logging.c
@@ -122,17 +122,23 @@ static void log_save_str(int len, char *log_buf, unsigned int *p
 void log_level(char *name_in, uint32_t level_in, const char *fmt, ...)
 {
        va_list ap;
-       char name[NAME_ID_SIZE + 1];
+       char name[NAME_ID_SIZE + 2];
        uint32_t level = level_in & 0x0000FFFF;
        uint32_t extra = level_in & 0xFFFF0000;
        int ret, pos = 0;
        int len = LOG_STR_LEN - 2;
+       int namelen = 0;
        int plock = extra & LOG_PLOCK;
 
        memset(name, 0, sizeof(name));
 
-       if (name_in)
-               snprintf(name, NAME_ID_SIZE, "%s ", name_in);
+       if (name_in) {
+               namelen = snprintf(name, NAME_ID_SIZE + 1, "%s", name_in);
+               if (namelen > NAME_ID_SIZE)
+                       namelen = NAME_ID_SIZE;
+               name[namelen] = ' ';
+               name[namelen+1] = '\0';
+       }
 
        ret = snprintf(log_str + pos, len - pos, "%llu %s",
                       (unsigned long long)monotime(), name);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]