]> pere.pagekite.me Git - homepage.git/blob - linux/sane/sane-debug-to-syslog.patch
Switched blog to hungry.com for now. Updated all links.
[homepage.git] / linux / sane / sane-debug-to-syslog.patch
1 Index: ChangeLog
2 ===================================================================
3 RCS file: /cvsroot/external/sane/ChangeLog,v
4 retrieving revision 1.1.1.1.2.115
5 diff -u -r1.1.1.1.2.115 ChangeLog
6 --- ChangeLog 2000/03/18 03:14:11 1.1.1.1.2.115
7 +++ ChangeLog 2000/03/18 03:19:11
8 @@ -1,5 +1,10 @@
9 2000-03-18 Petter Reinholdtsen <pere@td.org.uit.no>
10
11 + * include/sane/sanei_debug.h sanei/sanei_init_debug.c: Send debug
12 + messages to syslog if stderr is a socket.
13 +
14 +2000-03-18 Petter Reinholdtsen <pere@td.org.uit.no>
15 +
16 * backend/Makefile.in tools/libtool-get-dll-ext: New script to
17 detect shared library endings without using 'rev' which is missing
18 on some platforms.
19 Index: include/sane/sanei_debug.h
20 ===================================================================
21 RCS file: /cvsroot/external/sane/include/sane/sanei_debug.h,v
22 retrieving revision 1.1.1.1.2.1
23 diff -u -r1.1.1.1.2.1 sanei_debug.h
24 --- sanei_debug.h 2000/01/25 15:37:55 1.1.1.1.2.1
25 +++ sanei_debug.h 2000/03/18 03:19:12
26 @@ -1,3 +1,6 @@
27 +#ifndef _SANEI_DEBUG_H
28 +#define _SANEI_DEBUG_H
29 +
30 #include <sane/sanei.h>
31
32 #define ENTRY(name) PASTE(PASTE(PASTE(sane_,BACKEND_NAME),_),name)
33 @@ -8,9 +11,7 @@
34 # define HAVE_VARARG_MACROS
35 #endif
36
37 -#ifndef HAVE_VARARG_MACROS
38 - extern void sanei_debug (int level, const char *msg, ...);
39 -#endif
40 +extern void sanei_debug (int level, const char *msg, ...);
41
42 #ifdef NDEBUG
43 # define DBG_INIT(backend, var)
44 @@ -26,28 +27,31 @@
45 #define DBG_LEVEL PASTE(sanei_debug_,BACKEND_NAME)
46
47 #if defined(BACKEND_NAME) && !defined(STUBS)
48 -int PASTE(sanei_debug_,BACKEND_NAME);
49 +int DBG_LEVEL;
50 #endif
51
52 # define DBG_INIT() \
53 - sanei_init_debug (STRINGIFY(BACKEND_NAME), \
54 - &PASTE(sanei_debug_,BACKEND_NAME))
55 + sanei_init_debug (STRINGIFY(BACKEND_NAME), &DBG_LEVEL)
56
57 /* The cpp that comes with GNU C 2.5 seems to have troubles understanding
58 vararg macros. */
59 #ifdef HAVE_VARARG_MACROS
60 +extern void sanei_debug_max (int level, int max_level, const char *msg, ...);
61 +
62 # define DBG(level, msg, args...) \
63 do { \
64 - if (DBG_LEVEL >= (level)){ \
65 - fprintf (stderr, "[" STRINGIFY(BACKEND_NAME) "] " msg, ##args); \
66 - fflush(stderr); \
67 - } \
68 + sanei_debug_max ( level, DBG_LEVEL, \
69 + "[" STRINGIFY(BACKEND_NAME) "] " msg, ##args); \
70 } while (0)
71
72 extern void sanei_init_debug (const char * backend, int * debug_level_var);
73 #else
74 # define DBG sanei_debug
75 -#endif
76 +#endif /* HAVE_VARARG_MACROS */
77
78 # define IF_DBG(x) x
79 -#endif
80 +#endif */ NDEBUG */
81 +
82 +#else
83 +# warning "sane/sanei_debug.h included more then once!"
84 +#endif /* _SANEI_DEBUG_H */
85 Index: sanei/sanei_init_debug.c
86 ===================================================================
87 RCS file: /cvsroot/external/sane/sanei/sanei_init_debug.c,v
88 retrieving revision 1.1.1.1
89 diff -u -r1.1.1.1 sanei_init_debug.c
90 --- sanei_init_debug.c 1999/08/09 18:05:59 1.1.1.1
91 +++ sanei_init_debug.c 2000/03/18 03:19:12
92 @@ -43,24 +43,33 @@
93 #include <ctype.h>
94 #include <stdio.h>
95 #include <stdlib.h>
96 +#ifdef HAVE_UNISTD_H
97 +#include <unistd.h>
98 +#endif
99 +#include <stdarg.h>
100 +#include <sys/syslog.h>
101 +#ifdef HAVE_SYS_SOCKET_H
102 +#include <sys/socket.h>
103 +#endif
104 +#include <sys/stat.h>
105
106 #ifdef __EMX__
107 # define INCL_DOS
108 # include <os2.h>
109 #endif
110
111 +#define BACKEND_NAME sanei_debug
112 #include <sane/sanei_debug.h>
113
114 -#ifndef HAVE_VARARG_MACROS
115 - static int max_level = 0;
116 -#endif
117 +static int global_max_level = 0;
118 +
119
120 void
121 sanei_init_debug (const char * backend, int * var)
122 {
123 char ch, buf[256] = "SANE_DEBUG_";
124 const char * val;
125 - int i;
126 + unsigned int i;
127
128 *var = 0;
129
130 @@ -84,30 +93,38 @@
131
132 *var = atoi (val);
133
134 -#ifndef HAVE_VARARG_MACROS
135 - if (*var > max_level)
136 - max_level = *var;
137 -#endif
138 + if (*var > global_max_level)
139 + global_max_level = *var;
140
141 - fprintf (stderr, "[sanei_init_debug]: Setting debug level of %s to %d.\n",
142 - backend, *var);
143 + DBG (0, "Setting debug level of %s to %d.\n", backend, *var);
144 }
145
146 -#ifndef HAVE_VARARG_MACROS
147 -
148 -#include <stdarg.h>
149 +static void
150 +debug_msg (int level, int max_level, const char *fmt, va_list ap)
151 +{
152 + if (max_level >= level)
153 + {
154 + if ( 1 == isfdtype(fileno(stderr), S_IFSOCK) )
155 + vsyslog(LOG_DEBUG, fmt, ap);
156 + else
157 + vfprintf (stderr, fmt, ap);
158 + }
159 +}
160
161 void
162 sanei_debug (int level, const char *fmt, ...)
163 {
164 va_list ap;
165 -
166 - if (max_level >= level)
167 - {
168 - va_start (ap, fmt);
169 - vfprintf (stderr, fmt, ap);
170 - va_end (ap);
171 - }
172 + va_start (ap, fmt);
173 + debug_msg (level, global_max_level, fmt, ap);
174 + va_end (ap);
175 }
176
177 -#endif /* !HAVE_VARARG_MACROS */
178 +void
179 +sanei_debug_max (int level, int max_level, const char *fmt, ...)
180 +{
181 + va_list ap;
182 + va_start (ap, fmt);
183 + debug_msg (level, max_level, fmt, ap);
184 + va_end (ap);
185 +}