Skip to content

Commit

Permalink
Merge pull request #4 from spiiroin/jb24365_anonymous_spamming
Browse files Browse the repository at this point in the history
Diagnostic logging improvements
  • Loading branch information
spiiroin committed Mar 15, 2015
2 parents 9a46cf1 + 407719c commit 99b7d07
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -204,7 +204,7 @@ install-%-rfs-scripts:
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)

%.a:
$(AR) ru $@ $^
$(AR) r $@ $^

%.pic.o : CFLAGS += -fPIC
%.pic.o : CFLAGS += -fvisibility=hidden
Expand Down
25 changes: 0 additions & 25 deletions database.c
Expand Up @@ -249,31 +249,6 @@ static const char *custom_(const char *profile, const char *key)
return inifile_get(database_custom, profile, key, NULL);
}

/* ------------------------------------------------------------------------- *
* default_ -- helper for getting default value for key
* ------------------------------------------------------------------------- */

static const char *default_(const char *profile, const char *key)
{
/* - - - - - - - - - - - - - - - - - - - *
* profile lookup order:
* 1. config: "override"
* 2. config: caller provided
* 3. config: "fallback"
* - - - - - - - - - - - - - - - - - - - */

const char *res = 0;

if( (res = override_(key)) == 0 )
{
if( (res = config_(profile, key)) == 0 )
{
res = fallback_(key);
}
}
return res;
}

/* ------------------------------------------------------------------------- *
* current_ -- helper for getting current value for key
* ------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion libprofile.c
Expand Up @@ -127,7 +127,7 @@ client_exec_method_call(DBusMessage *msg)

dbus_error_free(&err);

log_debug("%s: %s -> %s\n", "libprofile",
log_debug("%s -> %s\n",
dbus_message_get_member(msg),
(rsp == 0 ) ? "NO REPLY" :
dbus_message_type_to_string(dbus_message_get_type(rsp)));
Expand Down
13 changes: 11 additions & 2 deletions logging_client.c
Expand Up @@ -37,6 +37,7 @@

#include "logging.h"
#include <stdio.h>
#include <stdlib.h>

#ifdef LOGGING_ENABLED

Expand Down Expand Up @@ -76,11 +77,19 @@ log_emit(int level, const char *fmt, ...)
level = log_level_promote;
}

char *msg = 0;

va_list va;
va_start(va, fmt);
//vsyslog(LOG_USER | level, fmt, va);
vsyslog(level, fmt, va);
if( vasprintf(&msg, fmt, va) < 0 )
{
msg = 0;
}
va_end(va);

syslog(level, "libprofile: %s", msg ?: fmt);

free(msg);
}
}

Expand Down
39 changes: 21 additions & 18 deletions tracker.c
Expand Up @@ -208,15 +208,15 @@ static inline void profile_track_profile(const char *profile)
{
if( profile_track_profile_func != 0 )
{
log_debug("%s: %s - %s\n", "libprofile", __FUNCTION__, profile);
log_debug("%s - %s\n", __FUNCTION__, profile);
profile_track_profile_func(profile, profile_track_profile_data);
}

for( size_t i = 0; i < profile_hooks; ++i )
{
profile_hook_t *h = &profile_hook[i];
profile_track_profile_fn_data cb = h->user_cb;
log_debug("%s: %s - %s @ %p %p %p\n", "libprofile", __FUNCTION__, profile,
log_debug("%s - %s @ %p %p %p\n", __FUNCTION__, profile,
h->user_cb, h->data, h->free_cb);
if( cb ) cb(profile, h->data);
}
Expand All @@ -233,7 +233,7 @@ static inline void profile_track_active(const char *profile,
{
if( profile_track_active_func != 0 )
{
log_debug("%s: %s - %s: %s = %s (%s)\n", "libprofile", __FUNCTION__,
log_debug("%s - %s: %s = %s (%s)\n", __FUNCTION__,
profile, key, val, type);

profile_track_active_func(profile, key, val, type,
Expand All @@ -245,8 +245,8 @@ static inline void profile_track_active(const char *profile,
profile_hook_t *h = &active_hook[i];
profile_track_value_fn_data cb = h->user_cb;

log_debug("%s: %s - %s: %s = %s (%s)@ %p %p %p\n",
"libprofile", __FUNCTION__,
log_debug("%s - %s: %s = %s (%s)@ %p %p %p\n",
__FUNCTION__,
profile, key, val, type,
h->user_cb, h->data, h->free_cb);

Expand All @@ -265,7 +265,7 @@ static inline void profile_track_change(const char *profile,
{
if( profile_track_change_func != 0 )
{
log_debug("%s: %s - %s: %s = %s (%s)\n", "libprofile", __FUNCTION__,
log_debug("%s - %s: %s = %s (%s)\n", __FUNCTION__,
profile, key, val, type);

profile_track_change_func(profile, key, val, type,
Expand All @@ -277,8 +277,8 @@ static inline void profile_track_change(const char *profile,
profile_hook_t *h = &change_hook[i];
profile_track_value_fn_data cb = h->user_cb;

log_debug("%s: %s - %s: %s = %s (%s)@ %p %p %p\n",
"libprofile", __FUNCTION__,
log_debug("%s - %s: %s = %s (%s)@ %p %p %p\n",
__FUNCTION__,
profile, key, val, type,
h->user_cb, h->data, h->free_cb);

Expand Down Expand Up @@ -386,13 +386,16 @@ profile_tracker_disconnect(void)
{
ENTER
/* stop listening to profiled signals */
dbus_bus_remove_match(profile_tracker_con, PROFILED_MATCH, &err);

if( dbus_error_is_set(&err) )
if( dbus_connection_get_is_connected(profile_tracker_con) )
{
log_err("%s: %s: %s: %s\n", "libprofile", "dbus_bus_remove_match",
err.name, err.message);
dbus_error_free(&err);
dbus_bus_remove_match(profile_tracker_con, PROFILED_MATCH, &err);

if( dbus_error_is_set(&err) )
{
log_err("%s: %s: %s\n", "dbus_bus_remove_match",
err.name, err.message);
dbus_error_free(&err);
}
}

/* remove message filter function */
Expand Down Expand Up @@ -439,7 +442,7 @@ profile_tracker_connect(void)
/* Register message filter */
if( !dbus_connection_add_filter(profile_tracker_con, profile_tracker_filter, 0, 0) )
{
log_err("%s: %s: %s: %s\n", "libprofile", "dbus_connection_add_filter",
log_err("%s: %s: %s\n", "dbus_connection_add_filter",
err.name, err.message);
goto cleanup;
}
Expand All @@ -449,7 +452,7 @@ profile_tracker_connect(void)

if( dbus_error_is_set(&err) )
{
log_err("%s: %s: %s: %s\n", "libprofile", "dbus_bus_add_match",
log_err("%s: %s: %s\n", "dbus_bus_add_match",
err.name, err.message);
goto cleanup;
}
Expand Down Expand Up @@ -601,7 +604,7 @@ profile_tracker_init(void)
profileval_t *val = 0;
#endif

log_debug("%s: init tracker ...\n", "libprofile");
log_debug("init tracker ...\n");

/* Establish dbus connection */
if( profile_tracker_connect() == -1 )
Expand Down Expand Up @@ -641,7 +644,7 @@ profile_tracker_init(void)
free(cur);
#endif

log_debug("%s: init tracker -> %s\n", "libprofile",
log_debug("init tracker -> %s\n",
(res == 0) ? "OK" : "FAILED");

/* Flag: client wants to use tracker */
Expand Down

0 comments on commit 99b7d07

Please sign in to comment.