home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / server / os / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-21  |  4.2 KB  |  202 lines

  1. /* $XConsortium: error.c,v 1.4 91/12/09 16:49:23 converse Exp $ */
  2. /*
  3.  * error message handling
  4.  */
  5. /*
  6.  * Copyright 1991 Network Computing Devices;
  7.  * Portions Copyright 1987 by Digital Equipment Corporation and the
  8.  * Massachusetts Institute of Technology
  9.  *
  10.  * Permission to use, copy, modify, and distribute this protoype software
  11.  * and its documentation to Members and Affiliates of the MIT X Consortium
  12.  * any purpose and without fee is hereby granted, provided
  13.  * that the above copyright notice appear in all copies and that both that
  14.  * copyright notice and this permission notice appear in supporting
  15.  * documentation, and that the names of Network Computing Devices, Digital or
  16.  * MIT not be used in advertising or publicity pertaining to distribution of
  17.  * the software without specific, written prior permission.
  18.  *
  19.  * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
  20.  * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  21.  * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
  22.  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  25.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  *
  27.  * $NCDId: @(#)error.c,v 4.1 1991/07/08 18:22:51 lemke Exp $
  28.  *
  29.  */
  30.  
  31. #include    <stdio.h>
  32. #include    <X11/Xos.h>
  33. #ifndef X_NOT_POSIX
  34. #ifdef _POSIX_SOURCE
  35. #include <limits.h>
  36. #else
  37. #define _POSIX_SOURCE
  38. #include <limits.h>
  39. #undef _POSIX_SOURCE
  40. #endif
  41. #endif
  42. #ifndef PATH_MAX
  43. #include <sys/param.h>
  44. #ifndef PATH_MAX
  45. #ifdef MAXPATHLEN
  46. #define PATH_MAX MAXPATHLEN
  47. #else
  48. #define PATH_MAX 1024
  49. #endif
  50. #endif
  51. #endif
  52.  
  53. #ifdef USE_SYSLOG
  54. #include    <syslog.h>
  55. #endif
  56.  
  57. #include    "misc.h"
  58.  
  59. Bool        UseSyslog;
  60. char        ErrorFile[PATH_MAX];
  61.  
  62. static Bool log_open;
  63.  
  64. static void
  65. abort_server()
  66. {
  67.     fflush(stderr);
  68.  
  69. #ifdef SABER
  70.     saber_stop();
  71. #else
  72.     abort();
  73. #endif
  74. }
  75.  
  76. void
  77. InitErrors()
  78. {
  79.     int         i;
  80.  
  81. #ifdef USE_SYSLOG
  82.     if (UseSyslog && !log_open) {
  83.     openlog("Font Server", LOG_PID, LOG_LOCAL0);
  84.     log_open = TRUE;
  85.     return;
  86.     }
  87. #endif
  88.  
  89.     if (ErrorFile[0]) {
  90.     i = creat(ErrorFile, 0666);
  91.     if (i != -1) {
  92.         dup2(i, 2);
  93.         close(i);
  94.     } else {
  95.         ErrorF("Can't open error file \"%s\"\n", ErrorFile);
  96.     }
  97.     }
  98. }
  99.  
  100. void
  101. CloseErrors()
  102. {
  103. #ifdef USE_SYSLOG
  104.     if (UseSyslog) {
  105.     closelog();
  106.     log_open = FALSE;
  107.     return;
  108.     }
  109. #endif
  110. }
  111.  
  112. void
  113. Error(str)
  114.     char       *str;
  115. {
  116.     /* XXX this should also go to syslog() */
  117.     perror(str);
  118. }
  119.  
  120. /*
  121.  * used for informational messages
  122.  */
  123. /* VARARGS1 */
  124. void
  125. NoticeF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)    /* limit of 10 args */
  126.     char       *f;
  127.     char       *s0,
  128.                *s1,
  129.                *s2,
  130.                *s3,
  131.                *s4,
  132.                *s5,
  133.                *s6,
  134.                *s7,
  135.                *s8,
  136.                *s9;
  137. {
  138.  
  139. #ifdef USE_SYSLOG
  140.     if (UseSyslog) {
  141.     syslog(LOG_NOTICE, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  142.     return;
  143.     }
  144. #endif
  145.  
  146.     /* XXX should Notices just be ignored if not using syslog? */
  147.     fprintf(stderr, "Notice: ");
  148.     fprintf(stderr, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  149. }
  150.  
  151. /*
  152.  * used for non-fatal error messages
  153.  */
  154. /* VARARGS1 */
  155. void
  156. ErrorF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)    /* limit of 10 args */
  157.     char       *f;
  158.     char       *s0,
  159.                *s1,
  160.                *s2,
  161.                *s3,
  162.                *s4,
  163.                *s5,
  164.                *s6,
  165.                *s7,
  166.                *s8,
  167.                *s9;
  168. {
  169.  
  170. #ifdef USE_SYSLOG
  171.     if (UseSyslog) {
  172.     syslog(LOG_ERR, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  173.     return;
  174.     }
  175. #endif
  176.  
  177.     fprintf(stderr, "Error: ");
  178.     fprintf(stderr, f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  179. }
  180.  
  181. /* VARARGS1 */
  182. void
  183. FatalError(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9)    /* limit of 10 args */
  184.     char       *f;
  185.     char       *s0,
  186.                *s1,
  187.                *s2,
  188.                *s3,
  189.                *s4,
  190.                *s5,
  191.                *s6,
  192.                *s7,
  193.                *s8,
  194.                *s9;
  195. {
  196.     ErrorF("\nFatal server error!\n");
  197.     ErrorF(f, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9);
  198.     ErrorF("\n");
  199.     abort_server();
  200.     /* NOTREACHED */
  201. }
  202.