Xreset.src: Do not hardcode /usr/dt.
[oweals/cde.git] / cde / programs / dtlogin / bls / debug.c
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 librararies 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  /***************
44     debug.c
45  ****************/
46
47 #ifndef NDEBUG
48 /* don't compile anything in this file unless this is pre-release code */
49 #include <stdio.h> 
50 #include <signal.h>
51 #include "../vg.h"
52 #include "bls.h"
53
54 # include <stdarg.h>
55 # define Va_start(a,b) va_start(a,b)
56
57 char *DisplayName=NULL;
58
59
60 /****************************************************************************
61  *
62  *  Debug
63  *
64  *  Write a debug message to stderr
65  *
66  ****************************************************************************/
67
68 static int  DoName=TRUE;
69 static int  debugLevel=0;
70
71
72 int
73 BLS_ToggleDebug( int arg)
74 {
75         debugLevel = !debugLevel;
76         (void) signal(SIGHUP,BLS_ToggleDebug);
77 }
78
79
80
81 void 
82 Debug( char *fmt, ...)
83 {
84         static int sentinel = 0;
85         static char *debugLog;
86
87     va_list  args;
88
89     Va_start(args,fmt);
90
91
92
93     if ( !sentinel ) {
94     /* 
95      * open up an error log for dtgreet
96      */
97         if ((debugLog = getenv("VG_DEBUG")) == 0)
98                 debugLog = "/usr/lib/X11/dt/Dtlogin/dtgreet.log";
99
100         if ( !freopen(debugLog,"a",stderr)) {
101                 perror("Debug:");
102         }
103         DisplayName=dpyinfo.name;
104         sentinel = 1;
105     }
106
107     if (debugLevel > 0)
108     {
109         if ( strlen(DisplayName) > 0 && DoName)
110             fprintf(stderr, "(%s) ", DisplayName);
111
112         vfprintf (stderr,fmt, args);
113         fflush (stderr);
114
115         /*
116          * don't prepend the display name next time if this debug message
117          * does not contain a "new line" character...
118          */
119
120         if ( strchr(fmt,'\n') == NULL )
121             DoName=FALSE;
122         else
123             DoName=TRUE;
124             
125     }
126
127     va_end(args);
128 }
129
130 #else
131
132 /*
133  * Debug stub for product purposes
134  */
135
136 void 
137 Debug( )
138 { }
139
140 #endif  /* NDEBUG */