~diwic/ubuntu/lucid/pulseaudio/bugfixes

« back to all changes in this revision

Viewing changes to src/pulsecore/log.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2008-11-04 15:46:00 UTC
  • mfrom: (1.2.1 upstream) (1.1.6 lenny)
  • Revision ID: james.westby@ubuntu.com-20081104154600-hlzknpcazaam0nxm
Tags: 0.9.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Don't build against, and create jack package. Jack is not in main.
  - Remove --disable-per-user-esound-socket from configure flags, as we still
    want per user esound sockets.
  - Remove stop links from rc0 and rc6.
  - Change default resample algorithm and bubffer size.
  - Add alsa configuration files to route alsa applications via pulseaudio.
  - Move libasound2-plugins from Recommends to Depends.
* debian/pulseaudio.preinst: When upgrading from intrepid, remove
  /etc/X11/Xsession.d/70pulseaudio, as this was used to minimize a race
  condition when starting GNOME in intrepid. This race should not exist in
  jaunty once libcanberra is built to use pulseaudio as a backend.
* Do not spawn a pulseaudio server if clients fail to find a running server.
* Remove explicit version dependency for libspeex-dev to allow the package
  to be built for now.
* Regenerate autotools files to work with Ubuntu's newer libtool/libltdl.
* debian/control: libpulsecore5 -> libpulsecore8 to match the library
  soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: log.c 1971 2007-10-28 19:13:50Z lennart $ */
2
 
 
3
1
/***
4
2
  This file is part of PulseAudio.
5
3
 
30
28
#include <stdio.h>
31
29
#include <unistd.h>
32
30
#include <string.h>
 
31
#include <errno.h>
33
32
 
34
33
#ifdef HAVE_SYSLOG_H
35
34
#include <syslog.h>
38
37
#include <pulse/utf8.h>
39
38
#include <pulse/xmalloc.h>
40
39
#include <pulse/util.h>
 
40
#include <pulse/timeval.h>
41
41
 
42
42
#include <pulsecore/macro.h>
43
43
#include <pulsecore/core-util.h>
 
44
#include <pulsecore/rtclock.h>
 
45
#include <pulsecore/once.h>
44
46
 
45
47
#include "log.h"
46
48
 
47
49
#define ENV_LOGLEVEL "PULSE_LOG"
48
50
#define ENV_LOGMETA "PULSE_LOG_META"
 
51
#define ENV_LOGTIME "PULSE_LOG_TIME"
49
52
 
50
53
static char *log_ident = NULL, *log_ident_local = NULL;
51
54
static pa_log_target_t log_target = PA_LOG_STDERR;
52
 
static void (*user_log_func)(pa_log_level_t l, const char *s) = NULL;
53
 
static pa_log_level_t maximal_level = PA_LOG_NOTICE;
 
55
static pa_log_func_t user_log_func = NULL;
 
56
static pa_log_level_t maximal_level = PA_LOG_ERROR;
54
57
 
55
58
#ifdef HAVE_SYSLOG_H
56
59
static const int level_to_syslog[] = {
82
85
/* To make valgrind shut up. */
83
86
static void ident_destructor(void) PA_GCC_DESTRUCTOR;
84
87
static void ident_destructor(void) {
 
88
    if (!pa_in_valgrind())
 
89
        return;
 
90
 
85
91
    pa_xfree(log_ident);
86
92
    pa_xfree(log_ident_local);
87
93
}
92
98
    maximal_level = l;
93
99
}
94
100
 
95
 
