home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / sup / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.4 KB  |  167 lines

  1. /*
  2.  * Copyright (c) 1992 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  12.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  13.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14.  *
  15.  * Carnegie Mellon requests users of this software to return to
  16.  *
  17.  *  Software Distribution Coordinator  or  Software_Distribution@CS.CMU.EDU
  18.  *  School of Computer Science
  19.  *  Carnegie Mellon University
  20.  *  Pittsburgh PA 15213-3890
  21.  *
  22.  * any improvements or extensions that they make and grant Carnegie Mellon
  23.  * the rights to redistribute these changes.
  24.  */
  25. /*
  26.  * Logging support for SUP
  27.  **********************************************************************
  28.  * HISTORY
  29.  * $Log: log.c,v $
  30.  * Revision 1.1.1.1  1993/05/21  14:52:17  cgd
  31.  * initial import of CMU's SUP to NetBSD
  32.  *
  33.  * Revision 1.5  92/08/11  12:03:43  mrt
  34.  *     Brad's delinting and variable argument list usage
  35.  *     changes. Added copyright.
  36.  * 
  37.  * Revision 1.3  89/08/15  15:30:37  bww
  38.  *     Updated to use v*printf() in place of _doprnt().
  39.  *     From "[89/04/19            mja]" at CMU.
  40.  *     [89/08/15            bww]
  41.  * 
  42.  * 27-Dec-87  Glenn Marcy (gm0w) at Carnegie-Mellon University
  43.  *    Added check to allow logopen() to be called multiple times.
  44.  *
  45.  * 20-May-87  Glenn Marcy (gm0w) at Carnegie-Mellon University
  46.  *    Created.
  47.  *
  48.  **********************************************************************
  49.  */
  50.  
  51. #include <stdio.h>
  52. #include <sys/syslog.h>
  53. #include <c.h>
  54. #if __STDC__
  55. #include <stdarg.h>
  56. #else
  57. #include <varargs.h>
  58. #endif
  59. #include "sup.h"
  60.  
  61. #ifdef    lint
  62. /*VARARGS1*//*ARGSUSED*/
  63. static void quit(status) {};
  64. #endif    /* lint */
  65.  
  66. static int opened = 0;
  67.  
  68. logopen(program)
  69. char *program;
  70. {
  71.     if (opened)  return;
  72.     openlog(program,LOG_PID,LOG_DAEMON);
  73.     opened++;
  74. }
  75.  
  76. #if __STDC__
  77. logquit(int retval,char *fmt,...)
  78. #else
  79. /*VARARGS*//*ARGSUSED*/
  80. logquit(va_alist)
  81. va_dcl
  82. #endif
  83. {
  84. #if !__STDC__
  85.     int retval;
  86.     char *fmt;
  87. #endif
  88.     char buf[STRINGLENGTH];
  89.     va_list ap;
  90.  
  91. #if __STDC__
  92.     va_start(ap,fmt);
  93. #else
  94.     va_start(ap);
  95.     retval = va_arg(ap,int);
  96.     fmt = va_arg(ap,char *);
  97. #endif
  98.     vsnprintf(buf, sizeof(buf), fmt, ap);
  99.     va_end(ap);
  100.     if (opened) {
  101.         syslog (LOG_ERR,buf);
  102.         closelog ();
  103.         exit (retval);
  104.     }
  105.     quit (retval,"SUP: %s\n",buf);
  106. }
  107.  
  108. #if __STDC__
  109. logerr(char *fmt,...)
  110. #else
  111. /*VARARGS*//*ARGSUSED*/
  112. logerr(va_alist)
  113. va_dcl
  114. #endif
  115. {
  116. #if !__STDC__
  117.     char *fmt;
  118. #endif
  119.     char buf[STRINGLENGTH];
  120.     va_list ap;
  121.  
  122. #if __STDC__
  123.     va_start(ap,fmt);
  124. #else
  125.     va_start(ap);
  126.     fmt = va_arg(ap,char *);
  127. #endif
  128.     vsnprintf(buf, sizeof(buf), fmt, ap);
  129.     va_end(ap);
  130.     if (opened) {
  131.         syslog (LOG_ERR,buf);
  132.         return;
  133.     }
  134.     fprintf (stderr,"SUP: %s\n",buf);
  135.     (void) fflush (stderr);
  136. }
  137.  
  138. #if __STDC__
  139. loginfo(char *fmt,...)
  140. #else
  141. /*VARARGS*//*ARGSUSED*/
  142. loginfo(va_alist)
  143. va_dcl
  144. #endif
  145. {
  146. #if !__STDC__
  147.     char *fmt;
  148. #endif
  149.     char buf[STRINGLENGTH];
  150.     va_list ap;
  151.  
  152. #if __STDC__
  153.     va_start(ap,fmt);
  154. #else
  155.     va_start(ap);
  156.     fmt = va_arg(ap,char *);
  157. #endif
  158.     vsnprintf(buf, sizeof(buf), fmt, ap);
  159.     va_end(ap);
  160.     if (opened) {
  161.         syslog (LOG_INFO,buf);
  162.         return;
  163.     }
  164.     printf ("%s\n",buf);
  165.     (void) fflush (stdout);
  166. }
  167.