mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2025-12-29 15:50:06 +01:00
Add a config file with SleepTimeout and AllowHibernateEncryptedSwap entries
This commit is contained in:
parent
42f0715637
commit
5f1e64709b
5 changed files with 157 additions and 92 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
SUBDIRS = devkit-power-gobject libupower-glib src doc tools policy po
|
SUBDIRS = etc devkit-power-gobject libupower-glib src doc tools policy po
|
||||||
|
|
||||||
if BACKEND_TYPE_LINUX
|
if BACKEND_TYPE_LINUX
|
||||||
SUBDIRS += rules
|
SUBDIRS += rules
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,7 @@ AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
devkit-power-gobject.pc
|
devkit-power-gobject.pc
|
||||||
upower-glib.pc
|
upower-glib.pc
|
||||||
|
etc/Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
src/dummy/Makefile
|
src/dummy/Makefile
|
||||||
src/freebsd/Makefile
|
src/freebsd/Makefile
|
||||||
|
|
|
||||||
6
etc/Makefile.am
Normal file
6
etc/Makefile.am
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
configdir = $(sysconfdir)/UPower
|
||||||
|
config_DATA = UPower.conf
|
||||||
|
|
||||||
|
EXTRA_DIST = \
|
||||||
|
$(config_DATA)
|
||||||
|
|
||||||
22
etc/UPower.conf
Normal file
22
etc/UPower.conf
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Only the system vendor should modify this file, ordinary users
|
||||||
|
# should not have to change anything.
|
||||||
|
|
||||||
|
[UPower]
|
||||||
|
|
||||||
|
# This is the smallest amount of time that UPower gives to session and system
|
||||||
|
# processes after the suspend or hibernate request is given.
|
||||||
|
# If the session power management component uses AboutToSuspend() then the
|
||||||
|
# session process can only make this time larger than the value below, never
|
||||||
|
# smaller.
|
||||||
|
#
|
||||||
|
# Reducing this time means the suspend happens quicker, but might also not give
|
||||||
|
# some processes enough time to save state.
|
||||||
|
#
|
||||||
|
# default=1000
|
||||||
|
SleepTimeout=1000
|
||||||
|
|
||||||
|
# This controls whether hibernate is allowed when using encrypted swap.
|
||||||
|
#
|
||||||
|
# default=true
|
||||||
|
AllowHibernateEncryptedSwap=true
|
||||||
|
|
||||||
218
src/up-daemon.c
218
src/up-daemon.c
|
|
@ -89,6 +89,8 @@ struct UpDaemonPrivate
|
||||||
guint battery_poll_count;
|
guint battery_poll_count;
|
||||||
GTimer *about_to_sleep_timer;
|
GTimer *about_to_sleep_timer;
|
||||||
guint about_to_sleep_id;
|
guint about_to_sleep_id;
|
||||||
|
guint conf_sleep_timeout;
|
||||||
|
gboolean conf_allow_hibernate_encrypted_swap;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void up_daemon_finalize (GObject *object);
|
static void up_daemon_finalize (GObject *object);
|
||||||
|
|
@ -309,13 +311,14 @@ up_daemon_about_to_sleep (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
PolkitSubject *subject = NULL;
|
PolkitSubject *subject = NULL;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
egg_debug ("emitting sleeping");
|
egg_debug ("emitting sleeping");
|
||||||
g_signal_emit (daemon, signals[SIGNAL_SLEEPING], 0);
|
g_signal_emit (daemon, signals[SIGNAL_SLEEPING], 0);
|
||||||
g_timer_start (daemon->priv->about_to_sleep_timer);
|
g_timer_start (priv->about_to_sleep_timer);
|
||||||
|
|
||||||
/* already requested */
|
/* already requested */
|
||||||
if (daemon->priv->about_to_sleep_id != 0) {
|
if (priv->about_to_sleep_id != 0) {
|
||||||
error = g_error_new (UP_DAEMON_ERROR,
|
error = g_error_new (UP_DAEMON_ERROR,
|
||||||
UP_DAEMON_ERROR_GENERAL,
|
UP_DAEMON_ERROR_GENERAL,
|
||||||
"Sleep has already been requested and is pending");
|
"Sleep has already been requested and is pending");
|
||||||
|
|
@ -323,12 +326,12 @@ up_daemon_about_to_sleep (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
subject = up_polkit_get_subject (daemon->priv->polkit, context);
|
subject = up_polkit_get_subject (priv->polkit, context);
|
||||||
if (subject == NULL)
|
if (subject == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* TODO: use another PolicyKit context? */
|
/* TODO: use another PolicyKit context? */
|
||||||
if (!up_polkit_check_auth (daemon->priv->polkit, subject, "org.freedesktop.upower.suspend", context))
|
if (!up_polkit_check_auth (priv->polkit, subject, "org.freedesktop.upower.suspend", context))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
dbus_g_method_return (context, NULL);
|
dbus_g_method_return (context, NULL);
|
||||||
|
|
@ -357,6 +360,7 @@ up_daemon_deferred_sleep_cb (UpDaemonDeferredSleep *sleep)
|
||||||
gchar *stderr = NULL;
|
gchar *stderr = NULL;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
UpDaemon *daemon = sleep->daemon;
|
UpDaemon *daemon = sleep->daemon;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
/* run the command */
|
/* run the command */
|
||||||
ret = g_spawn_command_line_sync (sleep->command, &stdout, &stderr, NULL, &error_local);
|
ret = g_spawn_command_line_sync (sleep->command, &stdout, &stderr, NULL, &error_local);
|
||||||
|
|
@ -374,15 +378,15 @@ up_daemon_deferred_sleep_cb (UpDaemonDeferredSleep *sleep)
|
||||||
g_signal_emit (daemon, signals[SIGNAL_RESUMING], 0);
|
g_signal_emit (daemon, signals[SIGNAL_RESUMING], 0);
|
||||||
|
|
||||||
/* reset the about-to-sleep logic */
|
/* reset the about-to-sleep logic */
|
||||||
g_timer_reset (daemon->priv->about_to_sleep_timer);
|
g_timer_reset (priv->about_to_sleep_timer);
|
||||||
g_timer_stop (daemon->priv->about_to_sleep_timer);
|
g_timer_stop (priv->about_to_sleep_timer);
|
||||||
|
|
||||||
/* actually return from the DBus call now */
|
/* actually return from the DBus call now */
|
||||||
dbus_g_method_return (sleep->context, NULL);
|
dbus_g_method_return (sleep->context, NULL);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
/* clear timer */
|
/* clear timer */
|
||||||
daemon->priv->about_to_sleep_id = 0;
|
priv->about_to_sleep_id = 0;
|
||||||
|
|
||||||
g_free (stdout);
|
g_free (stdout);
|
||||||
g_free (stderr);
|
g_free (stderr);
|
||||||
|
|
@ -402,6 +406,7 @@ static void
|
||||||
up_daemon_deferred_sleep (UpDaemon *daemon, const gchar *command, DBusGMethodInvocation *context)
|
up_daemon_deferred_sleep (UpDaemon *daemon, const gchar *command, DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
UpDaemonDeferredSleep *sleep;
|
UpDaemonDeferredSleep *sleep;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
gfloat elapsed;
|
gfloat elapsed;
|
||||||
|
|
||||||
/* create callback object */
|
/* create callback object */
|
||||||
|
|
@ -411,14 +416,15 @@ up_daemon_deferred_sleep (UpDaemon *daemon, const gchar *command, DBusGMethodInv
|
||||||
sleep->command = g_strdup (command);
|
sleep->command = g_strdup (command);
|
||||||
|
|
||||||
/* about to sleep */
|
/* about to sleep */
|
||||||
elapsed = g_timer_elapsed (daemon->priv->about_to_sleep_timer, NULL);
|
elapsed = 1000.0f * g_timer_elapsed (priv->about_to_sleep_timer, NULL);
|
||||||
egg_debug ("between AboutToSleep() and %s was %fs", sleep->command, elapsed);
|
egg_debug ("between AboutToSleep() and %s was %fms", sleep->command, elapsed);
|
||||||
if (elapsed < 1.0f) {
|
if (elapsed < priv->conf_sleep_timeout) {
|
||||||
/* we have to wait for a little bit */
|
/* we have to wait for a little bit */
|
||||||
daemon->priv->about_to_sleep_id = g_timeout_add (1000 - (elapsed * 1000), (GSourceFunc) up_daemon_deferred_sleep_cb, sleep);
|
priv->about_to_sleep_id = g_timeout_add (priv->conf_sleep_timeout - elapsed,
|
||||||
|
(GSourceFunc) up_daemon_deferred_sleep_cb, sleep);
|
||||||
} else {
|
} else {
|
||||||
/* we can do this straight away */
|
/* we can do this straight away */
|
||||||
daemon->priv->about_to_sleep_id = g_idle_add ((GSourceFunc) up_daemon_deferred_sleep_cb, sleep);
|
priv->about_to_sleep_id = g_idle_add ((GSourceFunc) up_daemon_deferred_sleep_cb, sleep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -431,9 +437,10 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
GError *error;
|
GError *error;
|
||||||
PolkitSubject *subject = NULL;
|
PolkitSubject *subject = NULL;
|
||||||
const gchar *command;
|
const gchar *command;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
/* no kernel support */
|
/* no kernel support */
|
||||||
if (!daemon->priv->kernel_can_suspend) {
|
if (!priv->kernel_can_suspend) {
|
||||||
error = g_error_new (UP_DAEMON_ERROR,
|
error = g_error_new (UP_DAEMON_ERROR,
|
||||||
UP_DAEMON_ERROR_GENERAL,
|
UP_DAEMON_ERROR_GENERAL,
|
||||||
"No kernel support");
|
"No kernel support");
|
||||||
|
|
@ -441,15 +448,15 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
subject = up_polkit_get_subject (daemon->priv->polkit, context);
|
subject = up_polkit_get_subject (priv->polkit, context);
|
||||||
if (subject == NULL)
|
if (subject == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!up_polkit_check_auth (daemon->priv->polkit, subject, "org.freedesktop.upower.suspend", context))
|
if (!up_polkit_check_auth (priv->polkit, subject, "org.freedesktop.upower.suspend", context))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* already requested */
|
/* already requested */
|
||||||
if (daemon->priv->about_to_sleep_id != 0) {
|
if (priv->about_to_sleep_id != 0) {
|
||||||
error = g_error_new (UP_DAEMON_ERROR,
|
error = g_error_new (UP_DAEMON_ERROR,
|
||||||
UP_DAEMON_ERROR_GENERAL,
|
UP_DAEMON_ERROR_GENERAL,
|
||||||
"Sleep has already been requested and is pending");
|
"Sleep has already been requested and is pending");
|
||||||
|
|
@ -458,7 +465,7 @@ up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* do this deferred action */
|
/* do this deferred action */
|
||||||
command = up_backend_get_suspend_command (daemon->priv->backend);
|
command = up_backend_get_suspend_command (priv->backend);
|
||||||
up_daemon_deferred_sleep (daemon, command, context);
|
up_daemon_deferred_sleep (daemon, command, context);
|
||||||
out:
|
out:
|
||||||
if (subject != NULL)
|
if (subject != NULL)
|
||||||
|
|
@ -474,12 +481,13 @@ up_daemon_suspend_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
PolkitSubject *subject = NULL;
|
PolkitSubject *subject = NULL;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
subject = up_polkit_get_subject (daemon->priv->polkit, context);
|
subject = up_polkit_get_subject (priv->polkit, context);
|
||||||
if (subject == NULL)
|
if (subject == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = up_polkit_is_allowed (daemon->priv->polkit, subject, "org.freedesktop.upower.suspend", context);
|
ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.suspend", context);
|
||||||
dbus_g_method_return (context, ret);
|
dbus_g_method_return (context, ret);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
@ -497,9 +505,10 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
GError *error;
|
GError *error;
|
||||||
PolkitSubject *subject = NULL;
|
PolkitSubject *subject = NULL;
|
||||||
const gchar *command;
|
const gchar *command;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
/* no kernel support */
|
/* no kernel support */
|
||||||
if (!daemon->priv->kernel_can_hibernate) {
|
if (!priv->kernel_can_hibernate) {
|
||||||
error = g_error_new (UP_DAEMON_ERROR,
|
error = g_error_new (UP_DAEMON_ERROR,
|
||||||
UP_DAEMON_ERROR_GENERAL,
|
UP_DAEMON_ERROR_GENERAL,
|
||||||
"No kernel support");
|
"No kernel support");
|
||||||
|
|
@ -508,7 +517,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enough swap? */
|
/* enough swap? */
|
||||||
if (!daemon->priv->hibernate_has_swap_space) {
|
if (!priv->hibernate_has_swap_space) {
|
||||||
error = g_error_new (UP_DAEMON_ERROR,
|
error = g_error_new (UP_DAEMON_ERROR,
|
||||||
UP_DAEMON_ERROR_GENERAL,
|
UP_DAEMON_ERROR_GENERAL,
|
||||||
"Not enough swap space");
|
"Not enough swap space");
|
||||||
|
|
@ -516,24 +525,25 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* encrypted swap? */
|
/* encrypted swap and no override? */
|
||||||
if (daemon->priv->hibernate_has_encrypted_swap) {
|
if (priv->hibernate_has_encrypted_swap &&
|
||||||
|
!priv->conf_allow_hibernate_encrypted_swap) {
|
||||||
error = g_error_new (UP_DAEMON_ERROR,
|
error = g_error_new (UP_DAEMON_ERROR,
|
||||||
UP_DAEMON_ERROR_GENERAL,
|
UP_DAEMON_ERROR_GENERAL,
|
||||||
"Swap space is encrypted");
|
"Swap space is encrypted, use AllowHibernateEncryptedSwap to override");
|
||||||
dbus_g_method_return_error (context, error);
|
dbus_g_method_return_error (context, error);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
subject = up_polkit_get_subject (daemon->priv->polkit, context);
|
subject = up_polkit_get_subject (priv->polkit, context);
|
||||||
if (subject == NULL)
|
if (subject == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!up_polkit_check_auth (daemon->priv->polkit, subject, "org.freedesktop.upower.hibernate", context))
|
if (!up_polkit_check_auth (priv->polkit, subject, "org.freedesktop.upower.hibernate", context))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* already requested */
|
/* already requested */
|
||||||
if (daemon->priv->about_to_sleep_id != 0) {
|
if (priv->about_to_sleep_id != 0) {
|
||||||
error = g_error_new (UP_DAEMON_ERROR,
|
error = g_error_new (UP_DAEMON_ERROR,
|
||||||
UP_DAEMON_ERROR_GENERAL,
|
UP_DAEMON_ERROR_GENERAL,
|
||||||
"Sleep has already been requested and is pending");
|
"Sleep has already been requested and is pending");
|
||||||
|
|
@ -542,7 +552,7 @@ up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* do this deferred action */
|
/* do this deferred action */
|
||||||
command = up_backend_get_hibernate_command (daemon->priv->backend);
|
command = up_backend_get_hibernate_command (priv->backend);
|
||||||
up_daemon_deferred_sleep (daemon, command, context);
|
up_daemon_deferred_sleep (daemon, command, context);
|
||||||
out:
|
out:
|
||||||
if (subject != NULL)
|
if (subject != NULL)
|
||||||
|
|
@ -558,12 +568,13 @@ up_daemon_hibernate_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
PolkitSubject *subject = NULL;
|
PolkitSubject *subject = NULL;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
subject = up_polkit_get_subject (daemon->priv->polkit, context);
|
subject = up_polkit_get_subject (priv->polkit, context);
|
||||||
if (subject == NULL)
|
if (subject == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = up_polkit_is_allowed (daemon->priv->polkit, subject, "org.freedesktop.upower.hibernate", context);
|
ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.hibernate", context);
|
||||||
dbus_g_method_return (context, ret);
|
dbus_g_method_return (context, ret);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
@ -580,9 +591,10 @@ up_daemon_register_power_daemon (UpDaemon *daemon)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
daemon->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
|
priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
|
||||||
if (daemon->priv->connection == NULL) {
|
if (priv->connection == NULL) {
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
g_critical ("error getting system bus: %s", error->message);
|
g_critical ("error getting system bus: %s", error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
|
|
@ -591,13 +603,13 @@ up_daemon_register_power_daemon (UpDaemon *daemon)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* connect to DBUS */
|
/* connect to DBUS */
|
||||||
daemon->priv->proxy = dbus_g_proxy_new_for_name (daemon->priv->connection,
|
priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
|
||||||
DBUS_SERVICE_DBUS,
|
DBUS_SERVICE_DBUS,
|
||||||
DBUS_PATH_DBUS,
|
DBUS_PATH_DBUS,
|
||||||
DBUS_INTERFACE_DBUS);
|
DBUS_INTERFACE_DBUS);
|
||||||
|
|
||||||
/* register GObject */
|
/* register GObject */
|
||||||
dbus_g_connection_register_g_object (daemon->priv->connection,
|
dbus_g_connection_register_g_object (priv->connection,
|
||||||
"/org/freedesktop/UPower",
|
"/org/freedesktop/UPower",
|
||||||
G_OBJECT (daemon));
|
G_OBJECT (daemon));
|
||||||
|
|
||||||
|
|
@ -616,6 +628,7 @@ up_daemon_startup (UpDaemon *daemon)
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
gboolean on_battery;
|
gboolean on_battery;
|
||||||
gboolean on_low_battery;
|
gboolean on_low_battery;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
/* register on bus */
|
/* register on bus */
|
||||||
ret = up_daemon_register_power_daemon (daemon);
|
ret = up_daemon_register_power_daemon (daemon);
|
||||||
|
|
@ -627,10 +640,10 @@ up_daemon_startup (UpDaemon *daemon)
|
||||||
/* stop signals and callbacks */
|
/* stop signals and callbacks */
|
||||||
egg_debug ("daemon now coldplug");
|
egg_debug ("daemon now coldplug");
|
||||||
g_object_freeze_notify (G_OBJECT(daemon));
|
g_object_freeze_notify (G_OBJECT(daemon));
|
||||||
daemon->priv->during_coldplug = TRUE;
|
priv->during_coldplug = TRUE;
|
||||||
|
|
||||||
/* coldplug backend backend */
|
/* coldplug backend backend */
|
||||||
ret = up_backend_coldplug (daemon->priv->backend, daemon);
|
ret = up_backend_coldplug (priv->backend, daemon);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
egg_warning ("failed to coldplug backend");
|
egg_warning ("failed to coldplug backend");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -647,11 +660,11 @@ up_daemon_startup (UpDaemon *daemon)
|
||||||
|
|
||||||
/* start signals and callbacks */
|
/* start signals and callbacks */
|
||||||
g_object_thaw_notify (G_OBJECT(daemon));
|
g_object_thaw_notify (G_OBJECT(daemon));
|
||||||
daemon->priv->during_coldplug = FALSE;
|
priv->during_coldplug = FALSE;
|
||||||
egg_debug ("daemon now not coldplug");
|
egg_debug ("daemon now not coldplug");
|
||||||
|
|
||||||
/* set pm-utils power policy */
|
/* set pm-utils power policy */
|
||||||
up_daemon_set_pmutils_powersave (daemon, daemon->priv->on_battery);
|
up_daemon_set_pmutils_powersave (daemon, priv->on_battery);
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -671,13 +684,15 @@ up_daemon_get_device_list (UpDaemon *daemon)
|
||||||
static gboolean
|
static gboolean
|
||||||
up_daemon_refresh_battery_devices_cb (UpDaemon *daemon)
|
up_daemon_refresh_battery_devices_cb (UpDaemon *daemon)
|
||||||
{
|
{
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
/* no more left to do? */
|
/* no more left to do? */
|
||||||
if (daemon->priv->battery_poll_count-- == 0) {
|
if (priv->battery_poll_count-- == 0) {
|
||||||
daemon->priv->battery_poll_id = 0;
|
priv->battery_poll_id = 0;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
egg_debug ("doing the delayed refresh (%i)", daemon->priv->battery_poll_count);
|
egg_debug ("doing the delayed refresh (%i)", priv->battery_poll_count);
|
||||||
up_daemon_refresh_battery_devices (daemon);
|
up_daemon_refresh_battery_devices (daemon);
|
||||||
|
|
||||||
/* keep going until none left to do */
|
/* keep going until none left to do */
|
||||||
|
|
@ -690,12 +705,14 @@ up_daemon_refresh_battery_devices_cb (UpDaemon *daemon)
|
||||||
static void
|
static void
|
||||||
up_daemon_poll_battery_devices_for_a_little_bit (UpDaemon *daemon)
|
up_daemon_poll_battery_devices_for_a_little_bit (UpDaemon *daemon)
|
||||||
{
|
{
|
||||||
daemon->priv->battery_poll_count = UP_DAEMON_POLL_BATTERY_NUMBER_TIMES;
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
|
priv->battery_poll_count = UP_DAEMON_POLL_BATTERY_NUMBER_TIMES;
|
||||||
|
|
||||||
/* already polling */
|
/* already polling */
|
||||||
if (daemon->priv->battery_poll_id != 0)
|
if (priv->battery_poll_id != 0)
|
||||||
return;
|
return;
|
||||||
daemon->priv->battery_poll_id =
|
priv->battery_poll_id =
|
||||||
g_timeout_add_seconds (UP_DAEMON_ON_BATTERY_REFRESH_DEVICES_DELAY,
|
g_timeout_add_seconds (UP_DAEMON_ON_BATTERY_REFRESH_DEVICES_DELAY,
|
||||||
(GSourceFunc) up_daemon_refresh_battery_devices_cb, daemon);
|
(GSourceFunc) up_daemon_refresh_battery_devices_cb, daemon);
|
||||||
}
|
}
|
||||||
|
|
@ -709,6 +726,7 @@ up_daemon_device_changed_cb (UpDevice *device, UpDaemon *daemon)
|
||||||
const gchar *object_path;
|
const gchar *object_path;
|
||||||
UpDeviceKind type;
|
UpDeviceKind type;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
g_return_if_fail (UP_IS_DAEMON (daemon));
|
g_return_if_fail (UP_IS_DAEMON (daemon));
|
||||||
g_return_if_fail (UP_IS_DEVICE (device));
|
g_return_if_fail (UP_IS_DEVICE (device));
|
||||||
|
|
@ -725,19 +743,19 @@ up_daemon_device_changed_cb (UpDevice *device, UpDaemon *daemon)
|
||||||
|
|
||||||
/* second, check if the on_battery and on_low_battery state has changed */
|
/* second, check if the on_battery and on_low_battery state has changed */
|
||||||
ret = (up_daemon_get_on_battery_local (daemon) && !up_daemon_get_on_ac_local (daemon));
|
ret = (up_daemon_get_on_battery_local (daemon) && !up_daemon_get_on_ac_local (daemon));
|
||||||
if (ret != daemon->priv->on_battery) {
|
if (ret != priv->on_battery) {
|
||||||
g_object_set (daemon, "on-battery", ret, NULL);
|
g_object_set (daemon, "on-battery", ret, NULL);
|
||||||
|
|
||||||
/* set pm-utils power policy */
|
/* set pm-utils power policy */
|
||||||
up_daemon_set_pmutils_powersave (daemon, ret);
|
up_daemon_set_pmutils_powersave (daemon, ret);
|
||||||
}
|
}
|
||||||
ret = up_daemon_get_on_low_battery_local (daemon);
|
ret = up_daemon_get_on_low_battery_local (daemon);
|
||||||
if (ret != daemon->priv->on_low_battery) {
|
if (ret != priv->on_low_battery) {
|
||||||
g_object_set (daemon, "on-low-battery", ret, NULL);
|
g_object_set (daemon, "on-low-battery", ret, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* emit */
|
/* emit */
|
||||||
if (!daemon->priv->during_coldplug) {
|
if (!priv->during_coldplug) {
|
||||||
object_path = up_device_get_object_path (device);
|
object_path = up_device_get_object_path (device);
|
||||||
egg_debug ("emitting device-changed: %s", object_path);
|
egg_debug ("emitting device-changed: %s", object_path);
|
||||||
|
|
||||||
|
|
@ -758,13 +776,14 @@ up_daemon_device_added_cb (UpBackend *backend, GObject *native, UpDevice *device
|
||||||
{
|
{
|
||||||
UpDeviceKind type;
|
UpDeviceKind type;
|
||||||
const gchar *object_path;
|
const gchar *object_path;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
g_return_if_fail (UP_IS_DAEMON (daemon));
|
g_return_if_fail (UP_IS_DAEMON (daemon));
|
||||||
g_return_if_fail (UP_IS_DEVICE (device));
|
g_return_if_fail (UP_IS_DEVICE (device));
|
||||||
g_return_if_fail (G_IS_OBJECT (native));
|
g_return_if_fail (G_IS_OBJECT (native));
|
||||||
|
|
||||||
/* add to device list */
|
/* add to device list */
|
||||||
up_device_list_insert (daemon->priv->power_devices, native, G_OBJECT (device));
|
up_device_list_insert (priv->power_devices, native, G_OBJECT (device));
|
||||||
|
|
||||||
/* connect, so we get changes */
|
/* connect, so we get changes */
|
||||||
g_signal_connect (device, "changed",
|
g_signal_connect (device, "changed",
|
||||||
|
|
@ -778,9 +797,9 @@ up_daemon_device_added_cb (UpBackend *backend, GObject *native, UpDevice *device
|
||||||
up_daemon_poll_battery_devices_for_a_little_bit (daemon);
|
up_daemon_poll_battery_devices_for_a_little_bit (daemon);
|
||||||
|
|
||||||
/* emit */
|
/* emit */
|
||||||
if (!daemon->priv->during_coldplug) {
|
if (!priv->during_coldplug) {
|
||||||
object_path = up_device_get_object_path (device);
|
object_path = up_device_get_object_path (device);
|
||||||
egg_debug ("emitting added: %s (during coldplug %i)", object_path, daemon->priv->during_coldplug);
|
egg_debug ("emitting added: %s (during coldplug %i)", object_path, priv->during_coldplug);
|
||||||
|
|
||||||
/* don't crash the session */
|
/* don't crash the session */
|
||||||
if (object_path == NULL) {
|
if (object_path == NULL) {
|
||||||
|
|
@ -799,13 +818,14 @@ up_daemon_device_removed_cb (UpBackend *backend, GObject *native, UpDevice *devi
|
||||||
{
|
{
|
||||||
UpDeviceKind type;
|
UpDeviceKind type;
|
||||||
const gchar *object_path;
|
const gchar *object_path;
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
g_return_if_fail (UP_IS_DAEMON (daemon));
|
g_return_if_fail (UP_IS_DAEMON (daemon));
|
||||||
g_return_if_fail (UP_IS_DEVICE (device));
|
g_return_if_fail (UP_IS_DEVICE (device));
|
||||||
g_return_if_fail (G_IS_OBJECT (native));
|
g_return_if_fail (G_IS_OBJECT (native));
|
||||||
|
|
||||||
/* remove from list */
|
/* remove from list */
|
||||||
up_device_list_remove (daemon->priv->power_devices, G_OBJECT(device));
|
up_device_list_remove (priv->power_devices, G_OBJECT(device));
|
||||||
|
|
||||||
/* refresh after a short delay */
|
/* refresh after a short delay */
|
||||||
g_object_get (device,
|
g_object_get (device,
|
||||||
|
|
@ -815,7 +835,7 @@ up_daemon_device_removed_cb (UpBackend *backend, GObject *native, UpDevice *devi
|
||||||
up_daemon_poll_battery_devices_for_a_little_bit (daemon);
|
up_daemon_poll_battery_devices_for_a_little_bit (daemon);
|
||||||
|
|
||||||
/* emit */
|
/* emit */
|
||||||
if (!daemon->priv->during_coldplug) {
|
if (!priv->during_coldplug) {
|
||||||
object_path = up_device_get_object_path (device);
|
object_path = up_device_get_object_path (device);
|
||||||
egg_debug ("emitting device-removed: %s", object_path);
|
egg_debug ("emitting device-removed: %s", object_path);
|
||||||
|
|
||||||
|
|
@ -853,6 +873,9 @@ static void
|
||||||
up_daemon_init (UpDaemon *daemon)
|
up_daemon_init (UpDaemon *daemon)
|
||||||
{
|
{
|
||||||
gfloat waterline;
|
gfloat waterline;
|
||||||
|
gboolean ret;
|
||||||
|
GError *error = NULL;
|
||||||
|
GKeyFile *file;
|
||||||
|
|
||||||
daemon->priv = UP_DAEMON_GET_PRIVATE (daemon);
|
daemon->priv = UP_DAEMON_GET_PRIVATE (daemon);
|
||||||
daemon->priv->polkit = up_polkit_new ();
|
daemon->priv->polkit = up_polkit_new ();
|
||||||
|
|
@ -869,6 +892,22 @@ up_daemon_init (UpDaemon *daemon)
|
||||||
daemon->priv->battery_poll_id = 0;
|
daemon->priv->battery_poll_id = 0;
|
||||||
daemon->priv->battery_poll_count = 0;
|
daemon->priv->battery_poll_count = 0;
|
||||||
daemon->priv->about_to_sleep_id = 0;
|
daemon->priv->about_to_sleep_id = 0;
|
||||||
|
daemon->priv->conf_sleep_timeout = 1000;
|
||||||
|
daemon->priv->conf_allow_hibernate_encrypted_swap = FALSE;
|
||||||
|
|
||||||
|
/* load some values from the config file */
|
||||||
|
file = g_key_file_new ();
|
||||||
|
ret = g_key_file_load_from_file (file, PACKAGE_SYSCONF_DIR "/UPower/UPower.conf", G_KEY_FILE_NONE, &error);
|
||||||
|
if (ret) {
|
||||||
|
daemon->priv->conf_sleep_timeout =
|
||||||
|
g_key_file_get_integer (file, "UPower", "SleepTimeout", NULL);
|
||||||
|
daemon->priv->conf_allow_hibernate_encrypted_swap =
|
||||||
|
g_key_file_get_boolean (file, "UPower", "AllowHibernateEncryptedSwap", NULL);
|
||||||
|
} else {
|
||||||
|
egg_warning ("failed to load config file: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
}
|
||||||
|
g_key_file_free (file);
|
||||||
|
|
||||||
daemon->priv->backend = up_backend_new ();
|
daemon->priv->backend = up_backend_new ();
|
||||||
g_signal_connect (daemon->priv->backend, "device-added",
|
g_signal_connect (daemon->priv->backend, "device-added",
|
||||||
|
|
@ -948,31 +987,33 @@ up_daemon_error_get_type (void)
|
||||||
static void
|
static void
|
||||||
up_daemon_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
up_daemon_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
UpDaemon *daemon;
|
UpDaemon *daemon = UP_DAEMON (object);
|
||||||
daemon = UP_DAEMON (object);
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_DAEMON_VERSION:
|
case PROP_DAEMON_VERSION:
|
||||||
g_value_set_string (value, PACKAGE_VERSION);
|
g_value_set_string (value, PACKAGE_VERSION);
|
||||||
break;
|
break;
|
||||||
case PROP_CAN_SUSPEND:
|
case PROP_CAN_SUSPEND:
|
||||||
g_value_set_boolean (value, daemon->priv->kernel_can_suspend);
|
g_value_set_boolean (value, priv->kernel_can_suspend);
|
||||||
break;
|
break;
|
||||||
case PROP_CAN_HIBERNATE:
|
case PROP_CAN_HIBERNATE:
|
||||||
g_value_set_boolean (value, (daemon->priv->kernel_can_hibernate &&
|
g_value_set_boolean (value, (priv->kernel_can_hibernate &&
|
||||||
daemon->priv->hibernate_has_swap_space &&
|
priv->hibernate_has_swap_space &&
|
||||||
!daemon->priv->hibernate_has_encrypted_swap));
|
(!priv->hibernate_has_encrypted_swap ||
|
||||||
|
priv->conf_allow_hibernate_encrypted_swap)));
|
||||||
break;
|
break;
|
||||||
case PROP_ON_BATTERY:
|
case PROP_ON_BATTERY:
|
||||||
g_value_set_boolean (value, daemon->priv->on_battery);
|
g_value_set_boolean (value, priv->on_battery);
|
||||||
break;
|
break;
|
||||||
case PROP_ON_LOW_BATTERY:
|
case PROP_ON_LOW_BATTERY:
|
||||||
g_value_set_boolean (value, daemon->priv->on_battery && daemon->priv->on_low_battery);
|
g_value_set_boolean (value, priv->on_battery && priv->on_low_battery);
|
||||||
break;
|
break;
|
||||||
case PROP_LID_IS_CLOSED:
|
case PROP_LID_IS_CLOSED:
|
||||||
g_value_set_boolean (value, daemon->priv->lid_is_closed);
|
g_value_set_boolean (value, priv->lid_is_closed);
|
||||||
break;
|
break;
|
||||||
case PROP_LID_IS_PRESENT:
|
case PROP_LID_IS_PRESENT:
|
||||||
g_value_set_boolean (value, daemon->priv->lid_is_present);
|
g_value_set_boolean (value, priv->lid_is_present);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
|
@ -987,22 +1028,23 @@ static void
|
||||||
up_daemon_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
up_daemon_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
UpDaemon *daemon = UP_DAEMON (object);
|
UpDaemon *daemon = UP_DAEMON (object);
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_LID_IS_CLOSED:
|
case PROP_LID_IS_CLOSED:
|
||||||
daemon->priv->lid_is_closed = g_value_get_boolean (value);
|
priv->lid_is_closed = g_value_get_boolean (value);
|
||||||
egg_debug ("now lid_is_closed = %s", daemon->priv->lid_is_closed ? "yes" : "no");
|
egg_debug ("now lid_is_closed = %s", priv->lid_is_closed ? "yes" : "no");
|
||||||
break;
|
break;
|
||||||
case PROP_LID_IS_PRESENT:
|
case PROP_LID_IS_PRESENT:
|
||||||
daemon->priv->lid_is_present = g_value_get_boolean (value);
|
priv->lid_is_present = g_value_get_boolean (value);
|
||||||
egg_debug ("now lid_is_present = %s", daemon->priv->lid_is_present ? "yes" : "no");
|
egg_debug ("now lid_is_present = %s", priv->lid_is_present ? "yes" : "no");
|
||||||
break;
|
break;
|
||||||
case PROP_ON_BATTERY:
|
case PROP_ON_BATTERY:
|
||||||
daemon->priv->on_battery = g_value_get_boolean (value);
|
priv->on_battery = g_value_get_boolean (value);
|
||||||
egg_debug ("now on_battery = %s", daemon->priv->on_battery ? "yes" : "no");
|
egg_debug ("now on_battery = %s", priv->on_battery ? "yes" : "no");
|
||||||
break;
|
break;
|
||||||
case PROP_ON_LOW_BATTERY:
|
case PROP_ON_LOW_BATTERY:
|
||||||
daemon->priv->on_low_battery = g_value_get_boolean (value);
|
priv->on_low_battery = g_value_get_boolean (value);
|
||||||
egg_debug ("now on_low_battery = %s", daemon->priv->on_low_battery ? "yes" : "no");
|
egg_debug ("now on_low_battery = %s", priv->on_low_battery ? "yes" : "no");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
|
@ -1138,26 +1180,20 @@ up_daemon_class_init (UpDaemonClass *klass)
|
||||||
static void
|
static void
|
||||||
up_daemon_finalize (GObject *object)
|
up_daemon_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
UpDaemon *daemon;
|
UpDaemon *daemon = UP_DAEMON (object);
|
||||||
|
UpDaemonPrivate *priv = daemon->priv;
|
||||||
|
|
||||||
g_return_if_fail (object != NULL);
|
if (priv->battery_poll_id != 0)
|
||||||
g_return_if_fail (UP_IS_DAEMON (object));
|
g_source_remove (priv->battery_poll_id);
|
||||||
|
|
||||||
daemon = UP_DAEMON (object);
|
if (priv->proxy != NULL)
|
||||||
|
g_object_unref (priv->proxy);
|
||||||
g_return_if_fail (daemon->priv != NULL);
|
if (priv->connection != NULL)
|
||||||
|
dbus_g_connection_unref (priv->connection);
|
||||||
if (daemon->priv->battery_poll_id != 0)
|
g_object_unref (priv->power_devices);
|
||||||
g_source_remove (daemon->priv->battery_poll_id);
|
g_object_unref (priv->polkit);
|
||||||
|
g_object_unref (priv->backend);
|
||||||
if (daemon->priv->proxy != NULL)
|
g_timer_destroy (priv->about_to_sleep_timer);
|
||||||
g_object_unref (daemon->priv->proxy);
|
|
||||||
if (daemon->priv->connection != NULL)
|
|
||||||
dbus_g_connection_unref (daemon->priv->connection);
|
|
||||||
g_object_unref (daemon->priv->power_devices);
|
|
||||||
g_object_unref (daemon->priv->polkit);
|
|
||||||
g_object_unref (daemon->priv->backend);
|
|
||||||
g_timer_destroy (daemon->priv->about_to_sleep_timer);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (up_daemon_parent_class)->finalize (object);
|
G_OBJECT_CLASS (up_daemon_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue