registrybackend: more cleanups

This commit is contained in:
Ignacio Casal Quinteiro 2016-01-26 09:00:35 +01:00
parent 7256f2289a
commit a159bc939d

View File

@ -192,7 +192,8 @@ trace (const char *format,
{ {
#ifdef TRACE #ifdef TRACE
va_list va; va_start (va, format); va_list va; va_start (va, format);
vprintf (format, va); fflush (stdout); vprintf (format, va);
fflush (stdout);
va_end (va); va_end (va);
#endif #endif
} }
@ -216,9 +217,11 @@ g_message_win32_error (DWORD result_code,
va_start (va, format); va_start (va, format);
pos = g_vsnprintf (win32_message, 512, format, va); pos = g_vsnprintf (win32_message, 512, format, va);
win32_message[pos++] = ':'; win32_message[pos++] = ' '; win32_message[pos++] = ':';
win32_message[pos++] = ' ';
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, result_code, 0, (LPTSTR)(win32_message+pos), FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL,
result_code, 0, (LPTSTR)(win32_message + pos),
1023 - pos, NULL); 1023 - pos, NULL);
if (result_code == ERROR_KEY_DELETED) if (result_code == ERROR_KEY_DELETED)
@ -256,7 +259,7 @@ parse_key (const gchar *key_name,
if (*c == '/') if (*c == '/')
{ {
*c = '\\'; *c = '\\';
(*value_name) = c; *value_name = c;
} }
} }
@ -404,7 +407,9 @@ registry_cache_add_item (GNode *parent,
item->subscription_count = 0; item->subscription_count = 0;
item->block_count = 0; item->block_count = 0;
item->touched = FALSE; item->touched = FALSE;
trace ("\treg cache: adding %s to %s\n", name, ((RegistryCacheItem *)parent->data)->name);
trace ("\treg cache: adding %s to %s\n",
name, ((RegistryCacheItem *)parent->data)->name);
cache_node = g_node_new (item); cache_node = g_node_new (item);
g_node_append (parent, cache_node); g_node_append (parent, cache_node);
@ -451,6 +456,7 @@ static void
_free_cache_item (RegistryCacheItem *item) _free_cache_item (RegistryCacheItem *item)
{ {
trace ("\t -- Free node %s\n", item->name); trace ("\t -- Free node %s\n", item->name);
g_free (item->name); g_free (item->name);
registry_value_free (item->value); registry_value_free (item->value);
g_slice_free (RegistryCacheItem, item); g_slice_free (RegistryCacheItem, item);
@ -557,6 +563,7 @@ registry_cache_find_immediate_child (GNode *node,
search.result = NULL; search.result = NULL;
search.name = name; search.name = name;
g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, 2, g_node_traverse (node, G_POST_ORDER, G_TRAVERSE_ALL, 2,
registry_cache_find_compare, &search); registry_cache_find_compare, &search);
@ -570,8 +577,8 @@ registry_cache_get_node_for_key_recursive (GNode *node,
gint n_parent_watches) gint n_parent_watches)
{ {
RegistryCacheItem *item; RegistryCacheItem *item;
gchar *component = key_name, gchar *component = key_name;
*c = strchr (component, '/'); gchar *c = strchr (component, '/');
GNode *child; GNode *child;
if (c != NULL) if (c != NULL)
@ -614,8 +621,8 @@ registry_cache_get_node_for_key (GNode *root,
const gchar *key_name, const gchar *key_name,
gboolean create_if_not_found) gboolean create_if_not_found)
{ {
GNode *child = NULL, GNode *child = NULL;
*result = NULL; GNode *result = NULL;
gchar *component, *c; gchar *component, *c;
g_return_val_if_fail (key_name != NULL, NULL); g_return_val_if_fail (key_name != NULL, NULL);
@ -1165,13 +1172,17 @@ registry_cache_destroy_tree (GNode *node,
if (item->subscription_count > 0) if (item->subscription_count > 0)
{ {
gint i; gint i;
/* There must be some watches active if this node is a watch point */ /* There must be some watches active if this node is a watch point */
g_warn_if_fail (self->cache_nodes->len > 1); g_warn_if_fail (self->cache_nodes->len > 1);
/* This is a watch point that has been deleted. Let's free the watch! */ /* This is a watch point that has been deleted. Let's free the watch! */
for (i = 1; i < self->cache_nodes->len; i++) for (i = 1; i < self->cache_nodes->len; i++)
{
if (g_ptr_array_index (self->cache_nodes, i) == node) if (g_ptr_array_index (self->cache_nodes, i) == node)
break; break;
}
if (i >= self->cache_nodes->len) if (i >= self->cache_nodes->len)
g_warning ("watch thread: a watch point was deleted, but unable to " g_warning ("watch thread: a watch point was deleted, but unable to "
"find '%s' in the list of %i watch nodes\n", item->name, "find '%s' in the list of %i watch nodes\n", item->name,
@ -1373,6 +1384,7 @@ static gboolean
watch_handler (RegistryEvent *event) watch_handler (RegistryEvent *event)
{ {
gint i; gint i;
trace ("Watch handler: got event in %s, items %i.\n", event->prefix, event->items->len); trace ("Watch handler: got event in %s, items %i.\n", event->prefix, event->items->len);
/* GSettings requires us to NULL-terminate the array. */ /* GSettings requires us to NULL-terminate the array. */
@ -1477,9 +1489,11 @@ watch_thread_handle_message (WatchThreadState *self)
gint i; gint i;
for (i = 1; i < self->prefixes->len; i++) for (i = 1; i < self->prefixes->len; i++)
{
if (strcmp (g_ptr_array_index (self->prefixes, i), if (strcmp (g_ptr_array_index (self->prefixes, i),
self->message.watch.prefix) == 0) self->message.watch.prefix) == 0)
break; break;
}
if (i >= self->prefixes->len) if (i >= self->prefixes->len)
{ {
@ -1714,6 +1728,7 @@ watch_stop_unlocked (GRegistryBackend *self)
{ {
WatchThreadState *watch = self->watch; WatchThreadState *watch = self->watch;
DWORD result; DWORD result;
g_return_if_fail (watch != NULL); g_return_if_fail (watch != NULL);
watch->message.type = WATCH_THREAD_STOP; watch->message.type = WATCH_THREAD_STOP;