GNOME Bugzilla – Bug 597030
support automatic logout after a maximum period of idleness
Last modified: 2013-01-25 15:44:47 UTC
Something I've wanted to do for a while is support automatic logout after a maximum period of idleness. Since the session and xorg are responsible for detecting idleness in the first place there really isn't much point in putting the max-idle enforcement mechanism outside the session. If the user really wants to get around the restriction they can send virtual keystrokes to xorg every second or two - or worse... So, a simple approach is to just start counting after the session goes idle, show a warning (or set of warnings) before the action, and then use the same logout path we use on a forced logout. If the logout gets stuck at any point during a forced logout that should be considered a bug and doesn't follow the gnome session spec. In the case where the screen isn't locked we should show some warnings - perhaps in the form of notification bubbles - that the session is about to end. If the screen is locked then the screensaver needs to show these same messages. When the screen is not locked, any user input should reset the idle counter and mark the user as availble- and not logout. If the screen is locked we require the user to unlock the screen (authenticate) in order to be authorized to reset the idle state and cancel the impending logout. Since logout is not the only possible action that may occur after a maximum-idle-time we should allow for adding these in the future. One can imagine doing a "disconnect" in the case of a terminal server for example. Since there may be logout inhibitors in place. We should probably have separate actions for a logout that honors them and that doesn't. Perhaps, "logout" and "forced-logout". For similar reasons, we may also want to have a gconf key that ignores idle inhibitors. However, as pointed out above this isn't really something that can force the user since passive presence detection is pretty weak - but it may be valuable if there are badly behaving applications. We should consider if it would make sense to have a "suspend" action or similar. A related but separate feature would be to add a maximum-login-time property that would force logouts after a certain time after login. Perhaps useful for timed kiosks.
What's the motivation here? Fast user switching? My friend comes in logs into the guest account, opens 30 firefox tabs, then I fast user switch back and his websites stay open eating lots of resources? I understand the kiosk case. But for the mobile case I'd *far* prefer suspend-by-default (or the status quo) at least in the single user case.
Very commonly requested anywhere that has shared resources: servers, labs, etc. Would not be enabled by default.
Created attachment 144599 [details] [review] patch
Ok, makes sense to me =)
Patch works fine in my testing.
Created attachment 146014 [details] [review] updated patch
Review of attachment 146014 [details] [review]: Looks good to me otherwise. ::: configure.in @@ +56,3 @@ devkit-power-gobject >= $DEVKIT_POWER_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED + libnotify >= $LIBNOTIFY_REQUIRED Hmm, not really happy with adding a dependency on libnotify. Well, it's a blessed dep on GNOME so maybe it's ok. ::: gnome-session/gsm-manager.c @@ +71,3 @@ +#define GS_INTERFACE "org.gnome.ScreenSaver" +#define GS_PATH "/org/gnome/ScreenSaver" +#define GS_NAME "org.gnome.ScreenSaver" The "GS" prefix doesn't say much here. Maybe "SCREENSAVER_" or something more explicit instead? @@ +174,3 @@ + ACTION_LOGOUT, + ACTION_NONE = 0, +typedef enum { Should probably be MaxIdleAction. And MAX_IDLE_ACTION_NONE, MAX_IDLE_ACTION_LOGOUT, MAX_IDLE_ACTION_FORCED_LOGOUT. For clarity reasons. @@ +2443,3 @@ + manager->priv->max_idle_warning_timeout_id = 0; + } + Destroy/close notification here? @@ +2524,3 @@ + char *summary; + char *body; + char *remaining; Align variables following the coding style of the rest of this file. @@ +2573,3 @@ + NULL); + } else { + manager->priv->max_idle_notification move '=' to end of previous line. @@ +2627,3 @@ + warn_secs = 0.05 * manager->priv->max_idle_time_secs; + manager->priv->max_idle_warning_timeout_id + = g_timeout_add_seconds (warn_secs, move the '=' to the end of previous line. @@ +2644,3 @@ + warn_secs = 0.1 * manager->priv->max_idle_time_secs; + manager->priv->max_idle_warning_timeout_id + = g_timeout_add_seconds (warn_secs, move the '=' to the end of previous line. @@ +2656,3 @@ + +static void +reset_max_idle_timer (GsmManager *manager) Maybe a better same for this function would be "maybe_reset_max_idle_timer". @@ +2662,3 @@ + g_object_get (manager->priv->presence, "status", &status, NULL); + + Remove this extra blank line. @@ +2683,3 @@ + + manager->priv->max_idle_timeout_id + = g_timeout_add_seconds (manager->priv->max_idle_time_secs, move the '=' to the end of previous line. @@ +2690,3 @@ + warn_secs = 0.8 * manager->priv->max_idle_time_secs; + manager->priv->max_idle_warning_timeout_id + = g_timeout_add_seconds (warn_secs, move the '=' to the end of previous line. @@ +2746,3 @@ + manager->priv->max_idle_action = ACTION_NONE; + } + reset_max_idle_timer (manager); It's a bit strange that changing the action resets the timer. Any specific reasons for doing it?
Review of attachment 146014 [details] [review]: Looks good to me otherwise. ::: configure.in @@ +56,3 @@ devkit-power-gobject >= $DEVKIT_POWER_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED + libnotify >= $LIBNOTIFY_REQUIRED Hmm, not really happy with adding a dependency on libnotify. Well, it's a blessed dep on GNOME so maybe it's ok. ::: gnome-session/gsm-manager.c @@ +71,3 @@ +#define GS_INTERFACE "org.gnome.ScreenSaver" +#define GS_PATH "/org/gnome/ScreenSaver" +#define GS_NAME "org.gnome.ScreenSaver" The "GS" prefix doesn't say much here. Maybe "SCREENSAVER_" or something more explicit instead? @@ +174,3 @@ + ACTION_LOGOUT, + ACTION_NONE = 0, +typedef enum { Should probably be MaxIdleAction. And MAX_IDLE_ACTION_NONE, MAX_IDLE_ACTION_LOGOUT, MAX_IDLE_ACTION_FORCED_LOGOUT. For clarity reasons. @@ +2443,3 @@ + manager->priv->max_idle_warning_timeout_id = 0; + } + Destroy/close notification here? @@ +2524,3 @@ + char *summary; + char *body; + char *remaining; Align variables following the coding style of the rest of this file. @@ +2573,3 @@ + NULL); + } else { + manager->priv->max_idle_notification move '=' to end of previous line. @@ +2627,3 @@ + warn_secs = 0.05 * manager->priv->max_idle_time_secs; + manager->priv->max_idle_warning_timeout_id + = g_timeout_add_seconds (warn_secs, move the '=' to the end of previous line. @@ +2644,3 @@ + warn_secs = 0.1 * manager->priv->max_idle_time_secs; + manager->priv->max_idle_warning_timeout_id + = g_timeout_add_seconds (warn_secs, move the '=' to the end of previous line. @@ +2656,3 @@ + +static void +reset_max_idle_timer (GsmManager *manager) Maybe a better same for this function would be "maybe_reset_max_idle_timer". @@ +2662,3 @@ + g_object_get (manager->priv->presence, "status", &status, NULL); + + Remove this extra blank line. @@ +2683,3 @@ + + manager->priv->max_idle_timeout_id + = g_timeout_add_seconds (manager->priv->max_idle_time_secs, move the '=' to the end of previous line. @@ +2690,3 @@ + warn_secs = 0.8 * manager->priv->max_idle_time_secs; + manager->priv->max_idle_warning_timeout_id + = g_timeout_add_seconds (warn_secs, move the '=' to the end of previous line. @@ +2746,3 @@ + } + reset_max_idle_timer (manager); + } else if (strcmp (key, KEY_MAX_IDLE_TIME) == 0) { It's a bit strange that changing the action resets the timer. Any specific reasons for doing it?
Created attachment 173699 [details] [review] updated patch Here is an update of the patch that works with libnotify 0.7
How about getting this landed for 3.2 ?
Hi there, I've written something that does this and have spoken to gnome devs about it before. It's probably much more than the gnome devs want, because it is targeted specifically for large computer labs, and sysadmins, but have a look if you're interested. The project is called "evanescent" and the code is available here: http://cs.mcgill.ca/~james/code/ Note: this is my old website, new website is: https://ttboj.wordpress.com/ Hope this is useful to you, if anything you might get some design ideas, and I have experience implementing this in a 300?+ computer setup. James
Created attachment 231311 [details] [review] Support automatic logout after a maximum period of idleness This is very commonly requested in any situation with shared resources: servers, labs, etc. We simply start counting down once the session goes idle, and display a warning notification when we get close to the maximum allowed idle time. The feature is controlled by two new org.gnome.SessionManager settings: max-idle-time and max-idle-action. The time is specified in minutes, and the action can be 'none', 'logout' or 'force-logout', with 'none' being the default. This commit adds a libnotify dependency. http://bugzilla.gnome.org/show_bug.cgi?id=597030
Review of attachment 231311 [details] [review]: The code looks OK. Matthias and I had a quick in person chat about this patch. My concern was mainly about potential for bad interaction with the lockscreen - for example, at the moment we pop up the end session dialog on top, which is suboptimal at least. Using libnotify - OK for now, the longer term solution is likely that this functionality is integrated into the shell (e.g. the lockscreen dialog knows how to show "you are about to be logged out" on its own).
Attachment 231311 [details] pushed as 7d0e8ae - Support automatic logout after a maximum period of idleness
Why do we do that in gnome-session? We already have a mechanism for handling "what to do" on idle in gnome-settings-daemon's power plugin. Adding support for closing the session would have meant: - adding a new enum member (or 2) to org.gnome.settings-daemon.GsdPowerActionType - adding support for calling out to gnome-session when sleep-inactive-ac-type or sleep-inactive-battery-type is hit. It means we don't need yet another idle in a separate code path.
Created attachment 231462 [details] [review] power: Support automatic logout after a maximum period of idleness This is very commonly requested in any situation with shared resources: servers, labs, etc. We simply show the log out dialog once the session goes idle. The feature is controlled by the sleep-inactive-*-timeout and sleep-inactive-*-type keys. http://bugzilla.gnome.org/show_bug.cgi?id=597030
Review of attachment 231462 [details] [review]: makes sense to me. We should revert the other bit and use this instead. ::: plugins/power/gsd-power-manager.c @@ +2039,3 @@ +gnome_session_logout_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) you don't line up arguments here, but do in gnome_session_logout @@ +2158,3 @@ + break; + case GSD_POWER_ACTION_FORCE_LOGOUT: + gnome_session_logout (manager, 2); might be better to have #defines for the logout mode
Note that it's completely untested, and doesn't have any of the nice GUI features that Matthias added to his version. The "we're about to logout" is implemented through the logout dialog that will countdown from 60 seconds.
I guess ideally we'd have some information in the dialog saying when it popped up. Though, thinking about this more. We generally don't like showing modal dialogs out of the blue, so just popping up the logout dialog might not be great idea. Not sure libnotify is awesome either. maybe we need a slow fade like screensaver has.
I've encountered the original code again, and I'm not sure it works as expected: in on_presence_status_changed(): system = gsm_get_system (); gsm_system_set_session_idle (system, (status == GSM_PRESENCE_STATUS_IDLE)); g_object_unref (system); reset_max_idle_timer (manager); Looks like the timer is reset when we go *to* idle, so a 5 minutes idle-delay with a 10 minutes max-idle actually turns into a 15 minutes max-idle. Can we get some comments on the "UI" (or lack thereof) of the gnome-settings-daemon implementation? Should we add similar warning notifications to gnome-settings-daemon? (which would allow us to enable automatic suspend on idle, maybe).
(In reply to comment #18) > Note that it's completely untested, and doesn't have any of the nice GUI > features that Matthias added to his version. The UI is certainly an important part of this - lets not drop it on the floor.
Created attachment 234181 [details] [review] Revert "Support automatic logout after a maximum period of idleness" This reverts commit 7d0e8aed1590eaa8caa7666a388eadb8182ac244. The functionality should be implemented in gnome-settings-daemon instead, using the already present "sleep-inactive-*-timeout" as the max idle value, with GSD_POWER_ACTION_INTERACTIVE as the "sleep-inactive-*-type". Notification is still missing compared to the gnome-session feature. http://bugzilla.gnome.org/show_bug.cgi?id=597030
Comment on attachment 234181 [details] [review] Revert "Support automatic logout after a maximum period of idleness" Attachment 234181 [details] pushed as ddd49c7 - Revert "Support automatic logout after a maximum period of idleness"
Created attachment 234286 [details] [review] power: Support automatic logout after a maximum period of idleness This is very commonly requested in any situation with shared resources: servers, labs, etc. We either log out, or force the logout when the maximum idle time has been detected. The feature is controlled by the sleep-inactive-*-timeout and sleep-inactive-*-type keys. http://bugzilla.gnome.org/show_bug.cgi?id=597030
Created attachment 234417 [details] [review] power: Support automatic logout after a maximum period of idleness This is very commonly requested in any situation with shared resources: servers, labs, etc. We either log out, or force the logout when the maximum idle time has been detected. The feature is controlled by the sleep-inactive-*-timeout and sleep-inactive-*-type keys. http://bugzilla.gnome.org/show_bug.cgi?id=597030
Created attachment 234418 [details] [review] power: Add tests for the logout on idle feature
Attachment 234417 [details] pushed as 5edebf4 - power: Support automatic logout after a maximum period of idleness