void pa_log_set_target(pa_log_target_t t, void (*func)(pa_log_level_t l, const char*s)) {
 
101
void pa_log_set_target(pa_log_target_t t, pa_log_func_t func) {
96
102
    pa_assert(t == PA_LOG_USER || !func);
97
103
 
98
104
    log_target = t;
108
114
        va_list ap) {
109
115
 
110
116
    const char *e;
111
 
    char *text, *t, *n, *location;
 
117
    char *t, *n;
 
118
    int saved_errno = errno;
 
119
 
 
120
    /* We don't use dynamic memory allocation here to minimize the hit
 
121
     * in RT threads */
 
122
    char text[1024], location[128], timestamp[32];
112
123
 
113
124
    pa_assert(level < PA_LOG_LEVEL_MAX);
114
125
    pa_assert(format);
116
127
    if ((e = getenv(ENV_LOGLEVEL)))
117
128
        maximal_level = atoi(e);
118
129
 
119
 
    if (level > maximal_level)
 
130
    if (level > maximal_level) {
 
131
        errno = saved_errno;
120
132
        return;
 
133
    }
121
134
 
122
 
    text = pa_vsprintf_malloc(format, ap);
 
135
    pa_vsnprintf(text, sizeof(text), format, ap);
123
136
 
124
137
    if (getenv(ENV_LOGMETA) && file && line > 0 && func)
125
 
        location = pa_sprintf_malloc("[%s:%i %s()] ", file, line, func);
 
138
        pa_snprintf(location, sizeof(location), "[%s:%i %s()] ", file, line, func);
126
139
    else if (file)
127
 
        location = pa_sprintf_malloc("%s: ", pa_path_get_filename(file));
 
140
        pa_snprintf(location, sizeof(location), "%s: ", pa_path_get_filename(file));
128
141
    else
129
 
        location = pa_xstrdup("");
 
142
        location[0] = 0;
 
143
 
 
144
    if (getenv(ENV_LOGTIME)) {
 
145
        static pa_usec_t start, last;
 
146
        pa_usec_t u, a, r;
 
147
 
 
148
        u = pa_rtclock_usec();
 
149
 
 
150
        PA_ONCE_BEGIN {
 
151
            start = u;
 
152
            last = u;
 
153
        } PA_ONCE_END;
 
154
 
 
155
        r = u - last;
 
156
        a = u - start;
 
157
 
 
158
        /* This is not thread safe, but this is a debugging tool only
 
159
         * anyway. */
 
160
        last = u;
 
161
 
 
162
        pa_snprintf(timestamp, sizeof(timestamp), "(%4llu.%03llu|%4llu.%03llu) ",
 
163
                    (unsigned long long) (a / PA_USEC_PER_SEC),
 
164
                    (unsigned long long) (((a / PA_USEC_PER_MSEC)) % 1000),
 
165
                    (unsigned long long) (r / PA_USEC_PER_SEC),
 
166
                    (unsigned long long) (((r / PA_USEC_PER_MSEC)) % 1000));
 
167
 
 
168
    } else
 
169
        timestamp[0] = 0;
130
170
 
131
171
    if (!pa_utf8_valid(text))
132
172
        pa_log_level(level, __FILE__": invalid UTF-8 string following below:");
158
198
                }
159
199
#endif
160
200
 
 
201
                /* We shouldn't be using dynamic allocation here to
 
202
                 * minimize the hit in RT threads */
161
203
                local_t = pa_utf8_to_locale(t);
162
204
                if (!local_t)
163
 
                    fprintf(stderr, "%c: %s%s%s%s\n", level_to_char[level], location, prefix, t, suffix);
 
205
                    fprintf(stderr, "%s%c: %s%s%s%s\n", timestamp, level_to_char[level], location, prefix, t, suffix);
164
206
                else {
165
 
                    fprintf(stderr, "%c: %s%s%s%s\n", level_to_char[level], location, prefix, local_t, suffix);
 
207
                    fprintf(stderr, "%s%c: %s%s%s%s\n", timestamp, level_to_char[level], location, prefix, local_t, suffix);
166
208
                    pa_xfree(local_t);
167
209
                }
168
210
 
177
219
 
178
220
                local_t = pa_utf8_to_locale(t);
179
221
                if (!local_t)
180
 
                    syslog(level_to_syslog[level], "%s%s", location, t);
 
222
                    syslog(level_to_syslog[level], "%s%s%s", timestamp, location, t);
181
223
                else {
182
 
                    syslog(level_to_syslog[level], "%s%s", location, local_t);
 
224
                    syslog(level_to_syslog[level], "%s%s%s", timestamp, location, local_t);
183
225
                    pa_xfree(local_t);
184
226
                }
185
227
 
189
231
#endif
190
232
 
191
233
            case PA_LOG_USER: {
192
 
                char *x;
 
234
                char x[1024];
193
235
 
194
 
                x = pa_sprintf_malloc("%s%s", location, t);
 
236
                pa_snprintf(x, sizeof(x), "%s%s%s", timestamp, location, t);
195
237
                user_log_func(level, x);
196
 
                pa_xfree(x);
197
238
 
198
239
                break;
199
240
            }
204
245
        }
205
246
    }
206
247
 
207
 
    pa_xfree(text);
208
 
    pa_xfree(location);
 
248
    errno = saved_errno;
209
249
}
210
250
 
211
251
void pa_log_level_meta(