When user logout or shutdown the system, a warning dialog was showing about wrong DBus reply. Now are used
ConsoleKit commands 'CanStop' and 'CanRestart' to check can user perform the action.
This commit is contained in:
Sanel Zukan 2012-11-26 19:38:24 +00:00
parent b7eb2760dc
commit c5fd4cd9ee

View File

@ -106,29 +106,36 @@ static void send_dbus_ede_quit(void) {
#endif #endif
} }
#define CONSOLEKIT_SERVICE "org.freedesktop.ConsoleKit"
#define CONSOLEKIT_PATH "/org/freedesktop/ConsoleKit/Manager"
#define CONSOLEKIT_INTERFACE "org.freedesktop.ConsoleKit.Manager"
static bool do_shutdown_or_restart(bool restart) { static bool do_shutdown_or_restart(bool restart) {
const char *action; const char *action;
int r = 1; int r = 1;
#ifdef EDELIB_HAVE_DBUS #ifdef EDELIB_HAVE_DBUS
const char *can_do_action;
EdbusConnection c; EdbusConnection c;
if(!c.connect(EDBUS_SYSTEM)) { if(!c.connect(EDBUS_SYSTEM)) {
alert(_("Unable to connect to HAL daemon. Make sure both D-BUS and HAL daemons are running")); alert(_("Unable to connect to DBus daemon. Make sure system DBus daemon is running and have permissions to access it"));
return false; return false;
} }
/* determine what to check first; ConsoleKit shutdown action calls 'Stop' */ /* determine what to check first; ConsoleKit shutdown action calls 'Stop' */
action = restart ? "Restart" : "Stop"; can_do_action = restart ? "CanRestart" : "CanStop";
action = restart ? "Restart" : "Stop";
EdbusMessage msg, ret; EdbusMessage msg, ret;
msg.create_method_call("org.freedesktop.ConsoleKit", msg.create_method_call(CONSOLEKIT_SERVICE,
"/org/freedesktop/ConsoleKit/Manager", CONSOLEKIT_PATH,
"org.freedesktop.ConsoleKit.Manager", CONSOLEKIT_INTERFACE,
action); can_do_action);
if(!c.send_with_reply_and_block(msg, 100, ret)) { if(!c.send_with_reply_and_block(msg, 100, ret)) {
EdbusError *err = c.error(); EdbusError *err = c.error();
alert(_("Unable to complete this action. Got '%s' (%s)"), err->name(), err->message()); alert(_("Unable to communicate with DBus properly. Got '%s' (%s)"), err->name(), err->message());
return false; return false;
} }
@ -138,8 +145,15 @@ static bool do_shutdown_or_restart(bool restart) {
} }
EdbusMessage::iterator it = ret.begin(); EdbusMessage::iterator it = ret.begin();
if((*it).to_bool() == true) if(it->is_bool() && it->to_bool() == true) {
/* call action */
msg.create_method_call(CONSOLEKIT_SERVICE,
CONSOLEKIT_PATH,
CONSOLEKIT_INTERFACE,
action);
c.send(msg);
return true; return true;
}
r = ask(_("You are not allowed to execute this command. Please consult ConsoleKit documentation on how to allow privileged actions. " r = ask(_("You are not allowed to execute this command. Please consult ConsoleKit documentation on how to allow privileged actions. "
"Would you like to try to execute system commands?")); "Would you like to try to execute system commands?"));
@ -147,17 +161,17 @@ static bool do_shutdown_or_restart(bool restart) {
/* try to do things manually */ /* try to do things manually */
if(!r) return false; if(!r) return false;
const char *cmd = _("restart"); action = _("restart");
if(restart) { if(restart) {
r = run_sync(REBOOT_CMD); r = run_sync(REBOOT_CMD);
} else { } else {
r = run_sync(POWEROFF_CMD); r = run_sync(POWEROFF_CMD);
cmd = _("shutdown"); action = _("shutdown");
} }
if(r) { if(r) {
alert(_("Unable to %s the computer. Probably you do not have enough permissions to do that"), cmd); alert(_("Unable to %s the computer. Probably you do not have enough permissions to do that"), action);
return false; return false;
} }