- backport from upstream lxsession-0.4.4-fix_upower_support.patch

lxsession-logout can finally fully work without HAL
  (using UPower)

OBS-URL: https://build.opensuse.org/package/show/X11:lxde/lxsession?expand=0&rev=34
This commit is contained in:
andrea florio 2010-07-26 06:56:07 +00:00 committed by Git OBS Bridge
parent 0b9c317702
commit 72d84ff149
3 changed files with 511 additions and 0 deletions

View File

@ -0,0 +1,500 @@
diff -uNr old-lxsession-0.4.4//lxsession-logout/dbus-interface.c lxsession-0.4.4/lxsession-logout/dbus-interface.c
--- old-lxsession-0.4.4//lxsession-logout/dbus-interface.c 2010-03-28 20:20:12.000000000 +0200
+++ lxsession-0.4.4/lxsession-logout/dbus-interface.c 2010-07-25 23:39:52.059867576 +0200
@@ -54,7 +54,7 @@
}
/* Send a message. */
-static DBusMessage * dbus_send_message(DBusMessage * message)
+static DBusMessage * dbus_send_message(DBusMessage * message, char * * error_text)
{
/* Get a connection handle. */
DBusConnection * connection = dbus_connect();
@@ -68,36 +68,25 @@
dbus_message_unref(message);
if (reply == NULL)
{
- g_warning(G_STRLOC ": DBUS: %s", error.message);
+ if ((error.name == NULL) || (strcmp(error.name, DBUS_ERROR_NO_REPLY) != 0))
+ {
+ if (error_text != NULL)
+ *error_text = g_strdup(error.message);
+ g_warning(G_STRLOC ": DBUS: %s", error.message);
+ }
dbus_error_free(&error);
}
return reply;
}
-/* Send a message with no reply expected. */
-static gboolean dbus_send_message_without_reply(DBusMessage * message)
-{
- /* Get a connection handle. */
- DBusConnection * connection = dbus_connect();
- if (connection == NULL)
- return FALSE;
-
- /* Send the message in the blind. */
- dbus_bool_t status = dbus_connection_send(connection, message, NULL);
- dbus_message_unref(message);
- if ( ! status)
- g_warning(G_STRLOC ": DBUS: dbus_connection_send failed\n");
- return status;
-}
-
/* Read a result for a method that returns void. */
-static gboolean dbus_read_result_void(DBusMessage * reply)
+static char * dbus_read_result_void(DBusMessage * reply)
{
if (reply != NULL)
dbus_message_unref(reply);
/* No result. Assume success. */
- return TRUE;
+ return NULL;
}
/* Read a result for a method that returns boolean. */
@@ -144,19 +133,21 @@
static gboolean dbus_ConsoleKit_query(const char * const query)
{
#ifdef HAVE_DBUS
- return dbus_read_result_boolean(dbus_send_message(dbus_ConsoleKit_formulate_message(query)));
+ return dbus_read_result_boolean(dbus_send_message(dbus_ConsoleKit_formulate_message(query), NULL));
#else
return FALSE;
#endif
}
/* Send a specified message to the ConsoleKit interface and process a void result. */
-static gboolean dbus_ConsoleKit_command(const char * const command)
+static char * dbus_ConsoleKit_command(const char * const command)
{
#ifdef HAVE_DBUS
- return dbus_read_result_void(dbus_send_message(dbus_ConsoleKit_formulate_message(command)));
+ char * error = NULL;
+ dbus_read_result_void(dbus_send_message(dbus_ConsoleKit_formulate_message(command), &error));
+ return error;
#else
- return FALSE;
+ return NULL;
#endif
}
@@ -173,49 +164,49 @@
}
/* Invoke the Stop method on ConsoleKit. */
-gboolean dbus_ConsoleKit_Stop(void)
+char * dbus_ConsoleKit_Stop(void)
{
return dbus_ConsoleKit_command("Stop");
}
/* Invoke the Restart method on ConsoleKit. */
-gboolean dbus_ConsoleKit_Restart(void)
+char * dbus_ConsoleKit_Restart(void)
{
return dbus_ConsoleKit_command("Restart");
}
-/*** DeviceKit Power mechanism ***/
+/*** UPower mechanism ***/
#ifdef HAVE_DBUS
-/* Formulate a message to the DeviceKit Power interface. */
-static DBusMessage * dbus_DeviceKit_formulate_command(const char * const command)
+/* Formulate a message to the UPower interface. */
+static DBusMessage * dbus_UPower_formulate_command(const char * const command)
{
return dbus_message_new_method_call(
- "org.freedesktop.DeviceKit.Power",
- "/org/freedesktop/DeviceKit/Power",
- "org.freedesktop.DeviceKit.Power",
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower",
+ "org.freedesktop.UPower",
command);
}
#endif
-/* Send a specified message to the DeviceKit interface and process a boolean result. */
-static gboolean dbus_DeviceKit_query(const char * const query)
+/* Send a specified message to the UPower interface and process a boolean result. */
+static gboolean dbus_UPower_query(const char * const query)
{
#ifdef HAVE_DBUS
/* Formulate a message to the Properties interface. */
DBusMessage * message = dbus_message_new_method_call(
- "org.freedesktop.DeviceKit.Power",
- "/org/freedesktop/DeviceKit/Power",
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower",
"org.freedesktop.DBus.Properties",
"Get");
- const char * const interface_name = "org.freedesktop.DeviceKit.Power";
+ const char * const interface_name = "org.freedesktop.UPower";
dbus_message_append_args(message,
DBUS_TYPE_STRING, &interface_name,
DBUS_TYPE_STRING, &query,
DBUS_TYPE_INVALID);
/* Send the message. */
- DBusMessage * reply = dbus_send_message(message);
+ DBusMessage * reply = dbus_send_message(message, NULL);
if (reply == NULL)
return FALSE;
@@ -237,39 +228,40 @@
#endif
}
-/* Send a specified message to the DeviceKit interface and process a void result. */
-static gboolean dbus_DeviceKit_command(const char * const command)
+/* Send a specified message to the UPower interface and process a void result. */
+static char * dbus_UPower_command(const char * const command)
{
#ifdef HAVE_DBUS
- return dbus_read_result_void(dbus_send_message(dbus_DeviceKit_formulate_command(command)));
-// return dbus_send_message_without_reply(dbus_DeviceKit_formulate_command(command)); It seems they don't send a reply; to be checked out
+ char * error = NULL;
+ dbus_read_result_void(dbus_send_message(dbus_UPower_formulate_command(command), &error));
+ return error;
#else
- return FALSE;
+ return NULL;
#endif
}
-/* Read the can-suspend property of DeviceKit/Power. */
-gboolean dbus_DeviceKit_CanSuspend(void)
+/* Read the can-suspend property of UPower. */
+gboolean dbus_UPower_CanSuspend(void)
{
- return dbus_DeviceKit_query("CanSuspend");
+ return dbus_UPower_query("CanSuspend");
}
-/* Read the can-hibernate property of DeviceKit/Power. */
-gboolean dbus_DeviceKit_CanHibernate(void)
+/* Read the can-hibernate property of UPower. */
+gboolean dbus_UPower_CanHibernate(void)
{
- return dbus_DeviceKit_query("CanHibernate");
+ return dbus_UPower_query("CanHibernate");
}
-/* Invoke the Suspend method on DeviceKit/Power. */
-gboolean dbus_DeviceKit_Suspend(void)
+/* Invoke the Suspend method on UPower. */
+char * dbus_UPower_Suspend(void)
{
- return dbus_DeviceKit_command("Suspend");
+ return dbus_UPower_command("Suspend");
}
-/* Invoke the Hibernate method on DeviceKit/Power. */
-gboolean dbus_DeviceKit_Hibernate(void)
+/* Invoke the Hibernate method on UPower. */
+char * dbus_UPower_Hibernate(void)
{
- return dbus_DeviceKit_command("Hibernate");
+ return dbus_UPower_command("Hibernate");
}
/*** HAL mechanism ***/
@@ -318,7 +310,7 @@
DBusMessage * message = dbus_HAL_formulate_string_property_query(property);
if (message == NULL)
return FALSE;
- DBusMessage * reply = dbus_send_message(message);
+ DBusMessage * reply = dbus_send_message(message, NULL);
if (reply == NULL)
return FALSE;
dbus_message_unref(reply);
@@ -332,20 +324,20 @@
static gboolean dbus_HAL_boolean_query(const char * const property)
{
#ifdef HAVE_DBUS
- return dbus_read_result_boolean(dbus_send_message(dbus_HAL_formulate_boolean_property_query(property)));
+ return dbus_read_result_boolean(dbus_send_message(dbus_HAL_formulate_boolean_property_query(property), NULL));
#else
return FALSE;
#endif
}
/* Send a specified message to the HAL interface and process a void result. */
-static gboolean dbus_HAL_command(const char * const command)
+static char * dbus_HAL_command(const char * const command)
{
#ifdef HAVE_DBUS
/* Formulate the message. */
DBusMessage * message = dbus_HAL_formulate_message(command);
if (message == NULL)
- return FALSE;
+ return NULL;
/* Suspend has an argument. */
if (strcmp(command, "Suspend") == 0)
@@ -355,9 +347,11 @@
}
/* Send the message and wait for a reply. */
- return dbus_read_result_void(dbus_send_message(message));
+ char * error = NULL;
+ dbus_read_result_void(dbus_send_message(message, &error));
+ return error;
#else
- return FALSE;
+ return NULL;
#endif
}
@@ -386,25 +380,25 @@
}
/* Invoke the Shutdown method on HAL. */
-gboolean dbus_HAL_Shutdown(void)
+char * dbus_HAL_Shutdown(void)
{
return dbus_HAL_command("Shutdown");
}
/* Invoke the Reboot method on HAL. */
-gboolean dbus_HAL_Reboot(void)
+char * dbus_HAL_Reboot(void)
{
return dbus_HAL_command("Reboot");
}
/* Invoke the Suspend method on HAL. */
-gboolean dbus_HAL_Suspend(void)
+char * dbus_HAL_Suspend(void)
{
return dbus_HAL_command("Suspend");
}
/* Invoke the Hibernate method on HAL. */
-gboolean dbus_HAL_Hibernate(void)
+char * dbus_HAL_Hibernate(void)
{
return dbus_HAL_command("Hibernate");
}
diff -uNr old-lxsession-0.4.4//lxsession-logout/dbus-interface.h lxsession-0.4.4/lxsession-logout/dbus-interface.h
--- old-lxsession-0.4.4//lxsession-logout/dbus-interface.h 2010-03-06 11:20:19.000000000 +0100
+++ lxsession-0.4.4/lxsession-logout/dbus-interface.h 2010-07-25 23:39:52.068871814 +0200
@@ -24,14 +24,14 @@
/* Interface to ConsoleKit for shutdown and reboot. */
extern gboolean dbus_ConsoleKit_CanStop(void);
extern gboolean dbus_ConsoleKit_CanRestart(void);
-extern gboolean dbus_ConsoleKit_Stop(void);
-extern gboolean dbus_ConsoleKit_Restart(void);
+extern char * dbus_ConsoleKit_Stop(void);
+extern char * dbus_ConsoleKit_Restart(void);
-/* Interface to DeviceKit/Power for suspend and hibernate. */
-extern gboolean dbus_DeviceKit_CanSuspend(void);
-extern gboolean dbus_DeviceKit_CanHibernate(void);
-extern gboolean dbus_DeviceKit_Suspend(void);
-extern gboolean dbus_DeviceKit_Hibernate(void);
+/* Interface to UPower for suspend and hibernate. */
+extern gboolean dbus_UPower_CanSuspend(void);
+extern gboolean dbus_UPower_CanHibernate(void);
+extern char * dbus_UPower_Suspend(void);
+extern char * dbus_UPower_Hibernate(void);
/* Interface to HAL for shutdown, reboot, suspend, and hibernate.
* HAL is being replaced by the above two mechanisms; this support is legacy. */
@@ -39,9 +39,9 @@
extern gboolean dbus_HAL_CanReboot(void);
extern gboolean dbus_HAL_CanSuspend(void);
extern gboolean dbus_HAL_CanHibernate(void);
-gboolean dbus_HAL_Shutdown(void);
-gboolean dbus_HAL_Reboot(void);
-gboolean dbus_HAL_Suspend(void);
-gboolean dbus_HAL_Hibernate(void);
+extern char * dbus_HAL_Shutdown(void);
+extern char * dbus_HAL_Reboot(void);
+extern char * dbus_HAL_Suspend(void);
+extern char * dbus_HAL_Hibernate(void);
#endif
diff -uNr old-lxsession-0.4.4//lxsession-logout/lxsession-logout.c lxsession-0.4.4/lxsession-logout/lxsession-logout.c
--- old-lxsession-0.4.4//lxsession-logout/lxsession-logout.c 2010-07-25 23:39:12.933867740 +0200
+++ lxsession-0.4.4/lxsession-logout/lxsession-logout.c 2010-07-25 23:50:55.106114634 +0200
@@ -53,6 +53,7 @@
typedef struct {
GPid lxsession_pid; /* Process ID of lxsession */
+ GtkWidget * error_label; /* Text of an error, if we get one */
int shutdown_available : 1; /* Shutdown is available */
int reboot_available : 1; /* Reboot is available */
@@ -62,20 +63,21 @@
int shutdown_ConsoleKit : 1; /* Shutdown is available via ConsoleKit */
int reboot_ConsoleKit : 1; /* Reboot is available via ConsoleKit */
- int suspend_DeviceKit : 1; /* Suspend is available via DeviceKit */
- int hibernate_DeviceKit : 1; /* Hibernate is available via DeviceKit */
+ int suspend_UPower : 1; /* Suspend is available via UPower */
+ int hibernate_UPower : 1; /* Hibernate is available via UPower */
int shutdown_HAL : 1; /* Shutdown is available via HAL */
int reboot_HAL : 1; /* Reboot is available via HAL */
int suspend_HAL : 1; /* Suspend is available via HAL */
int hibernate_HAL : 1; /* Hibernate is available via HAL */
int switch_user_GDM : 1; /* Switch User is available via GDM */
int switch_user_KDM : 1; /* Switch User is available via KDM */
- int ltsp : 1; /* under LTSP environment */
+ int ltsp : 1; /* Shutdown and reboot is accomplished via LTSP */
} HandlerContext;
static gboolean lock_screen(void);
static gboolean verify_running(char * display_manager, char * executable);
static void logout_clicked(GtkButton * button, HandlerContext * handler_context);
+static void change_root_property(GtkWidget* w, const char* prop_name, const char* value);
static void shutdown_clicked(GtkButton * button, HandlerContext * handler_context);
static void reboot_clicked(GtkButton * button, HandlerContext * handler_context);
static void suspend_clicked(GtkButton * button, HandlerContext * handler_context);
@@ -187,6 +189,7 @@
gtk_main_quit();
}
+/* Replace a property on the root window. */
static void change_root_property(GtkWidget* w, const char* prop_name, const char* value)
{
GdkDisplay* dpy = gtk_widget_get_display(w);
@@ -199,59 +202,81 @@
/* Handler for "clicked" signal on Shutdown button. */
static void shutdown_clicked(GtkButton * button, HandlerContext * handler_context)
{
- if (G_UNLIKELY(handler_context->ltsp))
+ char * error_result = NULL;
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
+
+ if (handler_context->ltsp)
{
change_root_property(GTK_WIDGET(button), "LTSP_LOGOUT_ACTION", "HALT");
kill(handler_context->lxsession_pid, SIGTERM);
}
else if (handler_context->shutdown_ConsoleKit)
- dbus_ConsoleKit_Stop();
+ error_result = dbus_ConsoleKit_Stop();
else if (handler_context->shutdown_HAL)
- dbus_HAL_Shutdown();
- gtk_main_quit();
+ error_result = dbus_HAL_Shutdown();
+ if (error_result != NULL)
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
+ else gtk_main_quit();
}
/* Handler for "clicked" signal on Reboot button. */
static void reboot_clicked(GtkButton * button, HandlerContext * handler_context)
{
- if (G_UNLIKELY(handler_context->ltsp))
+ char * error_result = NULL;
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
+
+ if (handler_context->ltsp)
{
change_root_property(GTK_WIDGET(button), "LTSP_LOGOUT_ACTION", "REBOOT");
kill(handler_context->lxsession_pid, SIGTERM);
}
else if (handler_context->reboot_ConsoleKit)
- dbus_ConsoleKit_Restart();
+ error_result = dbus_ConsoleKit_Restart();
else if (handler_context->reboot_HAL)
- dbus_HAL_Reboot();
- gtk_main_quit();
+ error_result = dbus_HAL_Reboot();
+ if (error_result != NULL)
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
+ else gtk_main_quit();
}
/* Handler for "clicked" signal on Suspend button. */
static void suspend_clicked(GtkButton * button, HandlerContext * handler_context)
{
lock_screen();
- if (handler_context->suspend_DeviceKit)
- dbus_DeviceKit_Suspend();
+ char * error_result = NULL;
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
+
+ if (handler_context->suspend_UPower)
+ error_result = dbus_UPower_Suspend();
else if (handler_context->suspend_HAL)
- dbus_HAL_Suspend();
- gtk_main_quit();
+ error_result = dbus_HAL_Suspend();
+ if (error_result != NULL)
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
+ else gtk_main_quit();
}
/* Handler for "clicked" signal on Hibernate button. */
static void hibernate_clicked(GtkButton * button, HandlerContext * handler_context)
{
lock_screen();
- if (handler_context->hibernate_DeviceKit)
- dbus_DeviceKit_Hibernate();
+ char * error_result = NULL;
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
+
+ if (handler_context->hibernate_UPower)
+ error_result = dbus_UPower_Hibernate();
else if (handler_context->hibernate_HAL)
- dbus_HAL_Hibernate();
- gtk_main_quit();
+ error_result = dbus_HAL_Hibernate();
+ if (error_result != NULL)
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), error_result);
+ else gtk_main_quit();
}
/* Handler for "clicked" signal on Switch User button. */
static void switch_user_clicked(GtkButton * button, HandlerContext * handler_context)
{
+
lock_screen();
+ gtk_label_set_text(GTK_LABEL(handler_context->error_label), NULL);
if (handler_context->switch_user_GDM)
g_spawn_command_line_sync("gdmflexiserver --startnew", NULL, NULL, NULL, NULL);
else if (handler_context->switch_user_KDM)
@@ -386,19 +411,17 @@
handler_context.reboot_ConsoleKit = TRUE;
}
-#ifdef LATENT_DEVICEKIT_SUPPORT
- /* Initialize capabilities of the DeviceKit mechanism. */
- if (dbus_DeviceKit_CanSuspend())
+ /* Initialize capabilities of the UPower mechanism. */
+ if (dbus_UPower_CanSuspend())
{
handler_context.suspend_available = TRUE;
- handler_context.suspend_DeviceKit = TRUE;
+ handler_context.suspend_UPower = TRUE;
}
- if (dbus_DeviceKit_CanHibernate())
+ if (dbus_UPower_CanHibernate())
{
handler_context.hibernate_available = TRUE;
- handler_context.hibernate_DeviceKit = TRUE;
+ handler_context.hibernate_UPower = TRUE;
}
-#endif
/* Initialize capabilities of the HAL mechanism. */
if (!handler_context.shutdown_available && dbus_HAL_CanShutdown())
@@ -597,6 +620,11 @@
g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(cancel_clicked), NULL);
gtk_box_pack_start(GTK_BOX(controls), cancel_button, FALSE, FALSE, 4);
+ /* Create the error text. */
+ handler_context.error_label = gtk_label_new("");
+ gtk_label_set_justify(GTK_LABEL(handler_context.error_label), GTK_JUSTIFY_CENTER);
+ gtk_box_pack_start(GTK_BOX(controls), handler_context.error_label, FALSE, FALSE, 4);
+
/* Show everything. */
gtk_widget_show_all(window);

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Jul 26 06:54:37 UTC 2010 - andrea@opensuse.org
- backport from upstream lxsession-0.4.4-fix_upower_support.patch
lxsession-logout can finally fully work without HAL
(using UPower)
-------------------------------------------------------------------
Sat Jul 17 09:51:25 UTC 2010 - guido+opensuse.org@berhoerster.name

View File

@ -32,6 +32,9 @@ Patch0: %name-0.4.4-lock-screen-bnc622083.patch
# PATCH-FIX-UPSTREAM lxsession-0.4.4-fix-bnc623192.patch bnc#623192 andrea@opensuse.org
# lxsession crasch with signal 6 (SIGABRT)
Patch1: %name-0.4.4-fix-bnc623192.patch
# PATCH-FIX-UPSTREAM lxsession-0.4.4-fix_upower_support.patch andrea@opensuse.org
# lxsession-logout now finally fully work without hal (using upower) backport patch from upstream git
Patch2: %name-0.4.4-fix_upower_support.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: dbus-1-glib-devel fdupes gtk2-devel intltool pkg-config
BuildRequires: docbook-utils docbook-xsl-stylesheets hal-devel libxslt
@ -50,6 +53,7 @@ Authors:
%setup -q -n %name-%version
%patch0 -p1
%patch1 -p1
%patch2 -p1
%build
export CFLAGS="$RPM_OPT_FLAGS"