From e1a933792dbf2114d66a3132d2ce29107ed25130 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 31 Aug 2011 13:09:57 +0100 Subject: apt race condition handled --- src/apt-watcher.c | 85 ++++++++++++++++++++++++++++++++++++------------- src/indicator-session.c | 1 + src/session-dbus.xml | 2 +- 3 files changed, 64 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index a4298a8..e757896 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -27,6 +27,7 @@ static guint watcher_id; struct _AptWatcher { GObject parent_instance; + guint reboot_query; GCancellable * proxy_cancel; GDBusProxy * proxy; SessionDbus* session_dbus_interface; @@ -64,6 +65,7 @@ static void apt_watcher_signal_cb (GDBusProxy* proxy, gpointer user_data); static void apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id); +static gboolean apt_watcher_query_reboot_status (gpointer self); @@ -75,6 +77,7 @@ apt_watcher_init (AptWatcher *self) self->current_state = UP_TO_DATE; self->proxy_cancel = g_cancellable_new(); self->proxy = NULL; + self->reboot_query = 0; self->current_transaction = NULL; g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, @@ -141,7 +144,11 @@ fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_signal_connect (self->proxy, "g-signal", G_CALLBACK(apt_watcher_signal_cb), - self); + self); + + /*self->reboot_query = g_timeout_add_seconds (5, + apt_watcher_query_reboot_status, + self);*/ } @@ -245,7 +252,16 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, == SIMULATION){ g_object_unref (G_OBJECT(self->current_transaction)); self->current_transaction = NULL; - } + } + if (self->reboot_query != 0){ + g_source_remove (self->reboot_query); + self->reboot_query = 0; + } + // Wait a sec before querying for reboot status, + // race condition with Apt has been observed. + self->reboot_query = g_timeout_add_seconds (1, + apt_watcher_query_reboot_status, + self); } else if (state == UPDATES_AVAILABLE){ dbusmenu_menuitem_property_set (self->apt_item, @@ -266,27 +282,20 @@ apt_watcher_transaction_state_update_cb (AptTransaction* trans, _("Updates Installing…")); } else if (state == FINISHED){ - GVariant* reboot_result = g_dbus_proxy_get_cached_property (self->proxy, - "RebootRequired"); - gboolean reboot; - g_variant_get (reboot_result, "b", &reboot); - if (reboot == FALSE){ - dbusmenu_menuitem_property_set (self->apt_item, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Software Up to Date")); - } - else{ - dbusmenu_menuitem_property_set (self->apt_item, - DBUSMENU_MENUITEM_PROP_LABEL, - _("Reboot Required")); - dbusmenu_menuitem_property_set (self->apt_item, - DBUSMENU_MENUITEM_PROP_DISPOSITION, - DBUSMENU_MENUITEM_DISPOSITION_ALERT); - session_dbus_restart_required (self->session_dbus_interface); - } - g_debug ("Finished with a reboot value of %i", reboot); g_object_unref (G_OBJECT(self->current_transaction)); - self->current_transaction = NULL; + self->current_transaction = NULL; + if (self->reboot_query != 0){ + g_source_remove (self->reboot_query); + self->reboot_query = 0; + } + // Wait a sec before querying for reboot status, + // race condition with Apt has been observed. + self->reboot_query = g_timeout_add_seconds (1, + apt_watcher_query_reboot_status, + self); + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Finished Updating…")); } self->current_state = state; } @@ -302,8 +311,38 @@ apt_watcher_manage_transactions (AptWatcher* self, gchar* transaction_id) } } +static gboolean +apt_watcher_query_reboot_status (gpointer data) +{ + g_return_val_if_fail (APT_IS_WATCHER (data), FALSE); + AptWatcher* self = APT_WATCHER (data); + + GVariant* reboot_result = g_dbus_proxy_get_cached_property (self->proxy, + "RebootRequired"); + gboolean reboot; + g_variant_get (reboot_result, "b", &reboot); + g_debug ("apt_watcher_query_reboot_status: reboot prop = %i", reboot); + + if (reboot == FALSE){ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Software Up to Date")); + } + else{ + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Reboot Required")); + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_DISPOSITION, + DBUSMENU_MENUITEM_DISPOSITION_ALERT); + session_dbus_restart_required (self->session_dbus_interface); + } + self->reboot_query = 0; + return FALSE; +} + // TODO - Ask MVO about this. -// Signal is of type s not sas which is on d-feet !!! +// Signal is of type s not sas which is on d-feet. static void apt_watcher_signal_cb ( GDBusProxy* proxy, gchar* sender_name, gchar* signal_name, diff --git a/src/indicator-session.c b/src/indicator-session.c index fab47b3..0f44a36 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -499,6 +499,7 @@ receive_signal (GDBusProxy * proxy, } else if (g_strcmp0(signal_name, "RebootRequired") == 0) { // TODO waiting on design to give me a name. + g_debug ("Reboot required, icon changed to %s", ICON_RESTART); self->devices.image = indicator_image_helper (ICON_RESTART); } } diff --git a/src/session-dbus.xml b/src/session-dbus.xml index fd1859f..076e595 100644 --- a/src/session-dbus.xml +++ b/src/session-dbus.xml @@ -8,7 +8,7 @@ - + -- cgit v1.2.3 From 254ca429137d15b4814b171c96a7d92f1a46b2da Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 31 Aug 2011 13:19:38 +0100 Subject: restart signal actually being sent now properly --- src/indicator-session.c | 3 +-- src/session-dbus.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/indicator-session.c b/src/indicator-session.c index 0f44a36..3b5a7c3 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -497,8 +497,7 @@ receive_signal (GDBusProxy * proxy, &self->users); } } - else if (g_strcmp0(signal_name, "RebootRequired") == 0) { - // TODO waiting on design to give me a name. + else if (g_strcmp0(signal_name, "RestartRequired") == 0) { g_debug ("Reboot required, icon changed to %s", ICON_RESTART); self->devices.image = indicator_image_helper (ICON_RESTART); } diff --git a/src/session-dbus.c b/src/session-dbus.c index 1cf73ac..232e440 100644 --- a/src/session-dbus.c +++ b/src/session-dbus.c @@ -300,11 +300,13 @@ void session_dbus_restart_required (SessionDbus* session) GError * error = NULL; if (priv->bus != NULL) { + g_debug("About to send RebootRequired signal"); + g_dbus_connection_emit_signal (priv->bus, NULL, INDICATOR_SESSION_SERVICE_DBUS_OBJECT, INDICATOR_SESSION_SERVICE_DBUS_IFACE, - "RebootRequired", + "RestartRequired", NULL, &error); -- cgit v1.2.3 From 55a161683098d17364d9f521d2f4b97f89298297 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 31 Aug 2011 14:32:07 +0100 Subject: tidy up --- src/apt-watcher.c | 6 +----- src/indicator-session.c | 1 - src/session-dbus.xml | 3 --- 3 files changed, 1 insertion(+), 9 deletions(-) (limited to 'src') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index e757896..346b8a9 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -144,11 +144,7 @@ fetch_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_signal_connect (self->proxy, "g-signal", G_CALLBACK(apt_watcher_signal_cb), - self); - - /*self->reboot_query = g_timeout_add_seconds (5, - apt_watcher_query_reboot_status, - self);*/ + self); } diff --git a/src/indicator-session.c b/src/indicator-session.c index 3b5a7c3..aacef49 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -498,7 +498,6 @@ receive_signal (GDBusProxy * proxy, } } else if (g_strcmp0(signal_name, "RestartRequired") == 0) { - g_debug ("Reboot required, icon changed to %s", ICON_RESTART); self->devices.image = indicator_image_helper (ICON_RESTART); } } diff --git a/src/session-dbus.xml b/src/session-dbus.xml index 076e595..96e9837 100644 --- a/src/session-dbus.xml +++ b/src/session-dbus.xml @@ -8,9 +8,6 @@ - - - -- cgit v1.2.3 From c7a50eedd6e9878547b73e8cf952f75f544cb5d2 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 31 Aug 2011 15:51:16 +0100 Subject: make sure to bring up logout dialog from apt menuitem when restart is required --- src/apt-watcher.c | 35 ++++++++++++++++++++++++------ src/device-menu-mgr.c | 59 --------------------------------------------------- 2 files changed, 28 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 346b8a9..779d02b 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -56,7 +56,7 @@ static void apt_watcher_upgrade_system_cb (GObject * obj, static void apt_watcher_show_apt_dialog (DbusmenuMenuitem* mi, guint timestamp, - gchar * type); + gpointer userdata); static void apt_watcher_signal_cb (GDBusProxy* proxy, gchar* sender_name, @@ -216,14 +216,35 @@ apt_watcher_upgrade_system_cb (GObject * obj, static void apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, guint timestamp, - gchar * type) + gpointer userdata) { GError * error = NULL; - if (!g_spawn_command_line_async("update-manager", &error)) - { - g_warning("Unable to show update-manager: %s", error->message); - g_error_free(error); - } + g_return_if_fail (APT_IS_WATCHER (userdata)); + AptWatcher* self = APT_WATCHER (userdata); + + gchar* disposition = dbusmenu_menuitem_property_get (self->apt_item, + DBUSMENU_MENUITEM_PROP_DISPOSITION); + + if (g_strcmp0 (disposition, DBUSMENU_MENUITEM_DISPOSITION_ALERT) == 0){ + gchar * helper = g_build_filename (LIBEXECDIR, "gtk-logout-helper", NULL); + gchar * dialog_line = g_strdup_printf ("%s --%s", helper, "Restart"); + g_free(helper); + g_debug("Showing dialog '%s'", dialog_line); + GError * error = NULL; + + if (!g_spawn_command_line_async(dialog_line, &error)) { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } + g_free(dialog_line); + } + else{ + if (!g_spawn_command_line_async("update-manager", &error)) + { + g_warning("Unable to show update-manager: %s", error->message); + g_error_free(error); + } + } } static void diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 523ea8d..5a63be3 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -61,7 +61,6 @@ static DBusGProxyCall * hibernate_call = NULL; static DbusmenuMenuitem * hibernate_mi = NULL; static DbusmenuMenuitem * suspend_mi = NULL; static DbusmenuMenuitem * logout_mi = NULL; -static DbusmenuMenuitem * restart_mi = NULL; static DbusmenuMenuitem * shutdown_mi = NULL; static gboolean can_hibernate = TRUE; @@ -73,7 +72,6 @@ static DBusGProxy * up_main_proxy = NULL; static DBusGProxy * up_prop_proxy = NULL; static void device_menu_mgr_ensure_settings_client (DeviceMenuMgr* self); -static void setup_restart_watch (DeviceMenuMgr* self); static void setup_up (DeviceMenuMgr* self); static void device_menu_mgr_rebuild_items (DeviceMenuMgr *self); static void lock_if_possible (DeviceMenuMgr* self); @@ -106,7 +104,6 @@ device_menu_mgr_init (DeviceMenuMgr *self) { self->apt_watcher = NULL; self->root_item = dbusmenu_menuitem_new (); - setup_restart_watch(self); setup_up(self); g_idle_add(lock_screen_setup, NULL); } @@ -751,62 +748,6 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) can_suspend && allow_suspend); } -/* When the directory changes we need to figure out how our menu - item should look. */ -static void -restart_dir_changed (gpointer userdata) -{ - DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); - gboolean restart_required = g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS); - - if (restart_required) { - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_LABEL, - _("Restart to Complete Update")); - } else { - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_LABEL, - _("Restart to Complete Update\342\200\246")); - } - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_ICON, - "system-restart-panel"); - if (self->session_dbus_interface != NULL) { - session_dbus_set_name (self->session_dbus_interface, ICON_RESTART); - } - } else { - if (supress_confirmations()) { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart")); - } else { - dbusmenu_menuitem_property_set(restart_mi, RESTART_ITEM_LABEL, _("Restart\342\200\246")); - } - dbusmenu_menuitem_property_remove(restart_mi, RESTART_ITEM_ICON); - if (self->session_dbus_interface != NULL) { - session_dbus_set_name(self->session_dbus_interface, ICON_DEFAULT); - } - } - return; -} - -/* Buids a file watcher for the directory so that when it - changes we can check to see if our reboot-required is - there. */ -static void -setup_restart_watch (DeviceMenuMgr* self) -{ - GFile * filedir = g_file_new_for_path("/var/run"); - GFileMonitor * filemon = g_file_monitor_directory(filedir, G_FILE_MONITOR_NONE, NULL, NULL); - if (filemon != NULL) { - g_signal_connect (G_OBJECT(filemon), - "changed", - G_CALLBACK(restart_dir_changed), - self); - } - restart_dir_changed(self); - return; -} - /* Ensures that we have a GConf client and if we build one set up the signal handler. */ static void -- cgit v1.2.3 From 5f9ec570e2e9552273a9a7b4c15cc4f6ce03a3ab Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 31 Aug 2011 18:02:57 +0100 Subject: tidy up --- src/apt-watcher.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index 779d02b..d19dc4f 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -221,17 +221,14 @@ apt_watcher_show_apt_dialog (DbusmenuMenuitem * mi, GError * error = NULL; g_return_if_fail (APT_IS_WATCHER (userdata)); AptWatcher* self = APT_WATCHER (userdata); - - gchar* disposition = dbusmenu_menuitem_property_get (self->apt_item, - DBUSMENU_MENUITEM_PROP_DISPOSITION); + const gchar* disposition = NULL; + disposition = dbusmenu_menuitem_property_get (self->apt_item, + DBUSMENU_MENUITEM_PROP_DISPOSITION); if (g_strcmp0 (disposition, DBUSMENU_MENUITEM_DISPOSITION_ALERT) == 0){ gchar * helper = g_build_filename (LIBEXECDIR, "gtk-logout-helper", NULL); - gchar * dialog_line = g_strdup_printf ("%s --%s", helper, "Restart"); + gchar * dialog_line = g_strdup_printf ("%s --%s", helper, "restart"); g_free(helper); - g_debug("Showing dialog '%s'", dialog_line); - GError * error = NULL; - if (!g_spawn_command_line_async(dialog_line, &error)) { g_warning("Unable to show dialog: %s", error->message); g_error_free(error); -- cgit v1.2.3 From b8b29748d3346c1cabf7ccac301158c709e56f39 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 31 Aug 2011 18:20:08 +0100 Subject: set the menuitem's disposition back to normal just in case --- src/apt-watcher.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/apt-watcher.c b/src/apt-watcher.c index d19dc4f..f5c9d55 100644 --- a/src/apt-watcher.c +++ b/src/apt-watcher.c @@ -341,6 +341,10 @@ apt_watcher_query_reboot_status (gpointer data) dbusmenu_menuitem_property_set (self->apt_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Software Up to Date")); + dbusmenu_menuitem_property_set (self->apt_item, + DBUSMENU_MENUITEM_PROP_DISPOSITION, + DBUSMENU_MENUITEM_DISPOSITION_NORMAL); + } else{ dbusmenu_menuitem_property_set (self->apt_item, -- cgit v1.2.3 From 383e28467156675a5c1231c37eafb2a7bbc6e4f2 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 1 Sep 2011 18:23:35 +0100 Subject: much easier of handling the greeter icon --- src/dbus-shared-names.h | 1 + src/indicator-session.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index c5372e4..350fa6d 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -63,5 +63,6 @@ typedef enum { #define ICON_DEFAULT "system-devices-panel" #define ICON_RESTART "system-devices-panel-alert" +#define GREETER_ICON_DEFAULT "system-shutdown-panel" #endif /* __DBUS_SHARED_NAMES_H__ */ diff --git a/src/indicator-session.c b/src/indicator-session.c index aacef49..2b36fdd 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -164,10 +164,19 @@ indicator_session_init (IndicatorSession *self) self->users.label = GTK_LABEL (gtk_label_new (NULL)); + const gchar *greeter_var; + greeter_var = g_getenv("INDICATOR_GREETER_MODE"); + // devices self->devices.menu = GTK_MENU (dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT)); - self->devices.image = indicator_image_helper (ICON_DEFAULT); + if (g_strcmp0(greeter_var, "1") == 0){ + self->devices.image = indicator_image_helper (GREETER_ICON_DEFAULT); + } + else{ + self->devices.image = indicator_image_helper (ICON_DEFAULT); + } + gtk_widget_show (GTK_WIDGET(self->devices.menu)); gtk_widget_show (GTK_WIDGET(self->devices.image)); -- cgit v1.2.3