! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Use the screensaver dbus api for 'lock' calls
Status:
RESOLVED: FIXED
Severity:
enhancement
Product:
Xfce4-power-manager
Component:
General

Comments

Description Eric Koegel editbugs 2016-05-27 15:05:05 CEST
Created attachment 6681 
Handle screensaver activity with it's own class

So I had this idea to make screensaver support with xfpm and xfsm a bit easier and standardized. Since most of the big screensaver daemons (kde, gnome, mate, cinnamon, lightlocker, etc) expose a dbus interface I now have xfpm try to use it for locking in addition to inhibit.

  If the screensaver doesn't have a dbus interface, things will continue to work via the heartbeat-command (for inhibit support) and the LockCommand (for locking) the same as things currently work.

  Now if you run xscreensaver for example and didn't set the heartbeat or lock commands, you won't get the inhibit support, but it will try to launch xdg-screensaver, then xflock4, and finally it will attempt to call xscreensaver so things still work.
Comment 1 Eric Koegel editbugs 2016-05-31 07:58:34 CEST
Pushed to master in:
commit 9e70d2e4aa8b9287a4d06d35010a01ba3bebd857
Author: Eric Koegel <eric.koegel@gmail.com>
Date:   Fri May 27 15:45:13 2016 +0300

    Handle screensaver activity with it's own class (Bug #12603)
    
    Move the screensaver inhibit, heartbeat, and lock code to its own
    set of files we can easily share with xfce4-session. Use the
    screensaver's dbus API if it supports it for inhibit and lock
    calls. Otherwise, use the heartbeat-command and LockCommand
    from xfpm and xfsm if available. Finally, for the lock function,
    fallback to trying xdg-screensaver, xflock4, and xscreensaver-command
    in that order.
http://git.xfce.org/xfce/xfce4-power-manager/commit/?id=9e70d2e4aa8b9287a4d06d35010a01ba3bebd857
Comment 2 Derk te Bokkel 2016-06-03 16:37:44 CEST
It seems that this patch breaks xfce-session-logout or so it appears .. as it only now does logout or shutdown no matter which button is pushed ..
git version compiled may 26, 2016 worked properly, may 31, 2016 has this issue ..
Comment 3 Derk te Bokkel 2016-06-03 16:40:50 CEST
also xfce4-power-manager also appears to have hibernation and sleep operation failures as well .. same time frame
Comment 4 Derk te Bokkel 2016-06-03 16:43:47 CEST
qdbusviewer shows xfce4-powermanager as having only quit and restart active as dbus rules
Comment 5 Derk te Bokkel 2016-06-03 16:51:46 CEST
direct commands to consolekit via dbusviewer give normal suspend function as do direct calls to pm-suspend

calling xfce-session-logout --hibernate (or sleep) via commandline results in immediate logout .. as do using the logout menu/buttons

somewhere the logic is failing any idea where this might be?
Comment 6 Derk te Bokkel 2016-06-03 19:36:53 CEST
reverting to xfce4-power-manager-1.6.0 returns normal suspend and hibernate functions to power manager.. this drops this patch effectively .. qdbusviewer still only shows restart and quit functions under xfce4-power-manager but the communication with consolekit (version2) works again

Also git version of xfce4-power-manager randomly stops running .. fyi
Comment 7 Derk te Bokkel 2016-06-03 19:47:17 CEST
turning off the screenlocker in the session manager(git version) allows proper suspend and hibernate to function ..

i'm using slock as my active screen locker with a patch to xflock4 (gentoo) to activate it .. I'll try to remove the patch and see if things work
Comment 8 Derk te Bokkel 2016-06-03 20:02:06 CEST
Ah! when the screenlocker is activated for sleep xfce4-power-manager crashes on attempting to suspend/hibernate .. also xfce-session-logout via menu allows hibernate and suspend to work when screenlocker is not selected .. but
Comment 9 Derk te Bokkel 2016-06-03 20:04:17 CEST
still crashes so  the gentoo xflock4 patch has no-effect on the instability when the screenlocker is activated
Comment 10 Derk te Bokkel 2016-06-03 20:10:21 CEST
sorry the last comment was not clear .. by crashes .. the session is ended force-ably instead of suspending or hibernating .. or so it appears .. this is in /var/log/messages

 kernel: traps: xfce4-session[5682] trap int3 ip:7f434d4b192b sp:7fff586b2a10 error:0
