lists.arthurdejong.org
RSS feed

nss-pam-ldapd commit: r1399 - nss-pam-ldapd/nslcd

[Date Prev][Date Next] [Thread Prev][Thread Next]

nss-pam-ldapd commit: r1399 - nss-pam-ldapd/nslcd



Author: arthur
Date: Sat Mar 19 16:13:31 2011
New Revision: 1399
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?view=rev&revision=1399

Log:
remove logging functionality that isn't used

Modified:
   nss-pam-ldapd/nslcd/log.c
   nss-pam-ldapd/nslcd/log.h

Modified: nss-pam-ldapd/nslcd/log.c
==============================================================================
--- nss-pam-ldapd/nslcd/log.c   Fri Mar 18 15:33:50 2011        (r1398)
+++ nss-pam-ldapd/nslcd/log.c   Sat Mar 19 16:13:31 2011        (r1399)
@@ -19,7 +19,6 @@
    02110-1301 USA
 */
 
-
 #include "config.h"
 
 #include <stdio.h>
@@ -34,106 +33,37 @@
 
 #include "log.h"
 
-
 /* set the logname */
 #undef PACKAGE
 #define PACKAGE "nslcd"
 
-
-/* storage for logging modes */
-static struct cvsd_log {
-  FILE *fp; /* NULL==syslog */
-  int loglevel;
-  struct cvsd_log *next;
-} *cvsd_loglist=NULL;
-
-
 /* default loglevel when no logging is configured */
 static int prelogging_loglevel=LOG_INFO;
 
+/* loglevel to use before logging to syslog */
+static int loglevel=LOG_INFO;
 
 /* the session id that is set for this thread */
 static __thread char *sessionid=NULL;
 
-
 /* the request identifier that is set for this thread */
 static __thread char *requestid=NULL;
 #define MAX_REQUESTID_LENGTH 40
 
-
 /* set loglevel when no logging is configured */
-void log_setdefaultloglevel(int loglevel)
-{
-  prelogging_loglevel=loglevel;
-}
-
-
-/* add logging method to configuration list */
-static void log_addlogging_fp(FILE *fp,int loglevel)
-{
-  struct cvsd_log *tmp,*lst;
-  /* create new logstruct */
-  tmp=(struct cvsd_log *)malloc(sizeof(struct cvsd_log));
-  if (tmp==NULL)
-  {
-    fprintf(stderr,"malloc() failed: %s",strerror(errno));
-    /* since this is done during initialisation it's best to bail out */
-    exit(EXIT_FAILURE);
-  }
-  tmp->fp=fp;
-  tmp->loglevel=loglevel;
-  tmp->next=NULL;
-  /* save the struct in the list */
-  if (cvsd_loglist==NULL)
-    cvsd_loglist=tmp;
-  else
-  {
-    for (lst=cvsd_loglist;lst->next!=NULL;lst=lst->next);
-    lst->next=tmp;
-  }
-}
-
-
-/* configure logging to a file */
-void log_addlogging_file(const char *filename,int loglevel)
-{
-  FILE *fp;
-  fp=fopen(filename,"a");
-  if (fp==NULL)
-  {
-    log_log(LOG_ERR,"cannot open logfile (%s) for appending: 
%s",filename,strerror(errno));
-    exit(EXIT_FAILURE);
-  }
-  log_addlogging_fp(fp,loglevel);
-}
-
-
-/* configure logging to syslog */
-void log_addlogging_syslog(int loglevel)
+void log_setdefaultloglevel(int pri)
 {
-  openlog(PACKAGE,LOG_PID,LOG_DAEMON);
-  log_addlogging_fp(NULL,loglevel);
+  prelogging_loglevel=pri;
 }
 
-
-/* configure a null logging mode (no logging) */
-void log_addlogging_none()
-{
-  /* this is a hack, but it's so easy */
-  log_addlogging_fp(NULL,LOG_EMERG);
-}
-
-
 /* start the logging with the configured logging methods
    if no method is configured yet, logging is done to syslog */
 void log_startlogging(void)
 {
-  if (cvsd_loglist==NULL)
-    log_addlogging_syslog(LOG_INFO);
+  openlog(PACKAGE,LOG_PID,LOG_DAEMON);
   prelogging_loglevel=-1;
 }
 
-
 /* indicate that we should clear any session identifiers set by
    log_newsession */
 void log_clearsession(void)
@@ -166,7 +96,6 @@
     requestid[0]='\0';
 }
 
-
 /* indicate that a request identifier should be included in the output
    from this point on, until log_newsession() is called */
 void log_setrequest(const char *format, ...)
@@ -189,27 +118,23 @@
   va_end(ap);
 }
 
