PoorMan debug utils

This commit is contained in:
Davide Andreoli 2021-04-24 08:39:18 +02:00
parent c45452ccaf
commit 9d06c71425
3 changed files with 47 additions and 30 deletions

View File

@ -7,6 +7,10 @@
#include "e_mod_places.h"
/* Enable/Disable debug messages */
// #define PDBG(...) do {} while (0)
#define PDBG(...) printf("PLACES(mnt): "__VA_ARGS__)
#define FSTAB_FILE "/etc/fstab"
#define MTAB_FILE "/proc/mounts"
@ -236,12 +240,12 @@ _places_mount_mtab_timer_cb(void *data)
Eina_Bool
places_mount_init(void)
{
printf("PLACES: mount: init()\n");
PDBG("init()\n");
if (!ecore_file_exists(FSTAB_FILE) ||
!ecore_file_exists(MTAB_FILE))
{
printf("PLACES: mount: Cannot find required files\n");
printf("PLACES(mnt): Cannot find required files\n");
return EINA_FALSE;
}
@ -260,12 +264,12 @@ places_mount_init(void)
void
places_mount_shutdown(void)
{
printf("PLACES: mtab: shutdown()\n");
PDBG("shutdown()\n");
E_FREE_FUNC(mtab_timer, ecore_timer_del);
E_FREE_FUNC(know_mounts, eina_list_free);
E_FREE_FUNC(eeh1, ecore_event_handler_del);
E_FREE_FUNC(eeh2, ecore_event_handler_del);
}
#undef PDBG
#endif

View File

@ -10,6 +10,11 @@
#include "e_mod_places.h"
/* Enable/Disable debug messages */
// #define PDBG(...) do {} while (0)
#define PDBG(...) printf("PLACES(ud2): "__VA_ARGS__)
/* UDisks2 defines */
#define UDISKS2_BUS "org.freedesktop.UDisks2"
#define UDISKS2_PATH "/org/freedesktop/UDisks2"
@ -66,14 +71,14 @@ static Eldbus_Object *_places_ud2_object_manager = NULL;
Eina_Bool
places_udisks2_init(void)
{
printf("PLACES: udisks2: init()\n");
PDBG("init()\n");
EINA_SAFETY_ON_FALSE_RETURN_VAL(eldbus_init(), EINA_FALSE);
_places_ud2_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
if (!_places_ud2_conn)
{
printf("PLACES: udisks2: Error connecting to system bus.\n");
printf("udisks2: Error connecting to system bus.\n");
return EINA_FALSE;
}
@ -86,7 +91,7 @@ places_udisks2_init(void)
void
places_udisks2_shutdown(void)
{
printf("PLACES: udisks2: shutdown()\n");
PDBG("shutdown()\n");
E_FREE_FUNC(_places_ud2_object_manager, eldbus_object_unref);
E_FREE_FUNC(_places_ud2_conn, eldbus_connection_unref);
eldbus_shutdown();
@ -168,7 +173,6 @@ _places_udisks2_string_convert(Eldbus_Message_Iter *ay)
if (!p) break;
p++;
}
// printf("PLACES: stupid string %s\n", str);
return strdup(buf);
}
@ -212,7 +216,7 @@ _places_ud2_get_managed_objects_cb(void *data, const Eldbus_Message *msg, Eldbus
PLACES_ON_MSG_ERROR_RETURN(msg);
printf("PLACES: GetManagedObjects\n");
PDBG("GetManagedObjects\n");
if (!eldbus_message_arguments_get(msg, "a{oa{sa{sv}}}", &objs_array))
return;
@ -240,7 +244,7 @@ _places_ud2_interfaces_added_cb(void *data, const Eldbus_Message *msg)
if (eldbus_message_arguments_get(msg, "oa{sa{sv}}", &obj_path, &ifaces_array))
{
printf("PLACES: InterfacesAdded on obj: %s\n", obj_path);
PDBG("InterfacesAdded on obj: %s\n", obj_path);
// we are only interested at block_device objects
if (eina_str_has_prefix(obj_path, UDISKS2_BLOCK_PREFIX))
_places_ud2_read_block_ifaces(obj_path, ifaces_array, EINA_FALSE);
@ -263,7 +267,7 @@ _places_ud2_interfaces_removed_cb(void *data, const Eldbus_Message *msg)
while (eldbus_message_iter_get_and_next(array_ifaces, 's', &iface_name))
{
printf("PLACES: InterfaceRemoved obj:%s - iface:%s\n", obj_path, iface_name);
PDBG("InterfaceRemoved obj:%s - iface:%s\n", obj_path, iface_name);
if (eina_streq(iface_name, UDISKS2_FILESYSTEM_IFACE) ||
eina_streq(iface_name, UDISKS2_BLOCK_IFACE))
if ((vol = places_volume_by_id_get(obj_path)))
@ -288,7 +292,7 @@ _places_ud2_block_props_changed_cb(void *data, const Eldbus_Message *msg)
&changed_props, &invalidated_props))
return;
printf("PLACES: PropertiesChanged obj:%s - iface:%s\n", vol->id, iface_name);
PDBG("PropertiesChanged obj:%s - iface:%s\n", vol->id, iface_name);
// atm we are only intrested in the mounted state (on the FS iface)
if (!eina_streq(iface_name, UDISKS2_FILESYSTEM_IFACE))
@ -299,7 +303,7 @@ _places_ud2_block_props_changed_cb(void *data, const Eldbus_Message *msg)
if (!eldbus_message_iter_arguments_get(props_entry, "sv", &prop_name, &var))
continue;
printf("PLACES: Changed prop: %s\n", prop_name);
PDBG(" Changed prop: %s\n", prop_name);
if (eina_streq(prop_name, "MountPoints"))
{
Eldbus_Message_Iter *mounts_array, *ay;
@ -329,7 +333,7 @@ _places_ud2_drive_props_changed_cb(void *data, const Eldbus_Message *msg)
&changed_props, &invalidated_props))
return;
printf("PLACES: PropertiesChanged obj:%s - iface:%s\n", vol->id, iface_name);
PDBG("PropertiesChanged obj:%s - iface:%s\n", vol->id, iface_name);
if (eina_streq(iface_name, UDISKS2_DRIVE_IFACE))
_places_ud2_read_drive_properies(vol, changed_props);
}
@ -352,19 +356,19 @@ _places_ud2_read_block_ifaces(const char *block_obj_path, Eldbus_Message_Iter *i
unsigned long long blockdevice_size = 0;
unsigned long long filesystem_size = 0;
printf("PLACES: Parsing block_device: %s\n", block_obj_path);
PDBG("Parsing block_device: %s\n", block_obj_path);
while (eldbus_message_iter_get_and_next(ifaces_array, 'e', &iface_entry))
{
if (!eldbus_message_iter_arguments_get(iface_entry, "sa{sv}", &iface_name, &props_array))
continue;
// printf("PLACES: Iface: %s\n", iface_name);
// PDBG("PLACES: Iface: %s\n", iface_name);
while (eldbus_message_iter_get_and_next(props_array, 'e', &props_entry))
{
if (!eldbus_message_iter_arguments_get(props_entry, "sv", &key, &var))
continue;
// printf("PLACES: Prop: %s\n", key);
// PDBG("PLACES: Prop: %s\n", key);
/* block device with the following ifaces must be ignored */
if(eina_streq(iface_name, UDISKS2_PARTITIONTABLE_IFACE) ||
@ -418,11 +422,11 @@ _places_ud2_read_block_ifaces(const char *block_obj_path, Eldbus_Message_Iter *i
mount_point = _places_udisks2_string_convert(chrarray);
}
}
// else printf("PLACES: WARNING - Unknown iface: %s\n", iface_name);
// else PDBG("PLACES: WARNING - Unknown iface: %s\n", iface_name);
}
}
printf("PLACES: Found device: %s\n", block_obj_path);
PDBG("Found device: %s\n", block_obj_path);
// create (or get an already created) places Volume
Volume *vol = _places_ud2_volume_add(block_obj_path, drive_obj_path, first_time);
@ -451,7 +455,7 @@ _places_ud2_read_block_ifaces(const char *block_obj_path, Eldbus_Message_Iter *i
eldbus_proxy_property_get_all(proxy, _places_ud2_drive_props_cb, vol);
eldbus_proxy_unref(proxy);
}
else printf("PLACES: WARNING - NO DRIVE FOR OBJECT %s\n", block_obj_path);
else PDBG("WARNING - NO DRIVE FOR OBJECT %s\n", block_obj_path);
skip:
if (device) free(device);
@ -469,7 +473,7 @@ _places_ud2_drive_props_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending
EINA_SAFETY_ON_NULL_RETURN(vol);
PLACES_ON_MSG_ERROR_RETURN(msg);
EINA_SAFETY_ON_FALSE_RETURN(eldbus_message_arguments_get(msg, "a{sv}", &props_array));
printf("PLACES: Drive properties for: %s\n", vol->id);
PDBG("Drive properties for: %s\n", vol->id);
_places_ud2_read_drive_properies(vol, props_array);
}
@ -531,7 +535,7 @@ static void
_places_ud2_volume_finalize(Volume *vol)
{
Eina_Bool is_valid = EINA_TRUE;
printf("PLACES: Validating %s\n", vol->id);
PDBG("Validating %s\n", vol->id);
// set mounted state
if (vol->mount_point && vol->mount_point[0])
@ -597,7 +601,7 @@ _places_ud2_mount_func(Volume *vol, Eina_List *opts)
// const char *opt_txt;
// EINA_LIST_FOREACH(opts, l, opt_txt)
// {
// // printf(" opt: '%s'\n", opt_txt);
// // PDBG(" opt: '%s'\n", opt_txt);
// eldbus_message_iter_basic_append(array, 's', opt_txt);
// }
// eldbus_message_iter_container_close(main_iter, array);
@ -641,5 +645,5 @@ _places_ud2_eject_func(Volume *vol, Eina_List *opts)
eldbus_object_send(bdata->drive_obj, msg, _places_udisks2_task_cb, vol, -1);
}
#undef PDBG
#endif

View File

@ -26,6 +26,12 @@
#endif
/* Enable/Disable debug messages */
// #define PDBG(...) do {} while (0)
#define PDBG(...) printf("PLACES: "__VA_ARGS__)
/* Local Typedefs */
typedef struct _FreespaceThreadData FreespaceThreadData;
struct _FreespaceThreadData
@ -68,7 +74,7 @@ places_init(void)
{
volumes = NULL;
printf("PLACES: Init\n");
PDBG("module init\n");
#ifdef PLACES_HAVE_SYSTEMD
places_systemd_init();
@ -480,7 +486,7 @@ places_fill_box(Evas_Object *main, Eina_Bool horiz)
edje_object_calc_force(main);
edje_object_size_min_restricted_calc(main, &min_w, &min_h, 99, 1);
// printf("PLACES: SIZE: %d %d\n", min_w, min_h);
// PDBG("SIZE: %d %d\n", min_w, min_h);
evas_object_size_hint_min_set(main, min_w, min_h);
}
@ -608,7 +614,7 @@ _places_freespace_thread_run(void *data, Ecore_Thread *thread)
FreespaceThreadData *td = NULL;
struct statvfs s;
// printf("PLACES: THIS RUN IN THREAD %p\n", thread);
// PDBG("THIS RUN IN THREAD %p\n", thread);
if (ecore_thread_check(thread) == EINA_TRUE) // thread cancelled
return;
@ -650,7 +656,7 @@ _places_freespace_thread_done(void *data, Ecore_Thread *thread)
E_FREE(td);
}
// printf("PLACES: THREAD DONE %p\n", thread);
// PDBG(" THREAD DONE %p\n", thread);
freespace_thread = NULL;
}
@ -675,10 +681,10 @@ _places_freespace_timer_cb(void *data EINA_UNUSED)
Eina_List *l, *tdl = NULL;
FreespaceThreadData *td = NULL;
// printf("PLACES: TIMER %.1f\n", ecore_time_get());
// PDBG("TIMER %.1f\n", ecore_time_get());
if (freespace_thread)
{
// printf("PLACES: *** SOMETHING WRONG *** thread:%p still running...\n", freespace_thread);
// PDBG("*** SOMETHING WRONG *** thread:%p still running...\n", freespace_thread);
return ECORE_CALLBACK_RENEW;
}
@ -1053,3 +1059,6 @@ places_augmentation(void *data, E_Menu *em)
e_menu_pre_activate_callback_set(m, places_generate_menu, NULL);
}
#undef PDBG