1: # include <stdio.h>
   2: # include <syslog.h>
   3: 
   4: # ifndef lint
   5: static char SccsId[] =  "@(#)logger.c	4.1		7/25/83";
   6: # endif lint
   7: 
   8: /*
   9: **  LOGGER -- read and log utility
  10: **
  11: **	This routine reads from an input and arranges to write the
  12: **	result on the system log, along with a useful tag.
  13: */
  14: 
  15: main(argc, argv)
  16:     int argc;
  17:     char **argv;
  18: {
  19:     char buf[200];
  20:     char *tag;
  21:     register char *p;
  22:     int pri = LOG_NOTICE;
  23:     int logflags = 0;
  24:     extern char *getlogin();
  25: 
  26:     /* initialize */
  27:     tag = getlogin();
  28: 
  29:     /* crack arguments */
  30:     while (--argc > 0)
  31:     {
  32:         p = *++argv;
  33:         if (*p != '-')
  34:             break;
  35: 
  36:         switch (*++p)
  37:         {
  38:           case '\0':        /* dummy */
  39:             /* this can be used to give null parameters */
  40:             break;
  41: 
  42:           case 't':     /* tag */
  43:             if (argc > 1 && argv[1][0] != '-')
  44:             {
  45:                 argc--;
  46:                 tag = *++argv;
  47:             }
  48:             else
  49:                 tag = NULL;
  50:             break;
  51: 
  52:           case 'p':     /* priority */
  53:             if (argc > 1 && argv[1][0] != '-')
  54:             {
  55:                 argc--;
  56:                 pri = atoi(*++argv);
  57:             }
  58:             break;
  59: 
  60:           case 'i':     /* log process id also */
  61:             logflags |= LOG_PID;
  62:             break;
  63: 
  64:           case 'f':     /* file to log */
  65:             if (argc > 1 && argv[1][0] != '-')
  66:             {
  67:                 argc--;
  68:                 if (freopen(*++argv, "r", stdin) == NULL)
  69:                 {
  70:                     fprintf("logger: ");
  71:                     perror(*argv);
  72:                     exit(1);
  73:                 }
  74:             }
  75:             break;
  76: 
  77:           default:
  78:             fprintf(stderr, "logger: unknown flag -%s\n", p);
  79:             break;
  80:         }
  81:     }
  82: 
  83:     /* setup for logging */
  84:     openlog(tag, logflags);
  85:     (void) fclose(stdout);
  86: 
  87:     /* log input line if appropriate */
  88:     if (argc > 0)
  89:     {
  90:         char buf[120];
  91: 
  92:         buf[0] = '\0';
  93:         while (argc-- > 0)
  94:         {
  95:             strcat(buf, " ");
  96:             strcat(buf, *argv++);
  97:         }
  98:         syslog(pri, buf + 1);
  99:         exit(0);
 100:     }
 101: 
 102:     /* main loop */
 103:     while (fgets(buf, sizeof buf, stdin) != NULL)
 104:         syslog(pri, buf);
 105: 
 106:     exit(0);
 107: }

Defined functions

main defined in line 15; never used

Defined variables

SccsId defined in line 5; never used
Last modified: 1983-12-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 661
Valid CSS Valid XHTML 1.0 Strict