~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to modules/linux/vsock/linux/driverLog.c

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-15 21:21:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080815212140-05fhxj8wroosysmj
Tags: 2008.08.08-109361-1ubuntu1
* Merge from Debian unstable (LP: #258393), remaining Ubuntu change:
  - add ubuntu_toolchain_FTBFS.dpatch patch, fix FTBFS
* Update ubuntu_toolchain_FTBFS.dpatch patch for the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2007 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License as published by the
 
6
 * Free Software Foundation version 2 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
11
 * for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
 
 
20
/*
 
21
 * driverLog.c --
 
22
 *
 
23
 *      Common logging functions for Linux kernel modules.
 
24
 */
 
25
 
 
26
#include "driver-config.h"
 
27
#include "compat_kernel.h"
 
28
#include "compat_sched.h"
 
29
#include <asm/current.h>
 
30
 
 
31
#include "driverLog.h"
 
32
 
 
33
#define LINUXLOG_BUFFER_SIZE 1024
 
34
 
 
35
static const char *driverLogPrefix = "";
 
36
 
 
37
/*
 
38
 * vsnprintf was born in 2.4.10. Fall back on vsprintf if we're
 
39
 * an older kernel.
 
40
 */
 
41
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 10)
 
42
# define vsnprintf(str, size, fmt, args) vsprintf(str, fmt, args)
 
43
#endif
 
44
 
 
45
 
 
46
/*
 
47
 *----------------------------------------------------------------------------
 
48
 *
 
49
 * DriverLog_Init --
 
50
 *
 
51
 *      Initializes the Linux logging.
 
52
 *
 
53
 * Results:
 
54
 *      None.
 
55
 *
 
56
 * Side effects:
 
57
 *      None.
 
58
 *
 
59
 *----------------------------------------------------------------------------
 
60
 */
 
61
 
 
62
void
 
63
DriverLog_Init(const char *prefix) // IN
 
64
{
 
65
   driverLogPrefix = prefix ? prefix : "";
 
66
}
 
67
 
 
68
 
 
69
/*
 
70
 *----------------------------------------------------------------------
 
71
 *
 
72
 * DriverLogPrint --
 
73
 *
 
74
 *      Log error message from a Linux module.
 
75
 *
 
76
 * Results:
 
77
 *      None.
 
78
 *
 
79
 * Side effects:
 
80
 *      None.
 
81
 *
 
82
 *----------------------------------------------------------------------
 
83
 */
 
84
 
 
85
static void
 
86
DriverLogPrint(const char *level,     // IN: KERN_* constant
 
87
               const char *fmt,       // IN: error format string
 
88
               va_list args)          // IN: arguments for format string
 
89
{
 
90
   static char staticBuf[LINUXLOG_BUFFER_SIZE];
 
91
   char stackBuf[128];
 
92
   va_list args2;
 
93
   const char *buf;
 
94
 
 
95
   /*
 
96
    * By default, use a small buffer on the stack (thread safe). If it is too
 
97
    * small, fall back to a larger static buffer (not thread safe).
 
98
    */
 
99
   va_copy(args2, args);
 
100
   if (vsnprintf(stackBuf, sizeof stackBuf, fmt, args2) < sizeof stackBuf) {
 
101
      buf = stackBuf;
 
102
   } else {
 
103
      vsnprintf(staticBuf, sizeof staticBuf, fmt, args);
 
104
      buf = staticBuf;
 
105
   }
 
106
   va_end(args2);
 
107
 
 
108
   printk("%s%s[%d]: %s", level, driverLogPrefix, current->pid, buf);
 
109
}
 
110
 
 
111
 
 
112
/*
 
113
 *----------------------------------------------------------------------
 
114
 *
 
115
 * Warning --
 
116
 *
 
117
 *      Warning messages from kernel module: logged into kernel log
 
118
 *      as warnings.
 
119
 *
 
120
 * Results:
 
121
 *      None.
 
122
 *
 
123
 * Side effects:
 
124
 *      None.
 
125
 *
 
126
 *----------------------------------------------------------------------
 
127
 */
 
128
 
 
129
void
 
130
Warning(const char *fmt, ...)  // IN: warning format string
 
131
{
 
132
   va_list args;
 
133
 
 
134
   va_start(args, fmt);
 
135
   DriverLogPrint(KERN_WARNING, fmt, args);
 
136
   va_end(args);
 
137
}
 
138
 
 
139
 
 
140
/*
 
141
 *----------------------------------------------------------------------
 
142
 *
 
143
 * Log --
 
144
 *
 
145
 *      Log messages from kernel module: logged into kernel log
 
146
 *      as debug information.
 
147
 *
 
148
 * Results:
 
149
 *      None.
 
150
 *
 
151
 * Side effects:
 
152
 *      None.
 
153
 *
 
154
 *----------------------------------------------------------------------
 
155
 */
 
156
 
 
157
void
 
158
Log(const char *fmt, ...)  // IN: log format string
 
159
{
 
160
   va_list args;
 
161
 
 
162
   /*
 
163
    * Use the kernel log with at least a KERN_DEBUG level
 
164
    * so it doesn't garbage the screen at (re)boot time on RedHat 6.0.
 
165
    */
 
166
 
 
167
   va_start(args, fmt);
 
168
   DriverLogPrint(KERN_DEBUG, fmt, args);
 
169
   va_end(args);
 
170
}
 
171
 
 
172
 
 
173
/*
 
174
 *----------------------------------------------------------------------
 
175
 *
 
176
 * Panic --
 
177
 *
 
178
 *      ASSERTION failures and Panics from kernel module get here.
 
179
 *      Message is logged to the kernel log and on console.
 
180
 *
 
181
 * Results:
 
182
 *      None.
 
183
 *
 
184
 * Side effects:
 
185
 *      Never returns
 
186
 *
 
187
 *----------------------------------------------------------------------
 
188
 */
 
189
 
 
190
void
 
191
Panic(const char *fmt, ...)  // IN: panic format string
 
192
{
 
193
   va_list args;
 
194
 
 
195
   va_start(args, fmt);
 
196
   DriverLogPrint(KERN_EMERG, fmt, args);
 
197
   va_end(args);
 
198
 
 
199
#ifdef BUG
 
200
   BUG();
 
201
#else
 
202
   /* Should die with %cs unwritable, or at least with page fault. */
 
203
   asm volatile("movb $0, %cs:(0)");
 
204
#endif
 
205
 
 
206
   while (1);
 
207
}