Commit 0a817747 authored by spiiroin's avatar spiiroin

[logging] Add enablers for exposing call stack

When debugging complex issues it can be helpful know also which thread is
emitting the diagnostic message and the code path that led to the situation.

This is meant to be used as a development time debugging feature and thus
requires enabling during build time - otherwise all related code is excluded
from usb-moded binary.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 0facd5b1
......@@ -63,6 +63,8 @@ static int android_probed = -1;
static bool
android_write_file(const char *path, const char *text)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( !path || !text )
......@@ -86,6 +88,8 @@ EXIT:
bool
android_in_use(void)
{
LOG_REGISTER_CONTEXT;
if( android_probed < 0 )
log_debug("android_in_use() called before android_probe()");
......@@ -95,6 +99,8 @@ android_in_use(void)
static bool
android_probe(void)
{
LOG_REGISTER_CONTEXT;
if( android_probed <= 0 ) {
android_probed = access(ANDROID0_ENABLE, F_OK) == 0;
log_warning("ANDROID0 %sdetected", android_probed ? "" : "not ");
......@@ -108,6 +114,8 @@ android_probe(void)
gchar *
android_get_serial(void)
{
LOG_REGISTER_CONTEXT;
static const char path[] = "/proc/cmdline";
static const char find[] = "androidboot.serialno=";
static const char pbrk[] = " \t\r\n,";
......@@ -157,6 +165,8 @@ EXIT:
bool
android_init_values(void)
{
LOG_REGISTER_CONTEXT;
gchar *text;
if( !android_probe() )
......@@ -217,6 +227,8 @@ EXIT:
bool
android_set_enabled(bool enable)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( android_in_use() ) {
const char *val = enable ? "1" : "0";
......@@ -233,6 +245,8 @@ android_set_enabled(bool enable)
bool
android_set_charging_mode(void)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( !android_in_use() )
......@@ -262,6 +276,8 @@ EXIT:
bool
android_set_function(const char *function)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( !function )
......@@ -293,6 +309,8 @@ EXIT:
bool
android_set_productid(const char *id)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( id && android_in_use() ) {
......@@ -316,6 +334,8 @@ android_set_productid(const char *id)
bool
android_set_vendorid(const char *id)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( id && android_in_use() ) {
char str[16];
......@@ -338,6 +358,8 @@ android_set_vendorid(const char *id)
bool
android_set_attr(const char *function, const char *attr, const char *value)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( function && attr && value && android_in_use() ) {
......
......@@ -64,6 +64,8 @@ static gboolean dbus_connection_disc = FALSE; // got disconnected
static void dbusappsync_release_name(void)
{
LOG_REGISTER_CONTEXT;
/* Drop the service name - if we have it */
if( dbus_connection_ses && dbus_connection_name )
{
......@@ -96,6 +98,8 @@ static void dbusappsync_release_name(void)
static gboolean dbusappsync_obtain_name(void)
{
LOG_REGISTER_CONTEXT;
DBusError error = DBUS_ERROR_INIT;
int ret;
......@@ -150,6 +154,8 @@ EXIT:
static DBusHandlerResult dbusappsync_msg_handler(DBusConnection *const connection, DBusMessage *const msg, gpointer const user_data)
{
LOG_REGISTER_CONTEXT;
DBusHandlerResult status = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
int type = dbus_message_get_type(msg);
const char *interface = dbus_message_get_interface(msg);
......@@ -221,6 +227,8 @@ IGNORE:
*/
static DBusHandlerResult dbusappsync_handle_disconnect(DBusConnection *conn, DBusMessage *msg, void *user_data)
{
LOG_REGISTER_CONTEXT;
if( dbus_message_is_signal(msg, DBUS_INTERFACE_LOCAL, "Disconnected") )
{
log_warning("disconnected from session bus - expecting restart/stop soon\n");
......@@ -235,6 +243,8 @@ static DBusHandlerResult dbusappsync_handle_disconnect(DBusConnection *conn, DBu
*/
static void dbusappsync_cleanup_connection(void)
{
LOG_REGISTER_CONTEXT;
if( dbus_connection_ses != 0 )
{
/* Remove message filters */
......@@ -259,6 +269,8 @@ static void dbusappsync_cleanup_connection(void)
*/
gboolean dbusappsync_init_connection(void)
{
LOG_REGISTER_CONTEXT;
gboolean result = FALSE;
DBusError error = DBUS_ERROR_INIT;
......@@ -316,6 +328,8 @@ EXIT:
*/
gboolean dbusappsync_init(void)
{
LOG_REGISTER_CONTEXT;
gboolean status = FALSE;
if( !dbusappsync_init_connection() )
......@@ -336,6 +350,8 @@ EXIT:
*/
void dbusappsync_cleanup(void)
{
LOG_REGISTER_CONTEXT;
dbusappsync_cleanup_connection();
// NOP
}
......@@ -345,6 +361,8 @@ void dbusappsync_cleanup(void)
*/
int dbusappsync_launch_app(char *launch)
{
LOG_REGISTER_CONTEXT;
int ret = -1; // assume failure
if( dbus_connection_ses == 0 )
......
......@@ -82,6 +82,8 @@ static int appsync_no_dbus = 1; // always disabled
static void appsync_free_elem(list_elem_t *elem)
{
LOG_REGISTER_CONTEXT;
g_free(elem->name);
g_free(elem->launch);
g_free(elem->mode);
......@@ -90,12 +92,16 @@ static void appsync_free_elem(list_elem_t *elem)
static void appsync_free_elem_cb(gpointer elem, gpointer user_data)
{
LOG_REGISTER_CONTEXT;
(void)user_data;
appsync_free_elem(elem);
}
void appsync_free_appsync_list(void)
{
LOG_REGISTER_CONTEXT;
if( appsync_sync_list != 0 )
{
/*g_list_free_full(appsync_sync_list, appsync_free_elem); */
......@@ -108,11 +114,15 @@ void appsync_free_appsync_list(void)
static gint appsync_list_sort_func(gconstpointer a, gconstpointer b)
{
LOG_REGISTER_CONTEXT;
return strcasecmp( (char*)a, (char*)b );
}
void appsync_read_list(int diag)
{
LOG_REGISTER_CONTEXT;
GDir *confdir = 0;
const gchar *dirname;
......@@ -160,6 +170,8 @@ cleanup:
static list_elem_t *appsync_read_file(const gchar *filename, int diag)
{
LOG_REGISTER_CONTEXT;
gchar *full_filename = NULL;
GKeyFile *settingsfile = NULL;
list_elem_t *list_item = NULL;
......@@ -215,6 +227,8 @@ cleanup:
/* @return 0 on succes, 1 if there is a failure */
int appsync_activate_sync(const char *mode)
{
LOG_REGISTER_CONTEXT;
GList *iter;
int count = 0;
......@@ -316,6 +330,8 @@ error:
int appsync_activate_sync_post(const char *mode)
{
LOG_REGISTER_CONTEXT;
GList *iter;
log_debug("activate post sync");
......@@ -374,6 +390,8 @@ error:
int appsync_mark_active(const gchar *name, int post)
{
LOG_REGISTER_CONTEXT;
int ret = -1; // assume name not found
int missing = 0;
......@@ -417,6 +435,8 @@ int appsync_mark_active(const gchar *name, int post)
#ifdef APP_SYNC_DBUS
static gboolean appsync_enumerate_usb_cb(gpointer data)
{
LOG_REGISTER_CONTEXT;
(void)data;
appsync_enumerate_usb_id = 0;
log_debug("handling enumeration timeout");
......@@ -427,6 +447,8 @@ static gboolean appsync_enumerate_usb_cb(gpointer data)
static void appsync_start_enumerate_usb_timer(void)
{
LOG_REGISTER_CONTEXT;
log_debug("scheduling enumeration timeout");
if( appsync_enumerate_usb_id )
g_source_remove(appsync_enumerate_usb_id), appsync_enumerate_usb_id = 0;
......@@ -441,6 +463,8 @@ static void appsync_start_enumerate_usb_timer(void)
static void appsync_cancel_enumerate_usb_timer(void)
{
LOG_REGISTER_CONTEXT;
if( appsync_enumerate_usb_id )
{
log_debug("canceling enumeration timeout");
......@@ -450,6 +474,8 @@ static void appsync_cancel_enumerate_usb_timer(void)
static void appsync_enumerate_usb(void)
{
LOG_REGISTER_CONTEXT;
struct timeval tv;
log_debug("Enumerating");
......@@ -469,6 +495,8 @@ static void appsync_enumerate_usb(void)
void appsync_stop_apps(int post)
{
LOG_REGISTER_CONTEXT;
GList *iter = 0;
for( iter = appsync_sync_list; iter; iter = g_list_next(iter) )
......@@ -487,6 +515,8 @@ void appsync_stop_apps(int post)
int appsync_stop(gboolean force)
{
LOG_REGISTER_CONTEXT;
/* If force arg is used, stop all applications that
* could have been started by usb-moded */
if(force)
......
......@@ -68,6 +68,8 @@ gchar *common_get_mode_list (mode_list_type_t type);
const char *cable_state_repr(cable_state_t state)
{
LOG_REGISTER_CONTEXT;
static const char * const lut[CABLE_STATE_NUMOF] = {
[CABLE_STATE_UNKNOWN] = "unknown",
[CABLE_STATE_DISCONNECTED] = "disconnected",
......@@ -159,6 +161,8 @@ static const modemapping_t common_modemapping[] =
const char *
common_map_mode_to_hardware(const char *internal_mode)
{
LOG_REGISTER_CONTEXT;
const char *hardware_mode = 0;
for( size_t i = 0; common_modemapping[i].internal_mode; ++i ) {
......@@ -173,6 +177,8 @@ common_map_mode_to_hardware(const char *internal_mode)
const char *
common_map_mode_to_external(const char *internal_mode)
{
LOG_REGISTER_CONTEXT;
const char *external_mode = 0;
for( size_t i = 0; common_modemapping[i].internal_mode; ++i ) {
......@@ -192,6 +198,8 @@ common_map_mode_to_external(const char *internal_mode)
*/
void common_send_supported_modes_signal(void)
{
LOG_REGISTER_CONTEXT;
gchar *mode_list = common_get_mode_list(SUPPORTED_MODES_LIST);
umdbus_send_supported_modes_signal(mode_list);
g_free(mode_list);
......@@ -201,6 +209,8 @@ void common_send_supported_modes_signal(void)
*/
void common_send_available_modes_signal(void)
{
LOG_REGISTER_CONTEXT;
gchar *mode_list = common_get_mode_list(AVAILABLE_MODES_LIST);
umdbus_send_available_modes_signal(mode_list);
g_free(mode_list);
......@@ -210,6 +220,8 @@ void common_send_available_modes_signal(void)
*/
void common_send_hidden_modes_signal(void)
{
LOG_REGISTER_CONTEXT;
gchar *mode_list = config_get_hidden_modes();
umdbus_send_hidden_modes_signal(mode_list);
g_free(mode_list);
......@@ -219,6 +231,8 @@ void common_send_hidden_modes_signal(void)
*/
void common_send_whitelisted_modes_signal(void)
{
LOG_REGISTER_CONTEXT;
gchar *mode_list = config_get_mode_whitelist();
umdbus_send_whitelisted_modes_signal(mode_list);
g_free(mode_list);
......@@ -237,6 +251,8 @@ void common_send_whitelisted_modes_signal(void)
*/
static void common_write_to_sysfs_file(const char *path, const char *text)
{
LOG_REGISTER_CONTEXT;
int fd = -1;
if (!path || !text)
......@@ -276,6 +292,8 @@ EXIT:
*/
void common_acquire_wakelock(const char *wakelock_name)
{
LOG_REGISTER_CONTEXT;
char buff[256];
snprintf(buff, sizeof buff, "%s %lld",
wakelock_name,
......@@ -293,6 +311,8 @@ void common_acquire_wakelock(const char *wakelock_name)
*/
void common_release_wakelock(const char *wakelock_name)
{
LOG_REGISTER_CONTEXT;
#if VERBOSE_WAKELOCKING
log_debug("common_release_wakelock %s", wakelock_name);
#endif
......@@ -310,6 +330,8 @@ int
common_system_(const char *file, int line, const char *func,
const char *command)
{
LOG_REGISTER_CONTEXT;
log_debug("EXEC %s; from %s:%d: %s()",
command, file, line, func);
......@@ -327,6 +349,8 @@ FILE *
common_popen_(const char *file, int line, const char *func,
const char *command, const char *type)
{
LOG_REGISTER_CONTEXT;
log_debug("EXEC %s; from %s:%d: %s()",
command, file, line, func);
......@@ -336,6 +360,8 @@ common_popen_(const char *file, int line, const char *func,
waitres_t
common_wait(unsigned tot_ms, bool (*ready_cb)(void *aptr), void *aptr)
{
LOG_REGISTER_CONTEXT;
struct timespec ts;
waitres_t res = WAIT_FAILED;
......@@ -384,6 +410,8 @@ EXIT:
bool
common_msleep_(const char *file, int line, const char *func, unsigned msec)
{
LOG_REGISTER_CONTEXT;
log_debug("SLEEP %u.%03u seconds; from %s:%d: %s()",
msec / 1000u, msec % 1000u,file, line, func);
return common_wait(msec, 0, 0) == WAIT_TIMEOUT;
......@@ -396,6 +424,8 @@ common_msleep_(const char *file, int line, const char *func, unsigned msec)
/* check if a mode is in a list */
static bool common_mode_in_list(const char *mode, char * const *modes)
{
LOG_REGISTER_CONTEXT;
int i;
if (!modes)
......@@ -417,6 +447,8 @@ static bool common_mode_in_list(const char *mode, char * const *modes)
*/
int common_valid_mode(const char *mode)
{
LOG_REGISTER_CONTEXT;
int valid = 1;
/* MODE_ASK, MODE_CHARGER and MODE_CHARGING_FALLBACK are not modes that are settable seen their special 'internal' status
* so we only check the modes that are announed outside. Only exception is the built in MODE_CHARGING */
......@@ -455,6 +487,8 @@ int common_valid_mode(const char *mode)
*/
gchar *common_get_mode_list(mode_list_type_t type)
{
LOG_REGISTER_CONTEXT;
GString *mode_list_str = g_string_new(NULL);
gchar *hidden_modes_value = 0;
......
This diff is collapsed.
......@@ -112,6 +112,8 @@ static int configfs_probed = -1;
static int configfs_file_type(const char *path)
{
LOG_REGISTER_CONTEXT;
int type = -1;
if( !path )
......@@ -130,6 +132,8 @@ EXIT:
static const char *
configfs_function_path(char *buff, size_t size, const char *func, ...)
{
LOG_REGISTER_CONTEXT;
char *pos = buff;
char *end = buff + size;
......@@ -150,12 +154,16 @@ configfs_function_path(char *buff, size_t size, const char *func, ...)
static const char *
configfs_unit_path(char *buff, size_t size, const char *func, const char *unit)
{
LOG_REGISTER_CONTEXT;
return configfs_function_path(buff, size, func, unit, NULL);
}
static const char *
configfs_config_path(char *buff, size_t size, const char *func)
{
LOG_REGISTER_CONTEXT;
snprintf(buff, size, "%s/%s", CONFIGFS_CONFIG, func);
return buff;
}
......@@ -163,6 +171,8 @@ configfs_config_path(char *buff, size_t size, const char *func)
static bool
configfs_mkdir(const char *path)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( mkdir(path, 0775) == -1 && errno != EEXIST ) {
......@@ -184,6 +194,8 @@ EXIT:
static bool
configfs_rmdir(const char *path)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( rmdir(path) == -1 && errno != ENOENT ) {
......@@ -200,6 +212,8 @@ EXIT:
static const char *
configfs_register_function(const char *function)
{
LOG_REGISTER_CONTEXT;
const char *res = 0;
static char fpath[256];
......@@ -220,6 +234,8 @@ EXIT:
static bool
configfs_unregister_function(const char *function)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
char fpath[256];
......@@ -239,6 +255,8 @@ EXIT:
static const char *
configfs_add_unit(const char *function, const char *unit)
{
LOG_REGISTER_CONTEXT;
const char *res = 0;
static char upath[256];
......@@ -258,6 +276,8 @@ EXIT:
static bool
configfs_remove_unit(const char *function, const char *unit)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
static char upath[256];
......@@ -277,6 +297,8 @@ EXIT:
static bool
configfs_enable_function(const char *function)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
const char *fpath = configfs_register_function(function);
......@@ -316,6 +338,8 @@ EXIT:
static bool
configfs_disable_function(const char *function)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
char cpath[256];
......@@ -341,6 +365,8 @@ EXIT:
static bool
configfs_disable_all_functions(void)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
DIR *dir = 0;
......@@ -372,6 +398,8 @@ EXIT:
static char *configfs_strip(char *str)
{
LOG_REGISTER_CONTEXT;
unsigned char *src = (unsigned char *)str;
unsigned char *dst = (unsigned char *)str;
......@@ -391,6 +419,8 @@ static char *configfs_strip(char *str)
bool
configfs_in_use(void)
{
LOG_REGISTER_CONTEXT;
if( configfs_probed < 0 )
log_debug("configfs_in_use() called before configfs_probe()");
return configfs_probed > 0;
......@@ -399,6 +429,8 @@ configfs_in_use(void)
static bool
configfs_probe(void)
{
LOG_REGISTER_CONTEXT;
if( configfs_probed <= 0 ) {
configfs_probed = access(CONFIGFS_GADGET, F_OK) == 0;
log_warning("CONFIGFS %sdetected", configfs_probed ? "" : "not ");
......@@ -409,6 +441,8 @@ configfs_probe(void)
static const char *
configfs_udc_enable_value(void)
{
LOG_REGISTER_CONTEXT;
static bool probed = false;
static char *value = 0;
......@@ -437,6 +471,8 @@ configfs_udc_enable_value(void)
static bool
configfs_write_file(const char *path, const char *text)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
int fd = -1;
......@@ -477,6 +513,8 @@ EXIT:
static bool
configfs_read_file(const char *path, char *buff, size_t size)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
int fd = -1;
......@@ -515,6 +553,8 @@ EXIT:
static bool
configfs_read_udc(char *buff, size_t size)
{
LOG_REGISTER_CONTEXT;
return configfs_read_file(CONFIGFS_UDC, buff, size);
}
#endif
......@@ -522,6 +562,8 @@ configfs_read_udc(char *buff, size_t size)
static bool
configfs_write_udc(const char *text)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
char prev[64];
......@@ -544,6 +586,8 @@ EXIT:
bool
configfs_set_udc(bool enable)
{
LOG_REGISTER_CONTEXT;
log_debug("UDC - %s", enable ? "ENABLE" : "DISABLE");
const char *value = "";
......@@ -559,6 +603,8 @@ configfs_set_udc(bool enable)
bool
configfs_init_values(void)
{
LOG_REGISTER_CONTEXT;
if( !configfs_probe() )
goto EXIT;
......@@ -622,6 +668,8 @@ EXIT:
bool
configfs_set_charging_mode(void)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( !configfs_set_function("mass_storage") )
......@@ -647,6 +695,8 @@ EXIT:
bool
configfs_set_productid(const char *id)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( id && configfs_in_use() ) {
......@@ -673,6 +723,8 @@ configfs_set_productid(const char *id)
bool
configfs_set_vendorid(const char *id)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( id && configfs_in_use() ) {
......@@ -699,6 +751,8 @@ configfs_set_vendorid(const char *id)
static const char *
configfs_map_function(const char *func)
{
LOG_REGISTER_CONTEXT;
if( func == 0 )
;
else if( !strcmp(func, "mass_storage") )
......@@ -721,6 +775,8 @@ configfs_map_function(const char *func)
bool
configfs_set_function(const char *func)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( !configfs_in_use() )
......@@ -753,6 +809,8 @@ EXIT:
bool
configfs_add_mass_storage_lun(int lun)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( !configfs_in_use() )
......@@ -769,6 +827,8 @@ EXIT:
bool
configfs_remove_mass_storage_lun(int lun)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( !configfs_in_use() )
......@@ -785,6 +845,8 @@ EXIT:
bool
configfs_set_mass_storage_attr(int lun, const char *attr, const char *value)
{
LOG_REGISTER_CONTEXT;
bool ack = false;
if( !configfs_in_use() )
......
......@@ -99,6 +99,8 @@ static cable_state_t control_cable_state = CABLE_STATE_UNKNOWN;
void
control_rethink_usb_charging_fallback(void)
{
LOG_REGISTER_CONTEXT;
/* Cable must be connected to a pc */
if( control_get_cable_state() != CABLE_STATE_PC_CONNECTED )
goto EXIT;
......@@ -125,11 +127,15 @@ EXIT:
const char *control_get_external_mode(void)
{
LOG_REGISTER_CONTEXT;
return control_external_mode ?: MODE_UNDEFINED;
}
static void control_set_external_mode(const char *mode)
{
LOG_REGISTER_CONTEXT;
gchar *previous = control_external_mode;
if( !g_strcmp0(previous, mode) )
goto EXIT;
......@@ -167,12 +173,16 @@ EXIT:
void control_clear_external_mode(void)
{
LOG_REGISTER_CONTEXT;
g_free(control_external_mode),
control_external_mode = 0;
}
static void control_update_external_mode(void)
{
LOG_REGISTER_CONTEXT;
const char *internal_mode = control_get_usb_mode();
const char *external_mode = common_map_mode_to_external(internal_mode);
......@@ -181,11 +191,15 @@ static void control_update_external_mode(void)
const char *control_get_target_mode(void)
{
LOG_REGISTER_CONTEXT;
return control_target_mode ?: MODE_UNDEFINED;
}
static void control_set_target_mode(const char *mode)
{
LOG_REGISTER_CONTEXT;
gchar *previous = control_target_mode;
if( !g_strcmp0(previous, mode) )
goto EXIT;
......@@ -204,6 +218,8 @@ EXIT:
void control_clear_target_mode(void)