# Re: net problem

Petter Reinholdtsen (pere@hungry.com)
Fri, 27 Aug 1999 12:42:06 +0200

- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
- Next message: Menaka Lashitha Bandara: "Acer Scanners"
- Previous message: Tom Martone: "Re: SANE V2"
- Maybe in reply to: Wim Taymans: "net problem"

[Petter Reinholdtsen]
> Maybe changing sanei_debug() to send messages to syslog if stderr is
> a socket would be the correct way to fix this.

Here is a patch to change the behavior of DBG(), relative to the
development branch in CVS.

Index: ChangeLog
===================================================================
RCS file: /cvsroot/external/sane/ChangeLog,v
retrieving revision 1.1.1.1.2.6
diff -u -r1.1.1.1.2.6 ChangeLog
--- ChangeLog 1999/08/16 19:15:54 1.1.1.1.2.6
+++ ChangeLog 1999/08/27 10:37:35
@@ -1,3 +1,9 @@
+1999-08-26 Petter Reinholdtsen <pere@td.org.uit.no>
+
+ * include/sane/config.h.in include/sane/sanei_debug.h
+ sanei/sanei_init_debug.c: Send debug messages to syslog if stderr
+ is a socket.
+
1999-08-16 Petter Reinholdtsen <pere@td.org.uit.no>
* configure.in: Turn on more gcc warnings.
Index: include/sane/config.h.in
===================================================================
RCS file: /cvsroot/external/sane/include/sane/config.h.in,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 config.h.in
--- config.h.in 1999/08/09 18:05:44 1.1.1.1
+++ config.h.in 1999/08/27 10:37:36
@@ -221,6 +221,9 @@
/* Define if you have the <sys/select.h> header file. */
#undef HAVE_SYS_SELECT_H
+/* Define if you have the <sys/socket.h> header file. */
+#undef HAVE_SYS_SOCKET_H
+
/* Define if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
Index: include/sane/sanei_debug.h
===================================================================
RCS file: /cvsroot/external/sane/include/sane/sanei_debug.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 sanei_debug.h
--- sanei_debug.h 1999/08/09 18:05:43 1.1.1.1
+++ sanei_debug.h 1999/08/27 10:37:36
@@ -1,5 +1,8 @@
#include <sane/sanei.h>
+#ifndef _SANEI_DEBUG_H
+#define _SANEI_DEBUG_H
+
#define ENTRY(name) PASTE(PASTE(PASTE(sane_,BACKEND_NAME),_),name)
/* The cpp that comes with GNU C 2.5 seems to have troubles understanding
@@ -8,9 +11,7 @@
# define HAVE_VARARG_MACROS
#endif
-#ifndef HAVE_VARARG_MACROS
- extern void sanei_debug (int level, const char *msg, ...);
-#endif
+extern void sanei_debug (int level, const char *msg, ...);
#ifdef NDEBUG
# define DBG_INIT(backend, var)
@@ -23,29 +24,33 @@
#else
# include <stdio.h>
-#define DBG_LEVEL PASTE(sanei_debug_,BACKEND_NAME)
+#define DBG_LEVEL PASTE(sanei_debug_level_,BACKEND_NAME)
#if defined(BACKEND_NAME) && !defined(STUBS)
-int PASTE(sanei_debug_,BACKEND_NAME);
+int DBG_LEVEL;
#endif
# define DBG_INIT() \
- sanei_init_debug (STRINGIFY(BACKEND_NAME), \
- &PASTE(sanei_debug_,BACKEND_NAME))
+ sanei_init_debug (STRINGIFY(BACKEND_NAME), &DBG_LEVEL)
/* The cpp that comes with GNU C 2.5 seems to have troubles understanding
vararg macros. */
#ifdef HAVE_VARARG_MACROS
+extern void sanei_debug_max (int level, int max_level, const char *msg, ...);
# define DBG(level, msg, args...) \
do { \
- if (DBG_LEVEL >= (level)) \
- fprintf (stderr, "[" STRINGIFY(BACKEND_NAME) "] " msg, ##args); \
+ sanei_debug_max ( level, DBG_LEVEL, \
+ "[" STRINGIFY(BACKEND_NAME) "] " msg, ##args); \
} while (0)
extern void sanei_init_debug (const char * backend, int * debug_level_var);
#else
# define DBG sanei_debug
-#endif
+#endif /* HAVE_VARARG_MACROS */
# define IF_DBG(x) x
-#endif
+#endif /* NDEBUG */
+
+#else
+# warning "sane/sanei.h included more then once!"
+#endif /* _SANEI_DEBUG_H */
Index: sanei/sanei_init_debug.c
===================================================================
RCS file: /cvsroot/external/sane/sanei/sanei_init_debug.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 sanei_init_debug.c
--- sanei_init_debug.c 1999/08/09 18:05:59 1.1.1.1
+++ sanei_init_debug.c 1999/08/27 10:37:36
@@ -43,17 +43,25 @@
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <stdarg.h>
+#include <sys/syslog.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <sys/stat.h>
#ifdef __EMX__
# define INCL_DOS
# include <os2.h>
#endif
+#define BACKEND_NAME sanei_debug
#include <sane/sanei_debug.h>
-#ifndef HAVE_VARARG_MACROS
- static int max_level = 0;
-#endif
+static int global_max_level = 0;
void
sanei_init_debug (const char * backend, int * var)
@@ -84,30 +92,38 @@
*var = atoi (val);
-#ifndef HAVE_VARARG_MACROS
- if (*var > max_level)
- max_level = *var;
-#endif
+ if (*var > global_max_level)
+ global_max_level = *var;
- fprintf (stderr, "[sanei_init_debug]: Setting debug level of %s to %d.\n",
- backend, *var);
+ DBG (0, "Setting debug level of %s to %d.\n", backend, *var);
}
-
-#ifndef HAVE_VARARG_MACROS
-#include <stdarg.h>
+static void
+debug_msg (int level, int max_level, const char *fmt, va_list ap)
+{
+ if (max_level >= level)
+ {
+ if ( 1 == isfdtype(fileno(stderr), S_IFSOCK) )
+ vsyslog(LOG_DEBUG, fmt, ap);
+ else
+ vfprintf (stderr, fmt, ap);
+ }
+}
void
sanei_debug (int level, const char *fmt, ...)
{
va_list ap;
-
- if (max_level >= level)
- {
- va_start (ap, fmt);
- vfprintf (stderr, fmt, ap);
- va_end (ap);
- }
+ va_start (ap, fmt);
+ debug_msg (level, global_max_level, fmt, ap);
+ va_end (ap);
}
-#endif /* !HAVE_VARARG_MACROS */
+void
+sanei_debug_max (int level, int max_level, const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ debug_msg (level, max_level, fmt, ap);
+ va_end (ap);
+}

    --
    ##>  Petter Reinholdtsen <##    | pere@td.org.uit.no
     O-  <SCRIPT Language="Javascript">window.close()</SCRIPT>
    http://www.hungry.com/~pere/    | Go Mozilla, go! Go!

    --
    Source code, list archive, and docs: http://www.mostang.com/sane/
    To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com

     Next message: Menaka Lashitha Bandara: "Acer Scanners"
     Previous message: Tom Martone: "Re: SANE V2"
     Maybe in reply to: Wim Taymans: "net problem"