Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kdm / backend / error.c
blobe806cf02d3c5eab76f9cf21f8a9477f2984cd3c6
1 /*
3 Copyright 1988, 1998 The Open Group
4 Copyright 2000-2004 Oswald Buddenhagen <ossi@kde.org>
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
10 documentation.
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of a copyright holder shall
24 not be used in advertising or otherwise to promote the sale, use or
25 other dealings in this Software without prior written authorization
26 from the copyright holder.
31 * xdm - display manager daemon
32 * Author: Keith Packard, MIT X Consortium
34 * Log display manager errors to a file as
35 * we generally do not have a terminal to talk to
36 * or use syslog if it exists
39 #include "dm.h"
40 #include "dm_error.h"
41 #include <unistd.h>
42 #include <stdio.h>
44 #define PRINT_QUOTES
45 #define PRINT_ARRAYS
46 #define LOG_DEBUG_MASK DEBUG_CORE
47 #define LOG_PANIC_EXIT 1
48 #define NEED_ASPRINTF
49 #define STATIC
50 #include "printf.c"
52 void
53 gDebug( const char *fmt, ... )
55 va_list args;
57 if (debugLevel & DEBUG_HLPCON) {
58 va_start( args, fmt );
59 logger( DM_DEBUG, fmt, args );
60 va_end( args );
64 void
65 panic( const char *mesg )
67 int fd = open( "/dev/console", O_WRONLY );
68 write( fd, "xdm panic: ", 11 );
69 write( fd, mesg, strlen( mesg ) );
70 write( fd, "\n", 1 );
71 #ifdef USE_SYSLOG
72 reInitErrorLog();
73 syslog( LOG_ALERT, "%s", mesg );
74 #endif
75 exit( 1 );
78 #ifdef USE_SYSLOG
79 void
80 reInitErrorLog()
82 if (!(debugLevel & DEBUG_NOSYSLOG))
83 InitLog();
85 #endif
87 void
88 initErrorLog( const char *errorLogFile )
90 int fd;
91 char buf[128];
93 #ifdef USE_SYSLOG
94 reInitErrorLog();
95 #endif
96 /* We do this independently of using syslog, as we cannot redirect
97 * the output of external programs to syslog.
99 if (!errorLogFile || strcmp( errorLogFile, "-" )) {
100 if (!errorLogFile) {
101 sprintf( buf, "/var/log/%s.log", prog );
102 errorLogFile = buf;
104 if ((fd = open( errorLogFile, O_CREAT | O_APPEND | O_WRONLY, 0666 )) < 0)
105 logError( "Cannot open log file %s\n", errorLogFile );
106 else {
107 #ifdef USE_SYSLOG
108 # ifdef USE_PAM
109 # define PAMLOG " PAM logs messages related to authentication to authpriv.*."
110 # else
111 # define PAMLOG
112 # endif
113 # define WARNMSG \
114 "********************************************************************************\n" \
115 "Note that your system uses syslog. All of kdm's internally generated messages\n" \
116 "(i.e., not from libraries and external programs/scripts it uses) go to the\n" \
117 "daemon.* syslog facility; check your syslog configuration to find out to which\n" \
118 "file(s) it is logged." PAMLOG "\n" \
119 "********************************************************************************\n\n"
120 if (!lseek( fd, 0, SEEK_END ))
121 write( fd, WARNMSG, sizeof(WARNMSG) - 1 );
122 #endif
123 dup2( fd, 1 );
124 close( fd );
125 dup2( 1, 2 );