Commit 5e004284 authored by Carlo Caione's avatar Carlo Caione

Add methods and backend to support RebootToFirmwareSetup

Add two new methods (SetRebootToFirmwareSetup and
CanRebootToFirmwareSetup) to the D-Bus interface to support rebooting
into setup mode. The idea is to present the user with a new option when
rebooting allowing to reboot into the firmware setup interface.
parent 26a00d75
......@@ -2537,6 +2537,38 @@ gsm_manager_can_shutdown (GsmExportedManager *skeleton,
return TRUE;
}
static gboolean
gsm_manager_can_reboot_to_firmware_setup (GsmExportedManager *skeleton,
GDBusMethodInvocation *invocation,
GsmManager *manager)
{
gboolean reboot_to_firmware_available;
g_debug ("GsmManager: CanRebootToFirmwareSetup called");
reboot_to_firmware_available = !_log_out_is_locked_down (manager) &&
gsm_system_can_restart_to_firmware_setup (manager->priv->system);
gsm_exported_manager_complete_can_reboot_to_firmware_setup (skeleton, invocation, reboot_to_firmware_available);
return TRUE;
}
static gboolean
gsm_manager_set_reboot_to_firmware_setup (GsmExportedManager *skeleton,
GDBusMethodInvocation *invocation,
gboolean enable,
GsmManager *manager)
{
g_debug ("GsmManager: SetRebootToFirmwareSetup called");
gsm_system_set_restart_to_firmware_setup (manager->priv->system, enable);
gsm_exported_manager_complete_set_reboot_to_firmware_setup (skeleton, invocation);
return TRUE;
}
static gboolean
gsm_manager_setenv (GsmExportedManager *skeleton,
GDBusMethodInvocation *invocation,
......@@ -3124,6 +3156,8 @@ register_manager (GsmManager *manager)
exit (1);
}
g_signal_connect (skeleton, "handle-can-reboot-to-firmware-setup",
G_CALLBACK (gsm_manager_can_reboot_to_firmware_setup), manager);
g_signal_connect (skeleton, "handle-can-shutdown",
G_CALLBACK (gsm_manager_can_shutdown), manager);
g_signal_connect (skeleton, "handle-get-clients",
......@@ -3148,6 +3182,8 @@ register_manager (GsmManager *manager)
G_CALLBACK (gsm_manager_reboot), manager);
g_signal_connect (skeleton, "handle-register-client",
G_CALLBACK (gsm_manager_register_client), manager);
g_signal_connect (skeleton, "handle-set-reboot-to-firmware-setup",
G_CALLBACK (gsm_manager_set_reboot_to_firmware_setup), manager);
g_signal_connect (skeleton, "handle-setenv",
G_CALLBACK (gsm_manager_setenv), manager);
g_signal_connect (skeleton, "handle-shutdown",
......
......@@ -85,6 +85,8 @@ gsm_system_null_init_iface (GsmSystemInterface *iface)
iface->can_switch_user = (void *) return_false;
iface->can_stop = (void *) return_false;
iface->can_restart = (void *) return_false;
iface->can_restart_to_firmware_setup = (void *) return_false;
iface->set_restart_to_firmware_setup = (void *) do_nothing;
iface->can_suspend = (void *) return_false;
iface->can_hibernate = (void *) return_false;
iface->attempt_stop = (void *) do_nothing;
......@@ -155,6 +157,19 @@ gsm_system_can_restart (GsmSystem *system)
return GSM_SYSTEM_GET_IFACE (system)->can_restart (system);
}
gboolean
gsm_system_can_restart_to_firmware_setup (GsmSystem *system)
{
return GSM_SYSTEM_GET_IFACE (system)->can_restart_to_firmware_setup (system);
}
void
gsm_system_set_restart_to_firmware_setup (GsmSystem *system,
gboolean enable)
{
GSM_SYSTEM_GET_IFACE (system)->set_restart_to_firmware_setup (system, enable);
}
gboolean
gsm_system_can_suspend (GsmSystem *system)
{
......
......@@ -53,6 +53,9 @@ struct _GsmSystemInterface
gboolean (* can_switch_user) (GsmSystem *system);
gboolean (* can_stop) (GsmSystem *system);
gboolean (* can_restart) (GsmSystem *system);
gboolean (* can_restart_to_firmware_setup) (GsmSystem *system);
void (* set_restart_to_firmware_setup) (GsmSystem *system,
gboolean enable);
gboolean (* can_suspend) (GsmSystem *system);
gboolean (* can_hibernate) (GsmSystem *system);
void (* attempt_stop) (GsmSystem *system);
......@@ -90,6 +93,11 @@ gboolean gsm_system_can_stop (GsmSystem *system);
gboolean gsm_system_can_restart (GsmSystem *system);
gboolean gsm_system_can_restart_to_firmware_setup (GsmSystem *system);
void gsm_system_set_restart_to_firmware_setup (GsmSystem *system,
gboolean enable);
gboolean gsm_system_can_suspend (GsmSystem *system);
gboolean gsm_system_can_hibernate (GsmSystem *system);
......
......@@ -530,6 +530,65 @@ gsm_systemd_can_restart (GsmSystem *system)
return can_restart;
}
static gboolean
gsm_systemd_can_restart_to_firmware_setup (GsmSystem *system)
{
GsmSystemd *manager = GSM_SYSTEMD (system);
const gchar *rv;
GVariant *res;
gboolean can_restart;
GError *error = NULL;
res = g_dbus_proxy_call_sync (manager->priv->sd_proxy,
"CanRebootToFirmwareSetup",
NULL,
G_DBUS_CALL_FLAGS_NONE,
G_MAXINT,
NULL,
&error);
if (!res) {
g_warning ("Calling CanRebootToFirmwareSetup failed. Check that logind is "
"properly installed and pam_systemd is getting used at login: %s",
error->message);
g_error_free (error);
return FALSE;
}
g_variant_get (res, "(&s)", &rv);
can_restart = g_strcmp0 (rv, "yes") == 0 ||
g_strcmp0 (rv, "challenge") == 0;
g_variant_unref (res);
return can_restart;
}
static void
gsm_systemd_set_restart_to_firmware_setup (GsmSystem *system,
gboolean enable)
{
GsmSystemd *manager = GSM_SYSTEMD (system);
GVariant *res;
GError *error = NULL;
res = g_dbus_proxy_call_sync (manager->priv->sd_proxy,
"SetRebootToFirmwareSetup",
g_variant_new ("(b)", enable),
G_DBUS_CALL_FLAGS_NONE,
G_MAXINT,
NULL,
&error);
if (!res) {
g_warning ("Calling SetRebootToFirmwareSetup failed. Check that logind is "
"properly installed and pam_systemd is getting used at login: %s",
error->message);
g_error_free (error);
}
g_variant_unref (res);
}
static gboolean
gsm_systemd_can_stop (GsmSystem *system)
{
......@@ -957,6 +1016,8 @@ gsm_systemd_system_init (GsmSystemInterface *iface)
iface->can_switch_user = gsm_systemd_can_switch_user;
iface->can_stop = gsm_systemd_can_stop;
iface->can_restart = gsm_systemd_can_restart;
iface->can_restart_to_firmware_setup = gsm_systemd_can_restart_to_firmware_setup;
iface->set_restart_to_firmware_setup = gsm_systemd_set_restart_to_firmware_setup;
iface->can_suspend = gsm_systemd_can_suspend;
iface->can_hibernate = gsm_systemd_can_hibernate;
iface->attempt_stop = gsm_systemd_attempt_stop;
......
......@@ -296,6 +296,33 @@
</doc:doc>
</method>
<method name="SetRebootToFirmwareSetup">
<arg name="enable" direction="in" type="b">
<doc:doc>
<doc:summary>Whether we should reboot into setup</doc:summary>
</doc:doc>
</arg>
<doc:doc>
<doc:description>
<doc:para>Allows the caller to indicate to the system's firmware to boot into setup mode</doc:para>
</doc:description>
</doc:doc>
</method>
<method name="CanRebootToFirmwareSetup">
<arg name="is_available" direction="out" type="b">
<doc:doc>
<doc:summary>True if boot into setup mode is available to the user, false otherwise</doc:summary>
</doc:doc>
</arg>
<doc:doc>
<doc:description>
<doc:para>Allows the caller to determine whether or not it's okay to show
a reboot to firmware option in the UI</doc:para>
</doc:description>
</doc:doc>
</method>
<method name="Logout">
<arg name="mode" type="u" direction="in">
<doc:doc>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment