~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kdm/backend/error.c

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright 1988, 1998  The Open Group
 
4
Copyright 2000-2004 Oswald Buddenhagen <ossi@kde.org>
 
5
 
 
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.
 
11
 
 
12
The above copyright notice and this permission notice shall be included
 
13
in all copies or substantial portions of the Software.
 
14
 
 
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.
 
22
 
 
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.
 
27
 
 
28
*/
 
29
 
 
30
/*
 
31
 * xdm - display manager daemon
 
32
 * Author: Keith Packard, MIT X Consortium
 
33
 *
 
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
 
37
 */
 
38
 
 
39
#include "dm.h"
 
40
#include "dm_error.h"
 
41
#include <unistd.h>
 
42
#include <stdio.h>
 
43
 
 
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"
 
51
 
 
52
void
 
53
gDebug(const char *fmt, ...)
 
54
{
 
55
    va_list args;
 
56
 
 
57
    if (debugLevel & DEBUG_HLPCON) {
 
58
        va_start(args, fmt);
 
59
        logger(DM_DEBUG, fmt, args);
 
60
        va_end(args);
 
61
    }
 
62
}
 
63
 
 
64
void
 
65
panic(const char *mesg)
 
66
{
 
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);
 
76
}
 
77
 
 
78
#ifdef USE_SYSLOG
 
79
void
 
80
reInitErrorLog()
 
81
{
 
82
    if (!(debugLevel & DEBUG_NOSYSLOG))
 
83
        InitLog();
 
84
}
 
85
#endif
 
86
 
 
87
void
 
88
initErrorLog(const char *errorLogFile)
 
89
{
 
90
    int fd;
 
91
    char buf[128];
 
92
 
 
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.
 
98
     */
 
99
    if (!errorLogFile || strcmp(errorLogFile, "-")) {
 
100
        if (!errorLogFile) {
 
101
            sprintf(buf, "/var/log/%s.log", prog);
 
102
            errorLogFile = buf;
 
103
        }
 
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);
 
126
        }
 
127
    }
 
128
}
 
129