From a3bdaac94ea2de068132676d3e27738eacca5278 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 7 Nov 2011 22:05:42 +0000 Subject: [PATCH] log_printf can be called concurently (removed static buffer) print to stdout msg of level <= log_info --- config.h.in | 3 +++ configure | 28 ++++++++++++++++++++++++++++ src/lib/log.c | 13 +++++++++---- src/lib/log.h | 1 + src/ui.c | 3 ++- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/config.h.in b/config.h.in index dc01697..05ed111 100644 --- a/config.h.in +++ b/config.h.in @@ -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 diff --git a/configure b/configure index b221d27..4270cac 100755 --- 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 diff --git a/src/lib/log.c b/src/lib/log.c index b1a5f3d..fdae032 100644 --- a/src/lib/log.c +++ b/src/lib/log.c @@ -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); } diff --git a/src/lib/log.h b/src/lib/log.h index ea303b7..cf4fcd3 100644 --- a/src/lib/log.h +++ b/src/lib/log.h @@ -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 diff --git a/src/ui.c b/src/ui.c index 91816bf..9bf4b82 100644 --- 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 -- 2.7.4