From 7e19d433643bd94cd485a1b6dbf7bf042adba48e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 28 Mar 2014 22:17:05 -0500 Subject: don't create menuitems for phantom users. --- src/service.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 68fbc50..a153306 100644 --- a/src/service.c +++ b/src/service.c @@ -576,12 +576,20 @@ create_switch_section (IndicatorSessionService * self, int profile) for (i=0; ilen; ++i) { const IndicatorSessionUser * u = g_ptr_array_index (users, i); + const char * label; GVariant * serialized_icon; if (profile == PROFILE_LOCKSCREEN && u->is_current_user) continue; - item = g_menu_item_new (get_user_label (u), NULL); + /* Sometimes we get a user without a username? bus hiccup. + I can't reproduce it, but let's not confuse users with + a meaningless menuitem. (see bug #1263228) */ + label = get_user_label (u); + if (!label || !*label) + continue; + + item = g_menu_item_new (label, NULL); g_menu_item_set_action_and_target (item, "indicator.switch-to-user", "s", u->user_name); g_menu_item_set_attribute (item, "x-canonical-type", "s", "indicator.user-menu-item"); -- cgit v1.2.3 From 8401862ae66ac619f517cd4bb37a07c6847f625c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 28 Mar 2014 22:21:35 -0500 Subject: silence compiler warning --- src/service.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index a153306..b3b0641 100644 --- a/src/service.c +++ b/src/service.c @@ -250,15 +250,15 @@ on_user_changed (IndicatorSessionUsers * backend_users G_GNUC_UNUSED, static void maybe_add_users (IndicatorSessionService * self) { - if (!show_user_list (self)) - return; - - GList * uids, * l; + if (show_user_list (self)) + { + GList * uids, * l; - uids = indicator_session_users_get_uids (self->priv->backend_users); - for (l=uids; l!=NULL; l=l->next) - add_user (self, GPOINTER_TO_UINT(l->data)); - g_list_free (uids); + uids = indicator_session_users_get_uids (self->priv->backend_users); + for (l=uids; l!=NULL; l=l->next) + add_user (self, GPOINTER_TO_UINT(l->data)); + g_list_free (uids); + } } -- cgit v1.2.3 From 8416dc9bee649ce728678e6cdadfd08a38aee548 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 2 Apr 2014 10:02:59 -0500 Subject: if we encounter a user for whom we can't find a name, report it to apport as a recoverable error. --- debian/control | 1 + src/service.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'src/service.c') diff --git a/debian/control b/debian/control index fb067cc..eb148bf 100644 --- a/debian/control +++ b/debian/control @@ -32,6 +32,7 @@ Recommends: indicator-applet (>= 0.2) | indicator-renderer, unity-control-center | gnome-control-center, unity-control-center-signon | gnome-control-center-signon Suggests: lightdm, + apport, zenity Description: indicator showing session management, status and user switching This indicator is designed to be placed on the right side of a panel and diff --git a/src/service.c b/src/service.c index b3b0641..7484134 100644 --- a/src/service.c +++ b/src/service.c @@ -21,6 +21,7 @@ #include #include "backend.h" +#include "recoverable-problem.h" #include "service.h" #define BUS_NAME "com.canonical.indicator.session" @@ -104,6 +105,7 @@ struct _IndicatorSessionServicePrivate GSimpleAction * user_switcher_action; GSimpleAction * guest_switcher_action; GHashTable * users; + GHashTable * reported_users; guint rebuild_id; int rebuild_flags; GDBusConnection * conn; @@ -488,6 +490,49 @@ serialize_icon_file (const gchar * filename) return serialized_icon; } +static void +report_unusable_user (IndicatorSessionService * self, const IndicatorSessionUser * u) +{ + const priv_t * const p = self->priv; + gpointer key; + + g_return_if_fail(u != NULL); + + key = GUINT_TO_POINTER(u->uid); + + if (!g_hash_table_contains (p->reported_users, key)) + { + gchar * uid_str; + GPtrArray * additional; + const gchar * const error_name = "indicator-session-unknown-user-error"; + + /* don't spam apport with duplicates */ + g_hash_table_add (p->reported_users, key); + + uid_str = g_strdup_printf("%u", u->uid); + + additional = g_ptr_array_new (); /* null-terminated key/value pair strs */ + g_ptr_array_add (additional, "uid"); + g_ptr_array_add (additional, uid_str); + g_ptr_array_add (additional, "icon_file"); + g_ptr_array_add (additional, u->icon_file ? u->icon_file : "(null)"); + g_ptr_array_add (additional, "is_current_user"); + g_ptr_array_add (additional, u->is_current_user ? "true" : "false"); + g_ptr_array_add (additional, "is_logged_in"); + g_ptr_array_add (additional, u->is_logged_in ? "true" : "false"); + g_ptr_array_add (additional, "real_name"); + g_ptr_array_add (additional, u->real_name ? u->real_name : "(null)"); + g_ptr_array_add (additional, "user_name"); + g_ptr_array_add (additional, u->user_name ? u->user_name : "(null)"); + g_ptr_array_add (additional, NULL); /* null termination */ + report_recoverable_problem(error_name, (GPid)0, FALSE, (gchar**)additional->pdata); + + /* cleanup */ + g_free (uid_str); + g_ptr_array_free (additional, TRUE); + } +} + static GMenuModel * create_switch_section (IndicatorSessionService * self, int profile) { @@ -587,7 +632,10 @@ create_switch_section (IndicatorSessionService * self, int profile) a meaningless menuitem. (see bug #1263228) */ label = get_user_label (u); if (!label || !*label) + { + report_unusable_user (self, u); continue; + } item = g_menu_item_new (label, NULL); g_menu_item_set_action_and_target (item, "indicator.switch-to-user", "s", u->user_name); @@ -1103,6 +1151,9 @@ indicator_session_service_init (IndicatorSessionService * self) g_direct_equal, NULL, (GDestroyNotify)indicator_session_user_free); + + p->reported_users = g_hash_table_new (g_direct_hash, g_direct_equal); + maybe_add_users (self); init_gactions (self); @@ -1243,6 +1294,7 @@ my_dispose (GObject * o) } g_clear_pointer (&p->users, g_hash_table_destroy); + g_clear_pointer (&p->reported_users, g_hash_table_destroy); g_clear_object (&p->backend_users); g_clear_object (&p->backend_guest); g_clear_object (&p->backend_actions); -- cgit v1.2.3