Back to index

courier  0.68.2
Functions | Variables
lcclog.c File Reference
#include "courier.h"
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <grp.h>
#include "maxlongsize.h"
#include <sys/uio.h>

Go to the source code of this file.

Functions

static void clog_msg_send_stderr ()
void clog_open_syslog (const char *module)
void clog_open_stderr (const char *module)
void clog_msg_start_info ()
void clog_msg_start_err ()
void clog_msg_send ()
void clog_msg_str (const char *p)
void clog_msg_ulong (unsigned long n)
void clog_msg_uint (unsigned n)
void clog_msg_int (int n)
void clog_msg_prerrno ()
void clog_msg_errno ()

Variables

static int log_opened = 0
static char logbuf [1024]
static const char * logmodule
static void(* clog_msg_send_func )()

Function Documentation

void clog_msg_errno ( )

Definition at line 200 of file lcclog.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void clog_msg_int ( int  n)

Definition at line 174 of file lcclog.c.

{
       if (n < 0)
       {
              n= -n;
              clog_msg_str("-");
       }
       clog_msg_uint(n);
}

Here is the call graph for this function:

void clog_msg_prerrno ( )

Definition at line 184 of file lcclog.c.

{
       clog_msg_start_err();
#if    HAVE_STRERROR
       clog_msg_str(strerror(errno));
#else
       {
       char   buf[MAXLONGSIZE+40];

              sprintf(buf, "System error, errno=%d", (int)errno);
              clog_msg_str(buf);
       }
#endif
       clog_msg_send();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void clog_msg_send ( )

Definition at line 83 of file lcclog.c.

{
       if (!log_opened)     return;

       (*clog_msg_send_func)();
}

Here is the caller graph for this function:

static void clog_msg_send_stderr ( ) [static]

Definition at line 90 of file lcclog.c.

{
struct iovec  iov[4];
int    niov=0;

       if (logmodule)
       {
              iov[niov].iov_base=(caddr_t)logmodule;
              iov[niov++].iov_len=strlen(logmodule);
              iov[niov].iov_base=(caddr_t)": ";
              iov[niov++].iov_len=2;
       }

       iov[niov].iov_base=(caddr_t)logbuf;
       iov[niov++].iov_len=strlen(logbuf);
       iov[niov].iov_base=(caddr_t)"\n";
       iov[niov++].iov_len=1;
       writev(2, iov, niov);
}

Here is the caller graph for this function:

Definition at line 76 of file lcclog.c.

{
       if (!log_opened)
              clog_open_stderr("init");
       strcpy(logbuf, "ERR: ");
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 70 of file lcclog.c.

{
       if (!log_opened)     return;
       strcpy(logbuf, "INFO: ");
}

Here is the caller graph for this function:

void clog_msg_str ( const char *  p)

Definition at line 126 of file lcclog.c.

{
int    n, l;
int    c;
int    trunc=0;

       if (!p || !log_opened)      return;
       n=strlen(p);
       l=strlen(logbuf);
       if (n > 128)
       {
              n=128;
              trunc=1;
       }

       if (n+l >= sizeof(logbuf)-1)
              n=sizeof(logbuf)-1-l;

       while (n)
       {
              c= *p++;
              if ( c == '\r')      continue;
              if ( c == '\n' && *p == 0)  break;

              if ( c == '\n')      c='/';
              else if (c < ' ' || c >= 0x7E)     c='.';
              logbuf[l++]=c;
              --n;
       }
       logbuf[l]=0;
       if (trunc)    clog_msg_str("...");
}

Here is the caller graph for this function:

void clog_msg_uint ( unsigned  n)

Definition at line 168 of file lcclog.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void clog_msg_ulong ( unsigned long  n)

Definition at line 159 of file lcclog.c.

{
char   buf[MAXLONGSIZE+2];

       if (!log_opened)     return;
       sprintf(buf, "%lu", n);
       clog_msg_str(buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void clog_open_stderr ( const char *  module)

Definition at line 59 of file lcclog.c.

{
#ifdef HAVE_SETVBUF_IOLBF
       setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
#endif

       log_opened=1;
       logmodule=module;
       clog_msg_send_func=clog_msg_send_stderr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void clog_open_syslog ( const char *  module)

Definition at line 39 of file lcclog.c.

{
#if    HAVE_SYSLOG_H

       logmodule=module;
       clog_msg_send_func=clog_msg_send_syslog;
       openlog(module, 0
#ifdef  LOG_NDELAY
                     | LOG_NDELAY
#else
                     | LOG_NOWAIT
#endif
                     , LOG_MAIL);

#else
       clog_open_stderr(module);
#endif
       log_opened=1;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

void(* clog_msg_send_func)() [static]

Definition at line 37 of file lcclog.c.

int log_opened = 0 [static]

Definition at line 28 of file lcclog.c.

char logbuf[1024] [static]

Definition at line 29 of file lcclog.c.

const char* logmodule [static]

Definition at line 30 of file lcclog.c.