log_printf can be called concurently (removed static buffer)
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 7 Nov 2011 22:05:42 +0000 (22:05 +0000)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 7 Nov 2011 22:05:42 +0000 (22:05 +0000)
print to stdout msg of level <= log_info

config.h.in
configure
src/lib/log.c
src/lib/log.h
src/ui.c

index dc01697..05ed111 100644 (file)
@@ -40,6 +40,9 @@
 /* Define to 1 if you have the `gettimeofday' function. */
 #undef HAVE_GETTIMEOFDAY
 
+/* Use GTK3 */
+#undef HAVE_GTK3
+
 /* Use GTOP */
 #undef HAVE_GTOP
 
index b221d27..4270cac 100755 (executable)
--- a/configure
+++ b/configure
@@ -645,6 +645,8 @@ LIBNOTIFY_LIBS
 LIBNOTIFY_CFLAGS
 GCONF_LIBS
 GCONF_CFLAGS
+GTK_FALSE
+GTK_TRUE
 GTK_LIBS
 GTK_CFLAGS
 XEXT_LIBS
@@ -7371,10 +7373,20 @@ else
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
+$as_echo "#define HAVE_GTK3 1" >>confdefs.h
+
+fi
+ if test -n "$GTK_LIBS"; then
+  GTK_TRUE=
+  GTK_FALSE='#'
+else
+  GTK_TRUE='#'
+  GTK_FALSE=
 fi
 
 
 
+
 if test "$GTK_LIBS" == ""; then
 
 pkg_failed=no
@@ -7467,6 +7479,14 @@ else
 $as_echo "yes" >&6; }
 
 fi
+    if test -n "$GTK_LIBS"; then
+  GTK_TRUE=
+  GTK_FALSE='#'
+else
+  GTK_TRUE='#'
+  GTK_FALSE=
+fi
+
 
 
 fi
@@ -8703,6 +8723,14 @@ if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then
   as_fn_error $? "conditional \"am__fastdepCC\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${GTK_TRUE}" && test -z "${GTK_FALSE}"; then
+  as_fn_error $? "conditional \"GTK\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${GTK_TRUE}" && test -z "${GTK_FALSE}"; then
+  as_fn_error $? "conditional \"GTK\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${LIBNOTIFY_TRUE}" && test -z "${LIBNOTIFY_FALSE}"; then
   as_fn_error $? "conditional \"LIBNOTIFY\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
index b1a5f3d..fdae032 100644 (file)
@@ -54,11 +54,11 @@ void log_close()
 void log_printf(int lvl, const char *fmt, ...)
 {
        struct timeval tv;
-       static char buffer[1 + LOG_BUFFER];
+       char buffer[1 + LOG_BUFFER];
        va_list ap;
        char *lvl_str;
 
-       if (!file || lvl > log_level)
+       if (lvl > LOG_INFO && (!file || lvl > log_level))
                return ;
 
        va_start(ap, fmt);
@@ -86,6 +86,11 @@ void log_printf(int lvl, const char *fmt, ...)
                lvl_str = "[??]";
        }
 
-       fprintf(file, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
-       fflush(file);
+       if (file && lvl <= log_level) {
+               fprintf(file, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
+               fflush(file);
+       }
+
+       if (lvl <= LOG_INFO)
+               printf("[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
 }
index ea303b7..cf4fcd3 100644 (file)
@@ -33,6 +33,7 @@ void log_printf(int lvl, const char *fmt, ...);
 
 void log_close();
 
+/* level of the log file. */
 extern int log_level;
 
 #endif
index 91816bf..9bf4b82 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -72,7 +72,8 @@ on_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
                log_printf(LOG_DEBUG, "hiding, WM is supporting appindicator");
                gtk_widget_hide(ui->main_window);
        } else {
-               log_printf(LOG_DEBUG, "quitting, WM not supporting appindicator");
+               log_printf(LOG_DEBUG,
+                          "quitting, WM not supporting appindicator");
                ui_psensor_quit(ui);
        }
 #else