-
 /* log the given message using the configured logging method */
 void log_log(int pri,const char *format, ...)
 {
   int res;
-  struct cvsd_log *lst;
-  /* TODO: make this something better */
-  #define maxbufferlen 200
-  char buffer[maxbufferlen];
+  char buffer[200];
   va_list ap;
   /* make the message */
   va_start(ap,format);
-  res=vsnprintf(buffer,maxbufferlen,format,ap);
-  if ((res<0)||(res>=maxbufferlen))
+  res=vsnprintf(buffer,sizeof(buffer),format,ap);
+  if ((res<0)||(res>=(int)sizeof(buffer)))
   {
     /* truncate with "..." */
-    buffer[maxbufferlen-2]='.';
-    buffer[maxbufferlen-3]='.';
-    buffer[maxbufferlen-4]='.';
+    buffer[sizeof(buffer)-2]='.';
+    buffer[sizeof(buffer)-3]='.';
+    buffer[sizeof(buffer)-4]='.';
   }
-  buffer[maxbufferlen-1]='\0';
+  buffer[sizeof(buffer)-1]='\0';
   va_end(ap);
   /* do the logging */
   if (prelogging_loglevel>=0)
@@ -227,52 +152,14 @@
   }
   else
   {
-    for (lst=cvsd_loglist;lst!=NULL;lst=lst->next)
+    if (pri<=loglevel)
     {
-      if (pri<=lst->loglevel)
-      {
-        if (lst->fp==NULL) /* syslog */
-        {
-          if ((requestid!=NULL)&&(requestid[0]!='\0'))
-            syslog(pri,"[%s] <%s> %s",sessionid,requestid,buffer);
-          else if ((sessionid!=NULL)&&(sessionid[0]!='\0'))
-            syslog(pri,"[%s] %s",sessionid,buffer);
-          else
-            syslog(pri,"%s",buffer);
-        }
-        else /* file */
-        {
-          if ((requestid!=NULL)&&(requestid[0]!='\0'))
-            fprintf(lst->fp,"%s: [%s] <%s> 
%s\n",sessionid,requestid,PACKAGE,buffer);
-          else if ((sessionid!=NULL)&&(sessionid[0]!='\0'))
-            fprintf(lst->fp,"%s: [%s] %s\n",sessionid,PACKAGE,buffer);
-          else
-            fprintf(lst->fp,"%s: %s\n",PACKAGE,buffer);
-          fflush(lst->fp);
-        }
-      }
+      if ((requestid!=NULL)&&(requestid[0]!='\0'))
+        syslog(pri,"[%s] <%s> %s",sessionid,requestid,buffer);
+      else if ((sessionid!=NULL)&&(sessionid[0]!='\0'))
+        syslog(pri,"[%s] %s",sessionid,buffer);
+      else
+        syslog(pri,"%s",buffer);
     }
   }
 }
-
-
-/* return the syslog loglevel represented by the string
-   return -1 on unknown */
-int log_getloglevel(const char *lvl)
-{
-  if ( strcmp(lvl,"crit")==0 )
-    return LOG_CRIT;
-  else if ( (strcmp(lvl,"error")==0) ||
-            (strcmp(lvl,"err")==0) )
-    return LOG_ERR;
-  else if ( strcmp(lvl,"warning")==0 )
-    return LOG_WARNING;
-  else if ( strcmp(lvl,"notice")==0 )
-    return LOG_NOTICE;
-  else if ( strcmp(lvl,"info")==0 )
-    return LOG_INFO;
-  else if ( strcmp(lvl,"debug")==0 )
-    return LOG_DEBUG;
-  else
-    return -1; /* unknown */
-}

Modified: nss-pam-ldapd/nslcd/log.h
==============================================================================
--- nss-pam-ldapd/nslcd/log.h   Fri Mar 18 15:33:50 2011        (r1398)
+++ nss-pam-ldapd/nslcd/log.h   Sat Mar 19 16:13:31 2011        (r1399)
@@ -23,57 +23,31 @@
 #ifndef NSLCD__LOG_H
 #define NSLCD__LOG_H 1
 
-
 #include <syslog.h>
 #include "compat/attrs.h"
 
-
 /* set loglevel when no logging is configured */
-void log_setdefaultloglevel(int loglevel);
-
-
-/* configure logging to a file */
-void log_addlogging_file(const char *filename,int loglevel);
-
-
-/* configure logging to syslog */
-void log_addlogging_syslog(int loglevel);
-
-
-/* configure a null logging mode (no logging) */
-void log_addlogging_none(void);
-
+void log_setdefaultloglevel(int pri);
 
 /* start the logging with the configured logging methods
    if no method is configured yet, logging is done to syslog */
 void log_startlogging(void);
 
-
 /* indicate that a session id should be included in the output
    and set it to a new value */
 void log_newsession(void);
 
-
 /* indicate that we should clear any session identifiers set by
    log_newsession */
 void log_clearsession(void);
 
-
 /* indicate that a request identifier should be included in the output
    from this point on, until log_newsession() is called */
 void log_setrequest(const char *format, ...)
   LIKE_PRINTF(1,2);
 
-
 /* log the given message using the configured logging method */
 void log_log(int pri,const char *format, ...)
   LIKE_PRINTF(2,3);
 
-
-/* return the syslog loglevel represented by the string
-   return -1 on unknown */
-int log_getloglevel(const char *lvl)
-  MUST_USE;
-
-
 #endif /* not NSLCD__LOG_H */
-- 
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits