src/lib/message.c
void Qmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...)
{
   va_list   arg_ptr;
   int len, maxlen;
   POOLMEM *pool_buf;
   MQUEUE_ITEM *item, *last_item;

   pool_buf = get_pool_memory(PM_EMSG);

   for (;;) {
      maxlen = sizeof_pool_memory(pool_buf) - 1;
      va_start(arg_ptr, fmt);
      len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr);
      va_end(arg_ptr);
      if (len < 0 || len >= (maxlen-5)) {
         pool_buf = realloc_pool_memory(pool_buf, maxlen + maxlen/2);
         continue;
      }
      break;
   }
   item = (MQUEUE_ITEM *)malloc(sizeof(MQUEUE_ITEM) + strlen(pool_buf) + 1);
   item->type = type;
   item->repeat = 0;
   item->mtime = time(NULL);
   strcpy(item->msg, pool_buf);
   if (!jcr) {
      jcr = get_jcr_from_tsd();
   }

   if (jcr && type==M_FATAL) {
      jcr->setJobStatus(JS_FatalError);
    }

   /* If no jcr or no queue or dequeuing send to syslog */
   if (!jcr || !jcr->msg_queue || jcr->dequeuing_msgs) {
      syslog(LOG_DAEMON|LOG_ERR, "%s", item->msg);
      P(daemon_msg_queue_mutex);
      if (daemon_msg_queue) {
         if (item->type == M_SECURITY) {  /* can be repeated */
            /* Keep repeat count of identical messages */
            last_item = (MQUEUE_ITEM *)daemon_msg_queue->last();
            if (last_item) {
               if (strcmp(last_item->msg, item->msg) == 0) {
                  last_item->repeat++;
                  free(item);
                  item = NULL;
               }
            }
         }
         if (item) {
            daemon_msg_queue->append(item);
         }
      }
      V(daemon_msg_queue_mutex);
   } else {
      /* Queue message for later sending */
      P(jcr->msg_queue_mutex);
      jcr->msg_queue->append(item);
      V(jcr->msg_queue_mutex);
   }
   free_memory(pool_buf);
}
/*
 * We queue messages rather than print them directly. This
 *  is generally used in low level routines (msg handler, bnet)
 *  to prevent recursion (i.e. if you are in the middle of
 *  sending a message, it is a bit messy to recursively call
 *  yourself when the bnet packet is not reentrant).
 */
We queue messages rather than print them directly. This
is generally used in low level routines (msg handler, bnet)
to prevent recursion .
We queue messages rather than print them directly . This is generally used in low level routines ( msg handler bnet ) to prevent recursion .
void Qmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...)
{
   va_list   arg_ptr;
   int len, maxlen;
   POOLMEM *pool_buf;
   MQUEUE_ITEM *item, *last_item;
   pool_buf = get_pool_memory(PM_EMSG);
   for (;;) {
      maxlen = sizeof_pool_memory(pool_buf) - 1;
      va_start(arg_ptr, fmt);
      len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr);
      va_end(arg_ptr);
      if (len < 0 || len >= (maxlen-5)) {
         pool_buf = realloc_pool_memory(pool_buf, maxlen + maxlen/2);
         continue;
      }
      break;
   }
   item = (MQUEUE_ITEM *)malloc(sizeof(MQUEUE_ITEM) + strlen(pool_buf) + 1);
   item->type = type;
   item->repeat = 0;
   item->mtime = time(NULL);
   strcpy(item->msg, pool_buf);
   if (!jcr) {
      jcr = get_jcr_from_tsd();
   }
   if (jcr && type==M_FATAL) {
      jcr->setJobStatus(JS_FatalError);
    }
   if (!jcr || !jcr->msg_queue || jcr->dequeuing_msgs) {
      syslog(LOG_DAEMON|LOG_ERR, "%s", item->msg);
      P(daemon_msg_queue_mutex);
      if (daemon_msg_queue) {
         if (item->type == M_SECURITY) {  
            last_item = (MQUEUE_ITEM *)daemon_msg_queue->last();
            if (last_item) {
               if (strcmp(last_item->msg, item->msg) == 0) {
                  last_item->repeat++;
                  free(item);
                  item = NULL;
               }
            }
         }
         if (item) {
            daemon_msg_queue->append(item);
         }
      }
      V(daemon_msg_queue_mutex);
   } else {
      P(jcr->msg_queue_mutex);
      jcr->msg_queue->append(item);
      V(jcr->msg_queue_mutex);
   }
   free_memory(pool_buf);
}
void Qmsg ( JCR * jcr , int type , utime_t mtime , const char * fmt , ... ) { va_list arg_ptr ; int len , maxlen ; POOLMEM * pool_buf ; MQUEUE_ITEM * item , * last_item ; pool_buf = get_pool_memory ( PM_EMSG ) ; for ( ; ; ) { maxlen = sizeof_pool_memory ( pool_buf ) - 1 ; va_start ( arg_ptr , fmt ) ; len = bvsnprintf ( pool_buf , maxlen , fmt , arg_ptr ) ; va_end ( arg_ptr ) ; if ( len < 0 || len >= ( maxlen - 5 ) ) { pool_buf = realloc_pool_memory ( pool_buf , maxlen + maxlen / 2 ) ; continue ; } break ; } item = ( MQUEUE_ITEM * ) malloc ( sizeof ( MQUEUE_ITEM ) + strlen ( pool_buf ) + 1 ) ; item -> type = type ; item -> repeat = 0 ; item -> mtime = time ( NULL ) ; strcpy ( item -> msg , pool_buf ) ; if ( ! jcr ) { jcr = get_jcr_from_tsd ( ) ; } if ( jcr && type == M_FATAL ) { jcr -> setJobStatus ( JS_FatalError ) ; } if ( ! jcr || ! jcr -> msg_queue || jcr -> dequeuing_msgs ) { syslog ( LOG_DAEMON | LOG_ERR , " " , item -> msg ) ; P ( daemon_msg_queue_mutex ) ; if ( daemon_msg_queue ) { if ( item -> type == M_SECURITY ) { last_item = ( MQUEUE_ITEM * ) daemon_msg_queue -> last ( ) ; if ( last_item ) { if ( strcmp ( last_item -> msg , item -> msg ) == 0 ) { last_item -> repeat ++ ; free ( item ) ; item = NULL ; } } } if ( item ) { daemon_msg_queue -> append ( item ) ; } } V ( daemon_msg_queue_mutex ) ; } else { P ( jcr -> msg_queue_mutex ) ; jcr -> msg_queue -> append ( item ) ; V ( jcr -> msg_queue_mutex ) ; } free_memory ( pool_buf ) ; }
We queue messages rather than print them directly.
We queue messages rather than print them directly .
/* If no jcr or no queue or dequeuing send to syslog */ /* can be repeated */ /* Keep repeat count of identical messages */ /* Queue message for later sending */