[multipathd] fix 2 log issues
authorroot <root@xa-s05.(none)>
Wed, 27 Jul 2005 06:40:36 +0000 (08:40 +0200)
committerroot <root@xa-s05.(none)>
Wed, 27 Jul 2005 06:40:36 +0000 (08:40 +0200)
There are two log issues that I uncovered. #1 If the log is emptied when
the tail points to the very end of the log area, and the next message needs
to roll over to the start, it doesn't pull the head around too, so the head
is pointing at an empty message, causing you to print a priority 0 message
of nothing. #2 It is possible for the log to be totally full, and on the
next enqueue, have the log tail point to the log head, which causes the
entire existing log to be lost.

This patch fixes both.

-Ben Marzinski

multipathd/log.c

index 90015a44f38125aa9f442f5605e3d250a2023d5c..ec4f3cd5a92f371d34e682430fb3a5ec5ebd8eca 100644 (file)
@@ -108,18 +108,20 @@ int log_enqueue (int prio, const char * fmt, va_list ap)
                la->tail += ALIGN(fwd, sizeof(void *));
        }
        vsnprintf(buff, MAX_MSG_SIZE, fmt, ap);
-       len = ALIGN(strlen(buff) * sizeof(char) + 1, sizeof(void *));
+       len = ALIGN(sizeof(struct logmsg) + strlen(buff) * sizeof(char) + 1,
+                   sizeof(void *));
 
        /* not enough space on tail : rewind */
-       if (la->head <= la->tail &&
-           (len + sizeof(struct logmsg)) > (la->end - la->tail)) {
+       if (la->head <= la->tail && len > (la->end - la->tail)) {
                logdbg(stderr, "enqueue: rewind tail to %p\n", la->tail);
                la->tail = la->start;
+
+               if (la->empty)
+                       la->head = la->start;
        }
 
        /* not enough space on head : drop msg */
-       if (la->head > la->tail &&
-           (len + sizeof(struct logmsg)) > (la->head - la->tail)) {
+       if (la->head > la->tail && len >= (la->head - la->tail)) {
                logdbg(stderr, "enqueue: log area overrun, drop msg\n");
 
                if (!la->empty)
@@ -153,7 +155,7 @@ int log_dequeue (void * buff)
 
        if (la->empty)
                return 1;
-       
+
        int len = strlen((char *)&src->str) * sizeof(char) +
                  sizeof(struct logmsg) + 1;