~ubuntu-branches/ubuntu/trusty/soundmodem/trusty

« back to all changes in this revision

Viewing changes to .pc/fix-syslog-format-security-err.patch/soundcard/log.c

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2012-12-15 07:56:39 UTC
  • mfrom: (1.3.5)
  • Revision ID: package-import@ubuntu.com-20121215075639-b8iwwf0d4mo5cqig
Tags: 0.18-1
* New upstream release
* Debian packaging:
  - dropped debian/patches merged upstream
  - replaced Build-deps exclusion list with [linux-any] (Closes: #634624)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************/
2
 
 
3
 
/*
4
 
 *      log.c  --  Logging functions.
5
 
 *
6
 
 *      Copyright (C) 1999-2000  Thomas Sailer (sailer@ife.ee.ethz.ch)
7
 
 *
8
 
 *      This program is free software; you can redistribute it and/or modify
9
 
 *      it under the terms of the GNU General Public License as published by
10
 
 *      the Free Software Foundation; either version 2 of the License, or
11
 
 *      (at your option) any later version.
12
 
 *
13
 
 *      This program is distributed in the hope that it will be useful,
14
 
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 *      GNU General Public License for more details.
17
 
 *
18
 
 *      You should have received a copy of the GNU General Public License
19
 
 *      along with this program; if not, write to the Free Software
20
 
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
 
 *
22
 
 *  Please note that the GPL allows you to use the driver, NOT the radio.
23
 
 *  In order to use the radio, you need a license from the communications
24
 
 *  authority of your country.
25
 
 *
26
 
 */
27
 
 
28
 
/*****************************************************************************/
29
 
 
30
 
#define _GNU_SOURCE
31
 
#define _REENTRANT
32
 
 
33
 
#ifdef HAVE_CONFIG_H
34
 
#include "config.h"
35
 
#endif
36
 
 
37
 
#include "soundio.h"
38
 
 
39
 
#ifdef HAVE_SYSLOG_H
40
 
#include <syslog.h>
41
 
#endif
42
 
 
43
 
#include <sys/types.h>
44
 
#include <unistd.h>
45
 
#include <stdio.h>
46
 
#include <errno.h>
47
 
#include <string.h>
48
 
#include <stdlib.h>
49
 
 
50
 
/* ---------------------------------------------------------------------- */
51
 
 
52
 
static unsigned int tosyslog = 0;
53
 
unsigned int log_verblevel = 0;
54
 
 
55
 
/* ---------------------------------------------------------------------- */
56
 
 
57
 
void logrelease(void)
58
 
{
59
 
#ifdef HAVE_CLOSELOG
60
 
        if (tosyslog)
61
 
                closelog();
62
 
#endif
63
 
        tosyslog = 0;
64
 
}
65
 
 
66
 
void loginit(unsigned int vl, unsigned int tosysl)
67
 
{
68
 
        log_verblevel = vl;
69
 
        tosyslog = 0;
70
 
#ifdef HAVE_OPENLOG
71
 
        if (tosysl) {
72
 
                openlog("soundmodem", LOG_PID, LOG_DAEMON);
73
 
                tosyslog = 1;
74
 
        }
75
 
#endif
76
 
}
77
 
 
78
 
void logvprintf(unsigned int level, const char *fmt, va_list args)
79
 
{
80
 
        static const int vltosev[] = { LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE };
81
 
 
82
 
        if (level <= log_verblevel) {
83
 
#ifdef HAVE_SYSLOG
84
 
                if (tosyslog) {
85
 
                        char tmp[512];
86
 
                        vsnprintf(tmp, sizeof(tmp), fmt, args);
87
 
                        syslog((level >= 256) ? LOG_DEBUG : (level >= 4) ? LOG_INFO : vltosev[level], tmp);
88
 
                } else
89
 
#endif
90
 
                {
91
 
                        fprintf(stderr, "sm[%lu]: ", (unsigned long)getpid());
92
 
                        vfprintf(stderr, fmt, args);
93
 
                }
94
 
        }
95
 
        if (!level)
96
 
                exit(1);
97
 
}
98
 
 
99
 
void logprintf(unsigned int level, const char *fmt, ...)
100
 
{
101
 
        va_list args;
102
 
 
103
 
        va_start(args, fmt);
104
 
        logvprintf(level, fmt, args);
105
 
        va_end(args);
106
 
}
107
 
 
108
 
void logerr(unsigned int level, const char *st)
109
 
{
110
 
        logprintf(level, "%s: %s (%d)\n", st, strerror(errno), errno);
111
 
}
112