Solved xfce4-power-manager plugin not working as expected

w5plt

Member

Thanks: 4
Messages: 29

#1
I recently acquired a ThinkPad T480 and installed FreeBSD 11.2 with XFCE4. Suspend and Resume work as expected from the command line. It also works from the menu within Xfce4, however, I cannot change the System power saving settings from within the Xfce Power Manager plugin.

Running the following command:

xfce4-power-manager --dump

Code:
---------------------------------------------------
       Xfce power manager version 1.6.1
With policykit support
Without network manager support
---------------------------------------------------
Can suspend: True
Can hibernate: True
Authorized to suspend: False
Authorized to hibernate: False
Authorized to shutdown: True
Has battery: True
Has brightness panel: False
Has power button: True
Has hibernate button: False
Has sleep button: True
Has LID: False
I want to change the "Authorized to suspend: False" to True but are not sure how to accomplish it.

I would appreciate any assistance.

Thanks in advance.
 
Last edited:

SirDice

Administrator
Staff member
Administrator
Moderator

Thanks: 6,776
Messages: 28,526

#2
I want to change the "Authorized to suspend: False" to True but are not sure how to accomplish it.
Never looked at it but I suspect this is done through PolicyKit. If I remember correctly the operator group already has quite a lot of permissions, have you tried adding your user account to that group?
 
OP
OP
w5plt

w5plt

Member

Thanks: 4
Messages: 29

#3
SirDice,

Thanks for the suggestion. The user was already a member of the group operator but I double checked to make sure. I suspect it has to do with PolicyKit but are unsure of how PolicyKit and Xfce4-power-manager play with one another at this point.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Thanks: 6,776
Messages: 28,526

#4
Found some interesting PolicyKit configs on the ArchWiki: https://wiki.archlinux.org/index.php/Polkit

Save this as /usr/local/etc/polkit-1/rules.d/10-enable-suspend.rules:
Code:
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.suspend" ||
        action.id == "org.freedesktop.login1.suspend-multiple-sessions" ||
        action.id == "org.freedesktop.login1.hibernate" ||
        action.id == "org.freedesktop.login1.hibernate-multiple-sessions")
    {
        return polkit.Result.YES;
    }
});
Not sure if this actually works, I haven't tested it. But it may give you some leads to play with.
 
OP
OP
w5plt

w5plt

Member

Thanks: 4
Messages: 29

#5
SirDice,

Thanks again for the hint and leads. I can manually suspend from the Logout/Suspend/Restart Menu. My issue is xfce4 includes a plugin called xfce4-power-manager that you can use to set up time constraints to suspend the system. It also has display settings for on battery and plugged in that you can blank the display or suspend the system.

There is a useful debugging tool which did indicate an issue with GDBus and PolicyKit. Here is the commands used:

xfce4-power-manager --no-daemon --debug

Abbreviated Output:


(xfce4-power-manager:43386): xfce4-power-manager-WARNING **: 'CheckAuthorization' failed with GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Unix process subject does not have uid set
TRACE[xfpm-polkit.c:366] xfpm_polkit_check_auth_intern(): Action=org.freedesktop.consolekit.system.suspend is authorized=FALSE
TRACE[xfpm-polkit.c:345] xfpm_polkit_check_auth_intern(): polkit request: (('unix-process', {'pid': <uint32 43386>, 'start-time': <uint64 1538617709>}), 'org.freedesktop.consolekit.system.hibernate', @a{ss} {}, uint32 0, '')

(xfce4-power-manager:43386): xfce4-power-manager-WARNING **: 'CheckAuthorization' failed with GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Unix process subject does not have uid set
TRACE[xfpm-polkit.c:366] xfpm_polkit_check_auth_intern(): Action=org.freedesktop.consolekit.system.hibernate is authorized=FALSE
TRACE[xfpm-power.c:1446] xfpm_update_blank_time(): Timeout: 10
TRACE[xfpm-power.c:1446] xfpm_update_blank_time(): Timeout: 10
TRACE[xfpm-power.c:1446] xfpm_update_blank_time(): Timeout: 10