Jun  3 14:02:13 zlink1 kernel: traps: ck-remove-direc[7947] trap int3 ip:7f0ab3eb192b sp:7ffe7748d590 error:0
Jun  3 14:02:13 zlink1 polkitd[1172]: Unregistered Authentication Agent for unix-session:/org/freedesktop/ConsoleKit/Session6 (system bus name :1.73, object path /org/gnome/PolicyKit1/AuthenticationAgent, locale en_US.utf8) (disconnected from bus)
j
Comment 11 Eric Koegel editbugs 2016-06-04 07:31:58 CEST
If xfpm or xfsm is crashing because of the patch, can you get a backtrace? https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces

What patch are you using for xflock4? Hopefully I can find a way to reproduce it.
Comment 12 Derk te Bokkel 2016-06-04 11:59:24 CEST
Created attachment 6692 
xflock4.patch adding alock support

removed this temporarily from gentoo xfce4-session.ebuild
Comment 13 Derk te Bokkel 2016-06-04 13:01:41 CEST
Created attachment 6693 
xfce4-session-logout backtraces

compiled xfce4-session, xfce4-power-manager, slock with split debug info

also activated core files

ran in terminal gdb -q xfce4-session-logout --suspend
twice once with screenlocking off second time with screenlocking on

also attaching core dump
Comment 14 Derk te Bokkel 2016-06-04 13:12:03 CEST
cancel core dump attachment as it is too big 34mb

correct command used was 

gdb -q xfce4-session-logout

.. that shows the menu .. then suspend was selected .. and we crash

checked core dump but we only crashed again .. not helpful

will try xfpm next ..
Comment 15 Derk te Bokkel 2016-06-04 14:04:28 CEST
i am not getting useful info trying to use gdb .. with xfce4-power-manager

trying to run from the command line  and not getting very far

is there a trick to starting xfce4-power-manager under gdb with arguments .. as gdb complains when I try to add --nodaemon --nodebug
Comment 16 Derk te Bokkel 2016-06-04 15:00:29 CEST
running xfce-power-manager --nodaemon --debug .. ending fragment



(xfce4-power-manager:13794): xfce4-power-manager-WARNING **: Unable to set the kernel brightness switch parameter to 0.
TRACE[xfpm-backlight.c:258] xfpm_backlight_brightness_on_ac_settings_changed(): Alarm on ac timeout changed 9
TRACE[xfpm-backlight.c:279] xfpm_backlight_brightness_on_battery_settings_changed(): Alarm on battery timeout changed 120

(xfce4-power-manager:13794): xfce4-power-manager-WARNING **: Failed to get keyboard max brightness level : GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface 'org.freedesktop.UPower.KbdBacklight' on object at path /org/freedesktop/UPower/KbdBacklight
TRACE[xfpm-polkit.c:244] xfpm_polkit_free_data(): Destroying Polkit data
TRACE[xfpm-manager.c:440] xfpm_manager_lid_changed_cb(): LID close event: ((XfpmLidTriggerAction) LID_TRIGGER_LOCK_SCREEN)

(xfce4-power-manager:13794): xfce4-power-manager-ERROR **: Screensaver lock command not set when attempting to lock the screen.
Please set the xfconf property /general/LockCommand in xfce4-session to the desired lock command
Trace/breakpoint trap (core dumped)


.. perhaps a clue .. slock is not being set in xfconf prior to laptop lid closure .. how is this done in xfce4-session???
Comment 17 Derk te Bokkel 2016-06-04 15:17:30 CEST
ok figured it out .. using the settings editor I set the session lockcomand to slock ..

then everything works normally ..

now is this required now or did something get missed in the detection of the available screen lockers?
Comment 18 Derk te Bokkel 2016-06-04 15:49:28 CEST
so there should be an error trap of some sort if no lockcommand is set or detected .. either in xfce4-session or/and xfce4-power-manager and the "lock before sleep" is selected in either program ..
Comment 19 Eric Koegel editbugs 2016-06-04 16:46:22 CEST
Created attachment 6694 
Fix a crash when warning about the screenlocker

oh, for the core dump, just typing bt after it crashes or after loading the core file like "gdb xfce4-power-manager core" but looks like you've narrowed things down, thanks.

The xfconf property is new and not required but the hope is that you can use it rather than hacking at xflock4. But if you don't set it, there's a warning to let you know that there you can use it now... which looks like I made it a g_error on accident which causes gtk to abort the program. 

Can you try this patch in xfce4-power-manager? I'll push the same fix to session if it works.
Comment 20 Derk te Bokkel 2016-06-04 17:17:45 CEST
ok tested by removing lockcommand from xfce4-session via xfce4-settings-editor then stopping the running version of xfce4-power-manager --quit then restarting with --nodaemon --debug flags via terminal .. absence of the lock command setting no-longer crashes xfce4-power-manager and suspend works properly .. but of course no lock screen .. there is no dialog popped up about this which might be useful somewhere .. perhaps with and entry line? for and easy setting .. just a thought .. perhaps xfce4-session manager would be a better place for that?

of course resetting lockcommand causes locker to work  :)
Comment 21 Eric Koegel editbugs 2016-06-04 17:34:04 CEST
oh right, so now it doesn't crash you'd be back to either needing the lockcommand or your patched xflock to call slock since it will fallback to trying xflock again (it was happening after the warning message). And yeah, next steps would be to expose or document it better.
Comment 22 Derk te Bokkel 2016-06-04 18:01:06 CEST
actually xflock4 does not seem to be called so the xfce4-session lockcommand setting only works fyi so slock is not triggered
Comment 23 Derk te Bokkel 2016-06-04 18:43:20 CEST
(xfce4-power-manager:6298): xfce4-power-manager-WARNING **: Failed to get keyboard max brightness level : GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface 'org.freedesktop.UPower.KbdBacklight' on object at path /org/freedesktop/UPower/KbdBacklight
TRACE[xfpm-manager.c:440] xfpm_manager_lid_changed_cb(): LID close event: ((XfpmLidTriggerAction) LID_TRIGGER_SUSPEND)

(xfce4-power-manager:6298): xfce4-power-manager-WARNING **: Screensaver lock command not set when attempting to lock the screen.
Please set the xfconf property /general/LockCommand in xfce4-session to the desired lock command
ERROR: Unknown command 'lock'
TRACE[xfpm-manager.c:473] xfpm_manager_lid_changed_cb(): LID opened: ((XfpmLidTriggerAction) LID_TRIGGER_SUSPEND)
TRACE[xfpm-dpms.c:284] xfpm_dpms_force_level(): start
TRACE[xfpm-dpms.c:316] xfpm_dpms_force_level(): No need to change DPMS mode, current_level=0 requested_level=0
  

this is the message stuff received w/ patch in place .. which only adds alock to the list .. so xfce4-session standard has slock in the xflock4 .. script by default ..

lockcommand not set .. so slock is in place but the script does not seem to run ..

added an "echo $lock_cmd"   just before call to slock and ran xflock4 manually:

xflock4
xlock -mode blank
slock


same as above with modified xflock4


TRACE[xfpm-manager.c:473] xfpm_manager_lid_changed_cb(): LID opened: ((XfpmLidTriggerAction) LID_TRIGGER_SUSPEND)
TRACE[xfpm-dpms.c:284] xfpm_dpms_force_level(): start
TRACE[xfpm-dpms.c:316] xfpm_dpms_force_level(): No need to change DPMS mode, current_level=0 requested_level=0
TRACE[xfpm-polkit.c:244] xfpm_polkit_free_data(): Destroying Polkit data
.... modified xflock4 .. here
TRACE[xfpm-manager.c:440] xfpm_manager_lid_changed_cb(): LID close event: ((XfpmLidTriggerAction) LID_TRIGGER_SUSPEND)

(xfce4-power-manager:6298): xfce4-power-manager-WARNING **: Screensaver lock command not set when attempting to lock the screen.
Please set the xfconf property /general/LockCommand in xfce4-session to the desired lock command
ERROR: Unknown command 'lock'
TRACE[xfpm-manager.c:473] xfpm_manager_lid_changed_cb(): LID opened: ((XfpmLidTriggerAction) LID_TRIGGER_SUSPEND)
TRACE[xfpm-dpms.c:284] xfpm_dpms_force_level(): start
TRACE[xfpm-dpms.c:316] xfpm_dpms_force_level(): No need to change DPMS mode, current_level=0 requested_level=0

or do I need a different command for it to show?
Comment 24 Eric Koegel editbugs 2016-06-05 15:54:08 CEST
Created attachment 6696 
When locking fallback to xflock4 first

