Back to index

nagios-plugins  1.4.16
Functions | Variables
log.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <time.h>
#include "radiusd.h"

Go to the source code of this file.

Functions

static int do_log (int lvl, char *fmt, va_list ap)
int log_debug (char *msg,...)
int log (int lvl, char *msg,...)

Variables

char log_sccsid [] = "@(#)log.c 1.2 Copyright 1998 Cistron Internet Services B.V,"
char * radlog_dir

Function Documentation

static int do_log ( int  lvl,
char *  fmt,
va_list  ap 
) [static]

Definition at line 23 of file log.c.

{
       FILE   *msgfd;
       unsigned char *s = ": ";
       char   buffer[256];
       time_t timeval;
       int    len;

       if ((lvl & L_CONS) || radlog_dir == NULL || debug_flag) {
              lvl &= ~L_CONS;
              if (!debug_flag) fprintf(stderr, "%s: ", progname);
              vfprintf(stderr, fmt, ap);
              fprintf(stderr, "\n");
       }
       if (radlog_dir == NULL || debug_flag) return 0;

       if (strcmp(radlog_dir, "stdout") != 0) {
              sprintf(buffer, "%.200s/%.50s", radlog_dir, RADIUS_LOG);
              if((msgfd = fopen(buffer, "a")) == NULL) {
                     fprintf(stderr, "%s: Couldn't open %s for logging\n",
                                   progname, buffer);
                     return -1;
              }
       } else {
              msgfd = stdout;
       }

       timeval = time(0);
       strcpy(buffer, ctime(&timeval));
       switch(lvl) {
              case L_DBG:
                     s = ": Debug: ";
                     break;
              case L_AUTH:
                     s = ": Auth: ";
                     break;
              case L_PROXY:
                     s = ": Proxy: ";
                     break;
              case L_INFO:
                     s = ": Info: ";
                     break;
              case L_ERR:
                     s = ": Error: ";
                     break;
       }
       strNcpy(buffer + 24, s, sizeof(buffer) - 24);
       len = strlen(buffer);

       vsprintf(buffer + len, fmt, ap);
       if (strlen(buffer) >= sizeof(buffer))
              /* What else can we do if we don't have vnsprintf */
              _exit(1);

       /*
        *     Filter out characters not in Latin-1.
        */
       for (s = buffer; *s; s++) {
              if (*s == '\r' || *s == '\n')
                     *s = ' ';
              else if (*s < 32 || (*s >= 128 && *s <= 160))
                     *s = '?';
       }
       strcat(buffer, "\n");

       fputs(buffer, msgfd);
       if (msgfd != stdout) 
         fclose(msgfd);
       else
         fflush(stdout);

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int log ( int  lvl,
char *  msg,
  ... 
)

Definition at line 109 of file log.c.

{
       va_list ap;
       int r;

       va_start(ap, msg);
       r = do_log(lvl, msg, ap);
       va_end(ap);

       return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int log_debug ( char *  msg,
  ... 
)

Definition at line 97 of file log.c.

{
       va_list ap;
       int r;

       va_start(ap, msg);
       r = do_log(L_DBG, msg, ap);
       va_end(ap);

       return r;
}

Here is the call graph for this function:


Variable Documentation

char log_sccsid[] = "@(#)log.c 1.2 Copyright 1998 Cistron Internet Services B.V,"

Definition at line 6 of file log.c.

char* radlog_dir

Definition at line 70 of file check_radius.c.