It does seem PolicyKit is looking for a uid for the process daemon xfce4-power-manager. At this point I'm not sure where to proceed. Any assistance would be appreciated.

73,

Scott - w5plt
 

k.jacker

Aspiring Daemon

Thanks: 311
Messages: 546

#6
Hei, I can't directly solve your problem, but hopefully help with some information.
I wonder how you start xfce4/Xorg, since you write you can suspend from the menu?
For me basically, starting xfce4/Xorg through x11/slim login manager, makes suspending available, both from the menu and also the output from
xfce4-power-manager
Code:
---------------------------------------------------
       Xfce power manager version 1.6.1
With policykit support
Without network manager support
---------------------------------------------------
Can suspend: True
Can hibernate: True
Authorized to suspend: True
Authorized to hibernate: True
Authorized to shutdown: True
...
While, when i stop the slim service and then start xfce4/Xorg through startx I can not suspend (or shutdown) from the menu anymore.
Also the output from
xfce4-power-manager shows I'm not authorized anymore.
Code:
---------------------------------------------------
       Xfce power manager version 1.6.1
With policykit support
Without network manager support
---------------------------------------------------
Can suspend: True
Can hibernate: True
Authorized to suspend: False
Authorized to hibernate: False
Authorized to shutdown: False
....
In short. Using policies never worked for me, but using slim login manager is fine.
 
OP
OP
w5plt

w5plt

Member

Thanks: 4
Messages: 29

#7
k.jacker,

I appreciate the information. I will install slim and compare my results to yours. I'm making a fresh install just to make sure I have a clean environment.

I'll report back in a day.

Thanks again.
 

xtaz

Well-Known Member

Thanks: 90
Messages: 377

#8
I am watching this thread too. I have what is basically a clean install on 11.2. There is very little changed and I also have those authorisation settings set to false. I use slim and so for me this makes no difference. I've tried all sorts of changes to polkit, consolekit and nothing seems to make any difference.

In my case I can suspend to ram from either closing the lid or from using the xfce4 menu option Log Out followed by Suspend. That works fine. But in the xfce4 power settings the options for suspend and hibernate are greyed out and can't be changed.

I have never expected hibernate to work because suspend to disk isn't a feature of FreeBSD, but I would like to get the xfce4 power settings to recognise suspend to ram so that I can configure it to do it automatically after some time.
 

k.jacker

Aspiring Daemon

Thanks: 311
Messages: 546

#9
But in the xfce4 power settings the options for suspend and hibernate are greyed out
Besides the authorization to suspend, the Can suspend: True is important.

Code:
% xfce4-power-manager --dump
---------------------------------------------------
       Xfce power manager version 1.6.1
With policykit support
Without network manager support
---------------------------------------------------
Can suspend: True
...
It will only show True when hw.acpi.suspend_state is S3.
Code:
% sysctl hw.acpi.suspend_state
hw.acpi.suspend_state: S3
Which usually needs to be configured from the BIOS.
I am a bit unsure why you are able to suspend manually, but most probably your value is NONE or something wrong at least.

Check sysctl hw.acpi.supported_sleep_state and see if S3 is listet.

From my own experience, some computer BIOS have stupid settings for that, e.g. my own computer.
In the BIOS settings:

Suspend to RAM: disabled (S3 and S4 disabled)
Suspend to RAM: enabled (only S4 enabled)
Suspend to RAM: auto (only S3 enabled) ==> Can suspend: True

Try playing with the options in your BIOS and see if that changes the value from sysctl hw.acpi.suspend_state to S3.
 
OP
OP
w5plt

w5plt

Member

Thanks: 4
Messages: 29

#10
xtaz and k.jacker,

Thanks again for the input. It has been very valuable. Here's what I know after a fresh install of FreeBSD 11.2:

If my .xinitrc file has the following: exec /usr/local/bin/startxfce4 --with-ck-launch and I manually launch from the command line with startx, the xfce4-power-manager plugin works as expected with suspend. Here is the output from xfce4-power-manager --dump