Hey, yeah it's probably because it's trying xdg-screensaver first, can you try this patch as well? Thanks.
Comment 25 Derk te Bokkel 2016-06-06 01:04:48 CEST
which source does this get applied to?
Comment 26 Derk te Bokkel 2016-06-06 01:23:06 CEST
oops goes on  xfce4-power-manager ... but xfce4-session .. needs something similar as well as it does not activate slock yet ..
Comment 27 Derk te Bokkel 2016-06-06 01:25:29 CEST
yeah the patch works for just xfce4-power-manager  ..
Comment 28 Eric Koegel editbugs 2016-06-06 05:31:47 CEST
Pushed the following fixes to xfpm:
commit 7e8574c188893eb2a73cf9d51765822089010dd5
Author: Eric Koegel <eric.koegel@gmail.com>
Date:   Sun Jun 5 16:10:46 2016 +0300

    When locking fallback to xflock4 first (Bug #12603)
    
    While it would be nice to use the xdg-screensaver first since it
    is the standard, it breaks the existing workflow for users who
    have custom patches in xflock4 so switch back to the previous
    fallback order.
http://git.xfce.org/xfce/xfce4-power-manager/commit/?id=7e8574c188893eb2a73cf9d51765822089010dd5

commit 24bcf752e51c2762d40a7611caff399c2f0556aa
Author: Eric Koegel <eric.koegel@gmail.com>
Date:   Sat Jun 4 17:44:10 2016 +0300

    Fix a crash when warning about the screenlocker (Bug #12603)
http://git.xfce.org/xfce/xfce4-power-manager/commit/?id=24bcf752e51c2762d40a7611caff399c2f0556aa

And the same to xfsm:
commit affe4d948da63b9c11553d295bddf2867f797ad2
Author: Eric Koegel <eric.koegel@gmail.com>
Date:   Mon Jun 6 05:56:57 2016 +0300

    When locking fallback to xflock4 first (Bug #12603)
http://git.xfce.org/xfce/xfce4-session/commit/?id=affe4d948da63b9c11553d295bddf2867f797ad2

commit cb4dda3e6696746d5f8ceb147e0c8fc43e434d32
Author: Eric Koegel <eric.koegel@gmail.com>
Date:   Sat Jun 4 18:49:52 2016 +0300

    Fix a crash when warning about the screenlocker (Bug #12603)
http://git.xfce.org/xfce/xfce4-session/commit/?id=cb4dda3e6696746d5f8ceb147e0c8fc43e434d32
Comment 29 Derk te Bokkel 2016-06-06 14:15:03 CEST
thank you for your work on this .. :)

all works again ..
Comment 30 Chris Rainey 2018-07-27 16:53:00 CEST
Just adding some notes here for anyone else that stumbles on to this bug before the fix gets pushed to Ubuntu >=18.04(I spent many hours yesterday looking back through various StackExchange and blog posts before Ifigured this out):


Using a pure install of the "xfce4" and "xfce4-power-manager" packages after a clean install of Ubuntu 18.04 LTS does not lock the screen when closing a laptop lid without manually adding the following property to the local or global xfconf database(/etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-session.xml):

<property name="LockCommand" type="string" value="xscreensaver-command -lock"/>

This property is undiscoverable and not well documented, if at all.

There was a patch to add this property back in 2015 @ https://git.xfce.org/xfce/xfce4-session/commit/settings/xfce4-session.xml?id=570093ffafa8a6226ce9dd0ee29e9e64539d4bc9, but it does not appear to be in the current Ubuntu source.

Manually adding this prpoerty is accomplished by the following command:

$xfconf-query -c xfce4-session -p /general/LockCommand -s 'xscreensaver-command -lock' -v -n -t string

Without this parameter and a named running screen locking daemon(XScreenSaver by default), the system will Suspend---but, not be locked upon Resume when triggered by a laptop lid-switch.

Please add or patch the Ubuntu version to provide this basic functionality as "systemd-logind.service" is not overriding by default:

$ systemd-inhibit --list
     Who: NetworkManager (UID 0/root, PID 936/NetworkManager)
    What: sleep
     Why: NetworkManager needs to turn off networks
    Mode: delay

     Who: ModemManager (UID 0/root, PID 895/ModemManager)
    What: sleep
     Why: ModemManager needs to reset devices
    Mode: delay

     Who: UPower (UID 0/root, PID 1564/upowerd)
    What: sleep
     Why: Pause device polling
    Mode: delay

     Who: xfce4-power-manager (UID 1000/chris, PID 1614/xfce4-power-man)
    What: handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch
     Why: xfce4-power-manager handles these events
    Mode: block

4 inhibitors listed.


SOURCE:  https://bugs.launchpad.net/ubuntu/+source/xfce4-session/+bug/1783895

Bug #12603

Reported by:
Eric Koegel
Reported on: 2016-05-27
Last modified on: 2018-09-14

People

Assignee:
Ali Abdallah
CC List:
6 users

Version

Attachments

Additional information