summaryrefslogtreecommitdiff
path: root/sanei/sanei_init_debug.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-03-30 21:30:45 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-03-30 21:30:45 +0200
commitee770c2346eb37e0dcb8b6cf3eaacf3d8efd6bbc (patch)
tree58f05092be1a17a939e861f8cadcda1b6ca2ecef /sanei/sanei_init_debug.c
parent0da9e21872802cfc6e975b1ebaf9efb9e5934d84 (diff)
parentfef76e17ed4c607ea73b81279f9ef1d7121be900 (diff)
Merge branch 'release/experimental/1.0.29-1_experimental1'experimental/1.0.29-1_experimental1
Diffstat (limited to 'sanei/sanei_init_debug.c')
-rw-r--r--sanei/sanei_init_debug.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/sanei/sanei_init_debug.c b/sanei/sanei_init_debug.c
index 0abb891..3cde74e 100644
--- a/sanei/sanei_init_debug.c
+++ b/sanei/sanei_init_debug.c
@@ -58,6 +58,8 @@
#include <sys/socket.h>
#endif
#include <sys/stat.h>
+#include <time.h>
+#include <sys/time.h>
#ifdef HAVE_OS2_H
# define INCL_DOS
@@ -107,16 +109,31 @@ sanei_init_debug (const char * backend, int * var)
DBG (0, "Setting debug level of %s to %d.\n", backend, *var);
}
+static int
+is_socket (int fd)
+{
+ struct stat sbuf;
+
+ if (fstat(fd, &sbuf) == -1) return 0;
+
+#if defined(S_ISSOCK)
+ return S_ISSOCK(sbuf.st_mode);
+#elif defined (S_IFMT) && defined(S_IFMT)
+ return (sbuf.st_mode & S_IFMT) == S_IFSOCK;
+#else
+ return 0;
+#endif
+}
+
void
sanei_debug_msg
(int level, int max_level, const char *be, const char *fmt, va_list ap)
{
char *msg;
-
+
if (max_level >= level)
{
-#ifdef S_IFSOCK
- if ( 1 == isfdtype(fileno(stderr), S_IFSOCK) )
+ if (is_socket(fileno(stderr)))
{
msg = (char *)malloc (sizeof(char) * (strlen(be) + strlen(fmt) + 4));
if (msg == NULL)
@@ -132,12 +149,17 @@ sanei_debug_msg
}
}
else
-#endif
{
- fprintf (stderr, "[%s] ", be);
+ struct timeval tv;
+ struct tm *t;
+
+ gettimeofday (&tv, NULL);
+ t = localtime (&tv.tv_sec);
+
+ fprintf (stderr, "[%02d:%02d:%02d.%06ld] [%s] ", t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec, be);
vfprintf (stderr, fmt, ap);
}
-
+
}
}