Code:
---------------------------------------------------
Xfce power manager version 1.6.1
With policykit support
Without network manager support
---------------------------------------------------
Can suspend: True
Can hibernate: True
Authorized to suspend: True
Authorized to hibernate: True
Authorized to shutdown: True
Has battery: True
Has brightness panel: False
Has power button: True
Has hibernate button: False
Has sleep button: True
Has LID: False
Using the same .xinitrc file and invoking slim as the login manager, the xfce4-power-manager plugin worked as expected with suspend. Here is the output from xfce4-power-manager --dump


Code:
---------------------------------------------------
       Xfce power manager version 1.6.1
With policykit support
Without network manager support
---------------------------------------------------
Can suspend: True
Can hibernate: False
Authorized to suspend: True
Authorized to hibernate: False
Authorized to shutdown: True
Has battery: True
Has brightness panel: False
Has power button: True
Has hibernate button: False
Has sleep button: True
Has LID: False
Using Slim apparently disables the Hibernation Functions of the plugin but that's fine since FreeBSD does not yet support Hibernation as xtaz mentioned above. But why this is happening? I'm not sure. Hopefully, someone can chime in and provide some insight. K.Jacker is also spot on in referencing bios functions related to suspend/hibernation/resume. In my case, I could always suspend and resume using the command line acpiconf -s 3

It is working now but I suspect under my previous installation when I invoked the hardening options at install time it may have contributed to my issue. I will manually turn on each of the features to see if it has any affect on the xfce4-power-manager plugin. I'll report back in the next day or two with the final results.


NOTE:
As per the pkg message from xfce4-session, I added the following rule to /usr/local/etc/polkit-1/rules.d/85-suspend.rules, of course, I used the group "operator" which my user is a member of:

Code:
polkit.addRule(function (action, subject) {
  if ((action.id == "org.freedesktop.consolekit.system.restart" ||
       action.id == "org.freedesktop.consolekit.system.stop")
      && subject.isInGroup("operator")) {
     return polkit.Result.YES;
   }
})

polkit.addRule(function (action, subject) {
   if (action.id == "org.freedesktop.consolekit.system.suspend"
       && subject.isInGroup("operator")) {
     return polkit.Result.YES;
  }
});
 
OP
OP
w5plt

w5plt

Member

Thanks: 4
Messages: 29

#11
Solved:

It seems when the "Hardening Options" are selected during the install time will affect xfce4-power-manager options.

BSD001.png


If these options were selected, the following changes are made to /etc/sysctl.conf:

Code:
security.bsd.see_other_uids=0
security.bsd.see_other_gids=0
security.bsd.unprivileged_read_msgbuf=0
security.bsd.unprivileged_proc_debug=0
kern.randompid=$(jot -r 1 9999)
security.bsd.stack_guard_page=1
If the following are comment out in /etc/sysctl.conf, xfce4-power-manager will work as expected:

Code:
#security.bsd.see_other_uids=0
#security.bsd.see_other_gids=0
Running the following command:

xfce4-power-manager --dump yields:

Code:
---------------------------------------------------
       Xfce power manager version 1.6.1
With policykit support
Without network manager support
---------------------------------------------------
Can suspend: True
Can hibernate: False
Authorized to suspend: True
Authorized to hibernate: False
Authorized to shutdown: True
Has battery: True
Has brightness panel: False
Has power button: True
Has hibernate button: False
Has sleep button: True
Has LID: True
This is correct and as if should be! All the xfce4-power-manager features work as expected. This makes sense since xfce4-power-manager utilizes PolicyKit for controlling system-wide privileges. By selecting the "Hardening Options" during install time, it prevented other processes to see other uid or guid's.

Thanks for SirDice, K.Jacker, and xtaz for their input and suggestions.

73,

w5plt
 

xtaz

Well-Known Member

Thanks: 90
Messages: 377

#12
Oooooh! Nice find. Yes I have all of those options set. Thank you for experimenting with this. I'll change that now!
 
Top