debug.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * xdm - display manager daemon
  25. *
  26. * $XConsortium: debug.c /main/3 1995/07/14 13:23:25 drk $
  27. *
  28. * Copyright 1988 Massachusetts Institute of Technology
  29. *
  30. * Permission to use, copy, modify, and distribute this software and its
  31. * documentation for any purpose and without fee is hereby granted, provided
  32. * that the above copyright notice appear in all copies and that both that
  33. * copyright notice and this permission notice appear in supporting
  34. * documentation, and that the name of M.I.T. not be used in advertising or
  35. * publicity pertaining to distribution of the software without specific,
  36. * written prior permission. M.I.T. makes no representations about the
  37. * suitability of this software for any purpose. It is provided "as is"
  38. * without express or implied warranty.
  39. *
  40. * Author: Keith Packard, MIT X Consortium
  41. */
  42. /***************
  43. debug.c
  44. ****************/
  45. #ifndef NDEBUG
  46. /* don't compile anything in this file unless this is pre-release code */
  47. #include <stdio.h>
  48. #include <signal.h>
  49. #include "../vg.h"
  50. #include "bls.h"
  51. # include <stdarg.h>
  52. # define Va_start(a,b) va_start(a,b)
  53. char *DisplayName=NULL;
  54. /****************************************************************************
  55. *
  56. * Debug
  57. *
  58. * Write a debug message to stderr
  59. *
  60. ****************************************************************************/
  61. static int DoName=TRUE;
  62. static int debugLevel=0;
  63. int
  64. BLS_ToggleDebug( int arg)
  65. {
  66. debugLevel = !debugLevel;
  67. (void) signal(SIGHUP,BLS_ToggleDebug);
  68. }
  69. void
  70. Debug( char *fmt, ...)
  71. {
  72. static int sentinel = 0;
  73. static char *debugLog;
  74. va_list args;
  75. Va_start(args,fmt);
  76. if ( !sentinel ) {
  77. /*
  78. * open up an error log for dtgreet
  79. */
  80. if ((debugLog = getenv("VG_DEBUG")) == 0)
  81. debugLog = "/usr/lib/X11/dt/Dtlogin/dtgreet.log";
  82. if ( !freopen(debugLog,"a",stderr)) {
  83. perror("Debug:");
  84. }
  85. DisplayName=dpyinfo.name;
  86. sentinel = 1;
  87. }
  88. if (debugLevel > 0)
  89. {
  90. if ( strlen(DisplayName) > 0 && DoName)
  91. fprintf(stderr, "(%s) ", DisplayName);
  92. vfprintf (stderr,fmt, args);
  93. fflush (stderr);
  94. /*
  95. * don't prepend the display name next time if this debug message
  96. * does not contain a "new line" character...
  97. */
  98. if ( strchr(fmt,'\n') == NULL )
  99. DoName=FALSE;
  100. else
  101. DoName=TRUE;
  102. }
  103. va_end(args);
  104. }
  105. #else
  106. /*
  107. * Debug stub for product purposes
  108. */
  109. void
  110. Debug( )
  111. { }
  112. #endif /* NDEBUG */