log.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included
  9. in all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  14. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  15. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  16. OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall
  18. not be used in advertising or otherwise to promote the sale, use or
  19. other dealings in this Software without prior written authorization
  20. from The Open Group.
  21. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  22. Copyright 1994 Quarterdeck Office Systems.
  23. All Rights Reserved
  24. Permission to use, copy, modify, and distribute this software and its
  25. documentation for any purpose and without fee is hereby granted,
  26. provided that the above copyright notice appear in all copies and that
  27. both that copyright notice and this permission notice appear in
  28. supporting documentation, and that the names of Digital and
  29. Quarterdeck not be used in advertising or publicity pertaining to
  30. distribution of the software without specific, written prior
  31. permission.
  32. DIGITAL AND QUARTERDECK DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  33. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  34. FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
  35. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  36. OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  37. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  38. OR PERFORMANCE OF THIS SOFTWARE.
  39. */
  40. /*
  41. * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
  42. *
  43. * Permission is hereby granted, free of charge, to any person obtaining a
  44. * copy of this software and associated documentation files (the "Software"),
  45. * to deal in the Software without restriction, including without limitation
  46. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  47. * and/or sell copies of the Software, and to permit persons to whom the
  48. * Software is furnished to do so, subject to the following conditions:
  49. *
  50. * The above copyright notice and this permission notice shall be included in
  51. * all copies or substantial portions of the Software.
  52. *
  53. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  54. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  55. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  56. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  57. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  58. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  59. * OTHER DEALINGS IN THE SOFTWARE.
  60. *
  61. * Except as contained in this notice, the name of the copyright holder(s)
  62. * and author(s) shall not be used in advertising or otherwise to promote
  63. * the sale, use or other dealings in this Software without prior written
  64. * authorization from the copyright holder(s) and author(s).
  65. */
  66. #ifdef HAVE_DIX_CONFIG_H
  67. #include <dix-config.h>
  68. #endif
  69. #include <X11/Xos.h>
  70. #include <stdio.h>
  71. #include <time.h>
  72. #include <sys/stat.h>
  73. #include <stdarg.h>
  74. #include <stdlib.h> /* for malloc() */
  75. #include <errno.h>
  76. #include "site.h"
  77. #include "opaque.h"
  78. #ifdef __GNUC__
  79. static void AbortServer(void) __attribute__((noreturn));
  80. #endif
  81. static void
  82. AbortServer(void)
  83. {
  84. OsCleanup(TRUE);
  85. AbortDDX();
  86. fflush(stderr);
  87. if (CoreDump)
  88. abort();
  89. exit (1);
  90. }
  91. #ifndef AUDIT_PREFIX
  92. #define AUDIT_PREFIX "AUDIT: %s: %ld: "
  93. #endif
  94. static char *
  95. AuditPrefix(void)
  96. {
  97. time_t tm;
  98. char *autime, *s;
  99. char *tmpBuf;
  100. int len;
  101. time(&tm);
  102. autime = ctime(&tm);
  103. if ((s = strchr(autime, '\n')))
  104. *s = '\0';
  105. len = strlen(AUDIT_PREFIX) + strlen(autime) + 10 + 1;
  106. tmpBuf = malloc(len);
  107. if (!tmpBuf)
  108. return NULL;
  109. snprintf(tmpBuf, len, AUDIT_PREFIX, autime, (unsigned long)getpid());
  110. return tmpBuf;
  111. }
  112. void
  113. AuditF(const char * f, ...)
  114. {
  115. va_list args;
  116. va_start(args, f);
  117. VAuditF(f, args);
  118. va_end(args);
  119. }
  120. void
  121. VAuditF(const char *f, va_list args)
  122. {
  123. char *prefix;
  124. char buf[1024];
  125. prefix = AuditPrefix();
  126. vsnprintf(buf, sizeof(buf), f, args);
  127. /* XXX Compressing duplicated messages is temporarily disabled to
  128. * work around bugzilla 964:
  129. * https://freedesktop.org/bugzilla/show_bug.cgi?id=964
  130. */
  131. ErrorF("%s%s", prefix != NULL ? prefix : "", buf);
  132. if (prefix != NULL)
  133. free(prefix);
  134. }
  135. _X_EXPORT void
  136. FatalError(const char *f, ...)
  137. {
  138. va_list args;
  139. ErrorF("\nFatal server error:\n");
  140. va_start(args, f);
  141. VErrorF(f, args);
  142. va_end(args);
  143. ErrorF("\n");
  144. AbortServer();
  145. /*NOTREACHED*/
  146. }
  147. _X_EXPORT void
  148. VErrorF(const char *f, va_list args)
  149. {
  150. vfprintf(stderr, f, args);
  151. }
  152. _X_EXPORT void
  153. ErrorF(const char * f, ...)
  154. {
  155. va_list args;
  156. va_start(args, f);
  157. VErrorF(f, args);
  158. va_end(args);
  159. }