Hi Bernd,

On Thu, Sep 16, 2010 at 12:11:39AM +0200, Bernd Schubert wrote:
> cl_log: Make functions static and remove CircularBuffer
> 
> CircularBuffer was added more than 5 years ago and still it is not used.
> So remove dead code, it can be retrieved from the repository history
> if required.
> Also make functions static only used with cl_log.c

Really can't go with more than one mutually independent changes
in a patch.  So, this needs to be split into two (at least).
There's also some funny, and unrelated, change in cl_opensyslog.
Please make sure that the changes are minimal.

Cheers,

Dejan

> Signed-off-by: Bernd Schubert <bschub...@ddn.com>
> 
> diff --git a/include/clplumbing/cl_log.h b/include/clplumbing/cl_log.h
> --- a/include/clplumbing/cl_log.h
> +++ b/include/clplumbing/cl_log.h
> @@ -39,7 +39,6 @@ void            cl_log(int priority, con
>  void            cl_perror(const char * fmt, ...) G_GNUC_PRINTF(1,2);
>  void         cl_log_enable_stderr(int truefalse);
>  void         cl_log_enable_stdout(int truefalse);
> -int          cl_set_logging_wqueue_maxlen(int);
>  gboolean     cl_log_test_logd(void);
>  void         cl_log_set_uselogd(int truefalse);
>  void         cl_log_enable_syslog_filefmt(int truefalse);
> @@ -48,7 +47,6 @@ void                cl_log_set_facility(int facility);
>  void         cl_log_set_entity(const char *  entity);
>  void         cl_log_set_logfile(const char * path);
>  void         cl_log_set_debugfile(const char * path);
> -void         inherit_compress(void);
>  void         cl_inherit_logging_environment(int maxqlen);
>  int          cl_log_set_logd_channel_source( void (*create_callback)(struct 
> IPC_CHANNEL* chan),
>                                               GDestroyNotify 
> destroy_callback);
> @@ -64,31 +62,4 @@ void               cl_flush_logs(void);
>  void cl_log_args(int argc, char **argv);
>  int cl_log_is_logd_fd(int fd);
>  
> -
> -typedef struct CircularBuffer_s 
> -{
> -     const char*     name;
> -     size_t          size;
> -     gboolean        empty_after_dump;
> -     GQueue*         queue;
> -     
> -} CircularBuffer_t;
> -
> -typedef struct CircularBufferEntry_s 
> -{
> -     int level;
> -     char *buf;
> -     
> -} CircularBufferEntry_t;
> -
> -CircularBuffer_t *NewCircularBuffer(
> -     const char *name, unsigned int size, gboolean empty_after_dump);
> -void LogToCircularBuffer(
> -     CircularBuffer_t *buffer, int level, const char *fmt, ...) 
> G_GNUC_PRINTF(3,4);
> -
> -void EmptyCircularBuffer(CircularBuffer_t *buffer);
> -
> -/* the prototype is designed to be easy to give to 
> G_main_add_SignalHandler() */
> -gboolean DumpCircularBuffer(int nsig, gpointer buffer);
> -
>  #endif
> diff --git a/lib/clplumbing/cl_log.c b/lib/clplumbing/cl_log.c
> --- a/lib/clplumbing/cl_log.c
> +++ b/lib/clplumbing/cl_log.c
> @@ -69,12 +69,12 @@ static gboolean           syslogformatfile = TRUE
>  int LogToDaemon(int priority, const char * buf, int bstrlen, gboolean 
> use_pri_str);
>  
>  static int LogToLoggingDaemon(int priority, const char * buf, int bstrlen, 
> gboolean use_pri_str);
> -IPC_Message* ChildLogIPCMessage(int priority, const char *buf, int bstrlen, 
> +static IPC_Message* ChildLogIPCMessage(int priority, const char *buf, int 
> bstrlen,
>                               gboolean use_priority_str, IPC_Channel* ch);
> -void FreeChildLogIPCMessage(IPC_Message* msg);
> -gboolean send_dropped_message(gboolean use_pri_str, IPC_Channel *chan);
> +static void  FreeChildLogIPCMessage(IPC_Message* msg);
> +static gboolean send_dropped_message(gboolean use_pri_str, IPC_Channel 
> *chan);
> +static int cl_set_logging_wqueue_maxlen(int qlen);
>  
> -const char * prio2str(int priority);
>  static int           use_logging_daemon =  FALSE;
>  static int           conn_logd_time = 0;
>  static char          cl_log_entity[MAXENTITY]= DFLT_ENTITY;
> @@ -173,7 +173,7 @@ cl_log_set_logdtime(int logdtime)
>  #define TRADITIONAL_COMPRESSION "HA_traditional_compression"
>  #define COMPRESSION   "HA_compression"
>  
> -void
> +static void
>  inherit_compress(void)
>  {
>       char* inherit_env = NULL;
> @@ -366,6 +366,17 @@ cl_log_test_logd(void)
>       
>  }
>  
> +static void
> +cl_opensyslog(void)
> +{
> +     if (*cl_log_entity == '\0' || cl_log_facility < 0) {
> +             return;
> +     }
> +     strncpy(common_log_entity, cl_log_entity, MAXENTITY);
> +     openlog(common_log_entity, LOG_CONS, cl_log_facility);
> +     syslog_enabled = 1;
> +}
> +
>  /* FIXME: This is way too ugly to bear */
>  
>  void
> @@ -445,7 +456,7 @@ cl_log_set_logd_channel_source( void (*c
>       return 0;
>  }
>  
> -const char *
> +static const char *
>  prio2str(int priority)
>  {
>       static const char *log_prio[8] = {
> @@ -734,7 +745,7 @@ ha_timestamp(TIME_T t)
>  }
>  
>  
> -int
> +static int
>  cl_set_logging_wqueue_maxlen(int qlen)
>  {
>       int sendrc;
> @@ -897,7 +908,7 @@ LogToLoggingDaemon(int priority, const c
>  }
>  
>  
> -gboolean
> +static gboolean
>  send_dropped_message(gboolean use_pri_str, IPC_Channel *chan)
>  {
>       int sendrc;
> @@ -924,27 +935,7 @@ send_dropped_message(gboolean use_pri_st
>       return sendrc == IPC_OK;
>  }
>  
> -
> -
> -
> -static int childlog_ipcmsg_allocated = 0;
> -static int childlog_ipcmsg_freed = 0;
> -void childlog_dump_ipcmsg_stats(void);
> -void
> -childlog_dump_ipcmsg_stats(void)
> -{
> -     
> -     cl_log(LOG_INFO, "childlog ipcmsg allocated:%d, freed=%d, diff =%d",
> -            childlog_ipcmsg_allocated,
> -            childlog_ipcmsg_freed,
> -            childlog_ipcmsg_allocated - childlog_ipcmsg_freed);
> -     
> -     return;
> -     
> -     
> -}
> -
> -IPC_Message*
> +static IPC_Message*
>  ChildLogIPCMessage(int priority, const char *buf, int bufstrlen, 
>                  gboolean use_prio_str, IPC_Channel* ch)
>  {
> @@ -1003,13 +994,11 @@ ChildLogIPCMessage(int priority, const c
>       ret->msg_done = FreeChildLogIPCMessage;
>       ret->msg_ch = ch;
>  
> -     childlog_ipcmsg_allocated++;
> -
>       return ret;
>  }
>  
>  
> -void
> +static void
>  FreeChildLogIPCMessage(IPC_Message* msg)
>  {
>       if (msg == NULL) {
> @@ -1021,140 +1010,10 @@ FreeChildLogIPCMessage(IPC_Message* msg)
>       memset(msg, 0, sizeof (*msg));
>       free(msg);
>       
> -     childlog_ipcmsg_freed ++;
> -     
>       return;
>  
>  }
>  
> -
> -
> -static void
> -cl_opensyslog(void)
> -{
> -     if (*cl_log_entity == '\0' || cl_log_facility < 0) {
> -             return;
> -     }
> -     syslog_enabled = 1;
> -     strncpy(common_log_entity, cl_log_entity, MAXENTITY);
> -     openlog(common_log_entity, LOG_CONS, cl_log_facility);
> -}
> -
> -/* What a horrible substitute for a low-overhead event log!! - FIXME!! */
> -
> -CircularBuffer_t *
> -NewCircularBuffer(const char *name, uint size, gboolean empty_after_dump)
> -{
> -     CircularBuffer_t *buffer = malloc(sizeof(CircularBuffer_t));
> -     if (!buffer) {
> -             return buffer;
> -     }
> -     buffer->name = name;
> -     buffer->size = size;
> -     buffer->empty_after_dump = empty_after_dump;
> -     buffer->queue = g_queue_new();
> -
> -#if 1
> -     if(empty_after_dump == FALSE) {
> -             cl_log(LOG_ERR, "This requires glib 2.4");
> -             empty_after_dump = TRUE;
> -     }
> -#endif
> -
> -     return buffer;
> -}
> -
> -void
> -LogToCircularBuffer(CircularBuffer_t *buffer, int level, const char *fmt, 
> ...)
> -{
> -     va_list ap;
> -     char buf[MAXLINE];
> -     int     nbytes;
> -     CircularBufferEntry_t *entry = malloc(sizeof(CircularBufferEntry_t));
> -     
> -     if (!entry) {
> -             return;
> -     }
> -     va_start(ap, fmt);
> -     nbytes=vsnprintf(buf, MAXLINE, fmt, ap);
> -     /*      nbytes=vasprintf(&buf, fmt, ap); */
> -     va_end(ap);
> -
> -     entry->buf = buf;
> -     entry->level = level;
> -
> -     g_queue_push_tail(buffer->queue, entry);
> -
> -     while(buffer->queue->length > buffer->size) {
> -             entry = g_queue_pop_head(buffer->queue);
> -             free(entry->buf);
> -             free(entry);
> -     }
> -}
> -
> -void
> -EmptyCircularBuffer(CircularBuffer_t *buffer) 
> -{
> -     CircularBufferEntry_t *entry = NULL;
> -     while(buffer->queue->length > 0) {
> -             entry = g_queue_pop_head(buffer->queue);
> -             free(entry->buf);
> -             free(entry);
> -     }
> -}
> -
> -gboolean
> -DumpCircularBuffer(int nsig, gpointer user_data) 
> -{
> -     CircularBuffer_t *buffer = user_data;
> -     CircularBufferEntry_t *entry = NULL;
> -     
> -     if(buffer == NULL) {
> -             /* error */
> -             cl_log(LOG_ERR, "No buffer supplied to dump.");
> -             return FALSE;
> -     }
> -
> -     if(logging_daemon_chan != NULL
> -        && logging_daemon_chan->send_queue->max_qlen < buffer->size) {
> -             /* We have no hope of getting the whole buffer out via the
> -              *  logging daemon.  Use direct log instead so the messages
> -              *  come out in the right order.
> -              */ 
> -             cl_log_depth++;
> -     }
> -     
> -     cl_log(LOG_INFO, "Mark: Begin dump of buffer %s", buffer->name);
> -     if(buffer->empty_after_dump) {
> -             while(buffer->queue->length > 0) {
> -                     entry = g_queue_pop_head(buffer->queue);
> -                     cl_log(entry->level, "%s", entry->buf);
> -                     free(entry->buf);
> -                     free(entry);
> -             }
> -
> -     } else {
> -#if 1
> -             cl_log(LOG_ERR, "This requires g_queue_peek_nth() from glib 
> 2.4");
> -#else
> -             uint lpc = 0;
> -             uint queue_len = buffer->queue->length;
> -             for(lpc = 0; lpc < queue_len; lpc++) {
> -                     entry = g_queue_peek_nth(buffer->queue, lpc);
> -                     cl_log(entry->level, "%s", entry->buf);
> -             }
> -#endif
> -     }
> -     if(logging_daemon_chan != NULL
> -        && logging_daemon_chan->send_queue->max_qlen < buffer->size) {
> -             /* Return is back to normal */
> -             cl_log_depth--;
> -     }
> -     cl_log(LOG_INFO, "Mark: End dump of buffer %s", buffer->name);
> -     return TRUE;
> -}
> -
> -
>  void
>  cl_log_args(int argc, char **argv)
>  {
> 
> -- 
> Bernd Schubert
> DataDirect Networks
> 
> _______________________________________________
> Pacemaker mailing list: Pacemaker@oss.clusterlabs.org
> http://oss.clusterlabs.org/mailman/listinfo/pacemaker
> 
> Project Home: http://www.clusterlabs.org
> Getting started: http://www.clusterlabs.org/doc/Cluster_from_Scratch.pdf
> Bugs: 
> http://developerbugs.linux-foundation.org/enter_bug.cgi?product=Pacemaker

_______________________________________________
Pacemaker mailing list: Pacemaker@oss.clusterlabs.org
http://oss.clusterlabs.org/mailman/listinfo/pacemaker

Project Home: http://www.clusterlabs.org
Getting started: http://www.clusterlabs.org/doc/Cluster_from_Scratch.pdf
Bugs: http://developerbugs.linux-foundation.org/enter_bug.cgi?product=Pacemaker

Reply via email to