OSSP CVS Repository

ossp - Check-in [771]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 771
Date: 2001-Aug-26 15:05:41 (local)
2001-Aug-26 13:05:41 (UTC)
User:ms
Branch:
Comment: Completed syslog channel implementation - might need trimming down.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2_ch_syslog.c      1.7 -> 1.8     24 inserted, 12 deleted

ossp-pkg/l2/l2_ch_syslog.c 1.7 -> 1.8

--- l2_ch_syslog.c       2001/08/25 18:27:48     1.7
+++ l2_ch_syslog.c       2001/08/26 13:05:41     1.8
@@ -34,8 +34,11 @@
 
 /* declare private channel configuration */
 typedef struct {
-    int iEtwas;
-    char *pszNada;
+    char *pszIdent; /* String to prepend to each syslog message */
+    int iLogopt;    /* Manipulates how kernel interacts with syslogd */
+    int iFacility;  /* Which part of the system generates this message */
+    int iPriority;  /* EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO... */
+    int iMaskpri;   /* Controls which priorities are or are not logged */
 } l2_ch_syslog_t;
 
 /* create channel */
@@ -44,10 +47,18 @@
     l2_ch_syslog_t *cfg;
 
     /* allocate private channel configuration */
+    if ((cfg = (l2_ch_syslog_t *)malloc(sizeof(l2_ch_syslog_t))) == NULL)
+        return L2_ERROR;
 
     /* initialize configuration with reasonable defaults */
+    cfg->pszIdent  = NULL;
+    cfg->iLogopt   = 0;
+    cfg->iFacility = LOG_USER;
+    cfg->iPriority = (LOG_DEBUG|LOG_ERR);
+    cfg->iMaskpri  = (0xFFFFFFFF); /* Allow all priorities to pass through */
 
     /* link private channel configuration into channel context */
+    ctx->vp = cfg;
 
     return L2_OK;
 }
@@ -56,7 +67,7 @@
 static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap)
 {
     l2_ch_syslog_t *cfg;
-    l2_param_t pa[3]; 
+    l2_param_t pa[3];
     l2_result_t rv;
 
     /* parameter checks */
@@ -64,8 +75,11 @@
         return L2_ERROR;
 
     /* feed and call generic parameter parsing engine */
-    L2_PARAM_SET(pa[0], iEtwas,   CHARPTR, &cfg->iEtwas);
-    L2_PARAM_SET(pa[1], pszNada, INT,     &cfg->pszNada);
+    L2_PARAM_SET(pa[0], ident,   CHARPTR,  &cfg->pszIdent);
+    L2_PARAM_SET(pa[1], logopts, INT,      &cfg->iLogopt);
+    L2_PARAM_SET(pa[1], facility, INT,     &cfg->iFacility);
+    L2_PARAM_SET(pa[1], priority, INT,     &cfg->iPriority);
+    L2_PARAM_SET(pa[1], maskpriority, INT, &cfg->iMaskpri);
     L2_PARAM_END(pa[2]);
     rv = l2_channel_setparams(pa, fmt, ap);
 
@@ -80,10 +94,10 @@
     /* parameter checks */
     if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL)
         return L2_ERROR;
-    if (cfg->pszNada == NULL) /* ATTENTION */
-        return L2_ERROR;
 
     /* open channel syslog */
+    openlog(cfg->pszIdent, cfg->iLogopt, cfg->iFacility);
+    setlogmask(cfg->iMaskpri);
 
     /* optionally open downstream channel, too */
     if (downstream != NULL)
@@ -104,6 +118,7 @@
         return L2_ERROR;
 
     /* write message to channel syslog */
+    syslog(cfg->iPriority, buf);
 
     /* optionally write to downstream channel, too */
     if (downstream != NULL)
@@ -116,11 +131,7 @@
 /* flush channel */
 static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream)
 {
-    l2_ch_syslog_t *cfg;
-
-    /* parameter checks */
-    if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL)
-        return L2_ERROR;
+    /* Noop for this channel, because syslog entries are unbuffered */
 
     /* optionally flush downstream channel, too */
     if (downstream != NULL)
@@ -145,6 +156,7 @@
         return L2_ERROR;
 
     /* close channel syslog */
+    closelog();
 
     return L2_OK;
 }

CVSTrac 2.0.1