home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume36 / slurp / part02 / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-12  |  2.3 KB  |  119 lines

  1. /*
  2.  * misc - general miscellaneous routines
  3.  *
  4.  * Copyright (C) 1992/93 Stephen Hebditch. All rights reserved.
  5.  * TQM Communications, BCM Box 225, London, WC1N 3XX.
  6.  * steveh@orbital.demon.co.uk  +44 836 825962
  7.  *
  8.  * See README for more information and disclaimers
  9.  *
  10.  * Assorted miscellaneous routines.
  11.  *
  12.  * $Id: misc.c,v 1.4 1993/02/14 14:53:27 root Exp $
  13.  *
  14.  * $Log: misc.c,v $
  15.  * Revision 1.4  1993/02/14  14:53:27  root
  16.  * In log_sys if any message ids are present, then submit the
  17.  * currently open batch and write out the unretrieved message
  18.  * ids to slurp.<hostname> along with the new time.
  19.  *
  20.  * Revision 1.0  1992/11/27
  21.  * Initial coding.
  22.  *
  23.  */
  24.  
  25. #include "slurp.h"
  26. #include <stdarg.h>
  27.  
  28. static int in_log_sys = FALSE;
  29.  
  30. static void log_doit (int sysflag, const char *fmt, va_list ap);
  31.  
  32.  
  33. /*
  34.  * log_ret - Log a message to stderr or syslog related to a system call
  35.  * containing the appropriate system error message and return.
  36.  */
  37.  
  38.     void
  39. log_ret (const char *fmt, ...)
  40.     {
  41.     va_list ap;
  42.  
  43.     va_start (ap, fmt);
  44.     log_doit (TRUE, fmt, ap);
  45.     va_end (ap);
  46.     return;
  47.     }
  48.  
  49.  
  50. /*
  51.  * log_sys - Log a message to stderr or syslog related to a system call.
  52.  * containing the appropriate system error message and exit program.
  53.  * If any message ids in the tree then write out slurp.<hostname> file
  54.  * and close the batch if open.
  55.  */
  56.  
  57.     void
  58. log_sys (const char *fmt, ...)
  59.     {
  60.     va_list ap;
  61.  
  62.     va_start (ap, fmt);
  63.     log_doit (TRUE, fmt, ap);
  64.     va_end (ap);
  65.     if ((!in_log_sys) && (root != NULL))
  66.         {
  67.         in_log_sys = TRUE;
  68.         enqueue_batch ();
  69.         if ((!no_time_flag) && (!no_id_load_flag))
  70.             set_ntime ();
  71.         }
  72.     exit (1);
  73.     }
  74.  
  75.  
  76. /*
  77.  * log_msg - Log a message to stderr or syslog unrelated to a system call.
  78.  */
  79.  
  80.     void
  81. log_msg (const char *fmt, ...)
  82.     {
  83.     va_list ap;
  84.  
  85.     va_start (ap, fmt);
  86.     log_doit (FALSE, fmt, ap);
  87.     va_end (ap);
  88.     return;
  89.     }
  90.  
  91.  
  92. /*
  93.  * log_doit - Write an error message to stderr if debug_flag is set or
  94.  * syslog if not set. If sysflag is true then the last system error
  95.  * message is appended.
  96.  */
  97.  
  98.     static void
  99. log_doit (int sysflag, const char *fmt, va_list ap)
  100.     {
  101.     int errnosave;
  102.     char buf [BUFSIZ];
  103.  
  104.     errnosave = errno;
  105.     (void) vsprintf (buf, fmt, ap);
  106.     if (sysflag)
  107.         (void) sprintf (buf + strlen (buf), ": %s", strerror (errnosave));
  108.     (void) strcat (buf, "\n");
  109. #ifdef SYSLOG
  110.         if (!debug_flag)
  111.             syslog (LOG_ERR, buf);
  112.         else
  113. #endif
  114.             (void) fprintf (stderr, "%s: %s", pname, buf);
  115.     }
  116.  
  117.  
  118. /* END-OF-FILE */
  119.