Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Xfce suspend script
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
skiwarz
Apprentice
Apprentice


Joined: 23 Feb 2014
Posts: 263

PostPosted: Sat Feb 15, 2020 6:41 am    Post subject: [SOLVED] Xfce suspend script Reply with quote

Hello all,
I have a script which I would like to run whenever my computer goes into the "suspend" state. I'm using Xfce for my DE, and I have consolekit, policykit, and pm-utils installed in order to make "suspend" work, and it suspends without much issue.
The script I am trying to run checks for any "emerge" or "gcc" processes and aborts the suspend operation if something is compiling. I placed it in the /etc/pm/sleep.d/ folder and formatted it properly according to the pm-utils instructions. The script works just fine.

Now, here's my issue:
When I suspend using either the Xfce "log out" menu, the pm-suspend command, "pkexec xfce4-pm-helper --suspend", or even invoking the Suspend method in dbus, my system runs the scripts in /etc/pm/sleep.d/ and suspends normally. However, when I use the xfce4-power-manager to make my computer suspend after XX minutes, or when I close the lid, it completely skips all the /etc/pm/ scripts and continues the suspend. I know this because 1: it still suspends even if I'm compiling something, and 2: the log file at /var/log/pm-suspend.log remains empty in this case. Ordinarily there would be ~30 lines or so entered there if it ran my script. Does anyone have any idea why this happens? I'm assuming that the Xfce power manager uses a different command to suspend, depending on which way you tell it to suspend. But I have no idea...

Please help if you can,

-skiwarz


Last edited by skiwarz on Sun Feb 16, 2020 7:35 am; edited 1 time in total
Back to top
View user's profile Send private message
0azza0
n00b
n00b


Joined: 16 Sep 2019
Posts: 15

PostPosted: Sun Feb 16, 2020 12:03 am    Post subject: Reply with quote

Its just, different .. i just went for a quick source read, haven't gone full trace on it as in, reading dbus code or totally verifying my statements but, here:

in pm-manager it happens directly within the xfce4-power-manager blob (where XfpmManagerPrivate struct has a pointer right into GDBus)

https://github.com/xfce-mirror/xfce4-power-manager/blob/master/src/xfpm-manager.c
lines: 336-338
Code:

    case XFPM_DO_SUSPEND:
      xfpm_power_suspend (manager->priv->power, force);
      break;

(the structs defining this are ~lines def: 88, called, line 155)


whereas when pm-helper invokes it, its actually going back to the OS with the command, in all cases:

https://github.com/xfce-mirror/xfce4-power-manager/blob/master/src/xfpm-pm-helper.c
lines: 178-180
Code:

  if(suspend)
  {
    if (run (UP_BACKEND_SUSPEND_COMMAND))


invoking, same file:
lines: 68-79
Code:

#ifdef BACKEND_TYPE_FREEBSD
#define UP_BACKEND_SUSPEND_COMMAND "/usr/sbin/acpiconf -s 3"
#define UP_BACKEND_HIBERNATE_COMMAND "/usr/sbin/acpiconf -s 4"
#endif
#ifdef BACKEND_TYPE_LINUX
#define UP_BACKEND_SUSPEND_COMMAND "/usr/sbin/pm-suspend"
#define UP_BACKEND_HIBERNATE_COMMAND "/usr/sbin/pm-hibernate"
#endif
#ifdef BACKEND_TYPE_OPENBSD
#define UP_BACKEND_SUSPEND_COMMAND  "/usr/sbin/zzz"
#define UP_BACKEND_HIBERNATE_COMMAND "/usr/sbin/ZZZ"
#endif


It'd be a pretty easy patch.. of course (it seems like,) dbus itself has covered the case of manual invocation by the user but apparently not when it is this particular function calling..? idk - xfce4 project may be interested, or dbus.
Back to top
View user's profile Send private message
skiwarz
Apprentice
Apprentice


Joined: 23 Feb 2014
Posts: 263

PostPosted: Sun Feb 16, 2020 4:28 am    Post subject: Reply with quote

Thank you, 0azza0 for digging into this.
The xfpm_power_suspend() function calls xfpm_power_sleep.
Code:
void xfpm_power_suspend (XfpmPower *power, gboolean force)
{
    xfpm_power_sleep (power, "Suspend", force);
}
The xfpm_power_sleep function then calls on either a built-in function or consolekit (if installed) to perform the suspend:
Code:
if (check_for_consolekit2 (power))
{
    xfpm_console_kit_suspend (power->priv->console, &error);
}
else
{
    xfpm_suspend_try_action (XFPM_SUSPEND);
}
The xfpm_console_kit_suspend() makes a call to dbus:
Code:
void
xfpm_console_kit_suspend (XfpmConsoleKit *console,
                          GError        **error)
{
    GVariant *var;

    g_return_if_fail (console->priv->proxy != NULL );

    var = g_dbus_proxy_call_sync (console->priv->proxy, "Suspend",
                                  g_variant_new ("(b)", TRUE),
                                  G_DBUS_CALL_FLAGS_NONE,
                                  -1, NULL,
                                  error);

    if (var)
   g_variant_unref (var);
}
...and the xfpm_suspend_try_action() invokes xfce-pm-helper, running the code mentioned in the second half of your post.
If I run the above dbus call manually in a terminal, it still results in the pm-suspend scripts being run. (The "force" argument shown here doesn't do anything meaningful).
In other words, my friend, I still can't find any way to suspend which skips the /etc/pm/sleep.d/ scripts.. but somehow xfce-power-manager IS skipping them...
Back to top
View user's profile Send private message
0azza0
n00b
n00b


Joined: 16 Sep 2019
Posts: 15

PostPosted: Sun Feb 16, 2020 4:48 am    Post subject: Reply with quote

wait - so wait - you have consolekit (and,) your sure thats the point where power-manager is running the dbus call?

i was looking at a call to pkexec in the shell as the final fall-through.

https://github.com/xfce-mirror/xfce4-power-manager/blob/master/src/xfpm-power.c
lines: function at 365, comment at 447
Code:

    /* This is fun, here's the order of operations:
     * - if the Logind is running then use it
     * - if UPower < 0.99.0 then use it (don't make changes on the user unless forced)
     * - if ConsoleKit2 is running then use it
     * - if everything else fails use our built-in fallback
     */


unless you had upower hiding in there .. shoot - sorry - i was thinking permissions on whatever uid pkexec had but - if the gtk menu option is working that seems unlikely.
fallback im reading at ..
(line 191 of https://github.com/xfce-mirror/xfce4-power-manager/blob/master/src/xfpm-suspend.c)


hrmm.. now im thinking on this aspect of the problem -- may have skimmed over some logic relating to those kinds of cases:
Quote:
when I use the xfce4-power-manager to make my computer suspend after XX minutes, or when I close the lid,
Back to top
View user's profile Send private message
skiwarz
Apprentice
Apprentice


Joined: 23 Feb 2014
Posts: 263

PostPosted: Sun Feb 16, 2020 5:32 am    Post subject: Reply with quote

I'm not an expert on dbus, and from what I've experienced, dbus is a confusing pile of dog poop.

However, I've learned that there is a difference between the "system" bus and a "session" bus. Also, it turns out that there are no less than three different "Suspend()" objects within my dbus. It seems that one of these, in the session bus, is being called by xfce4-power-manager to execute the suspend. When I execute this particular one manually, it skips all the /etc/pm/sleep.d/ scripts as I've been experiencing.

The confusing part has been that none of the source code I've been looking at seems to invoke this dbus method (They all go through the ConsoleKit dbus tree). But, anyways, now I need to find a way to modify my scripts to accommodate this.

Follow-up question: Is it possible to completely get rid of dbus?


Last edited by skiwarz on Sun Feb 16, 2020 5:51 am; edited 1 time in total
Back to top
View user's profile Send private message
skiwarz
Apprentice
Apprentice


Joined: 23 Feb 2014
Posts: 263

PostPosted: Sun Feb 16, 2020 5:48 am    Post subject: Reply with quote

0azza0 wrote:
wait - so wait - you have consolekit (and,) your sure thats the point where power-manager is running the dbus call?

i was looking at a call to pkexec in the shell as the final fall-through.

https://github.com/xfce-mirror/xfce4-power-manager/blob/master/src/xfpm-power.c
lines: function at 365, comment at 447
Code:

    /* This is fun, here's the order of operations:
     * - if the Logind is running then use it
     * - if UPower < 0.99.0 then use it (don't make changes on the user unless forced)
     * - if ConsoleKit2 is running then use it
     * - if everything else fails use our built-in fallback
     */



So, I have consolekit and upower installed, but upower is version 0.99.9. I don't have systemd. So, it skips the logind and upower portions of that code and only runs through the code I pasted in my previous post.
Hmm... it's not on github, but if you download the xfce4-power-manager source from portage, look at .../src/org.freedesktop.PowerManagement.c which is where I assume the source code is for the dbus methods. In there, the Suspend() call seems to just make a g_dbus_proxy_call() to itself? I think? Doesn't actually describe what it's doing. But again, I'm a complete novice at everything dbus.

Thanks again for your help, 0azza0 :)
Back to top
View user's profile Send private message
0azza0
n00b
n00b


Joined: 16 Sep 2019
Posts: 15

PostPosted: Sun Feb 16, 2020 5:48 am    Post subject: Reply with quote

if you didnt get a notice for the PM i sent one about 'hibernate' vs 'suspend' either as a command-line or consolekit option being unique to timed sleep. <- there it is

..i didnt look too closely at the lid stuff because it reminded me of javascript show/hide logic and it made me go crosseyed too. i have basically the same thoughts about dbus. i think if there is an alternative it basically puts you in kde/qt ground. could be wrong.

Quote:
It seems that one of these, in the session bus, is being called by xfce4-power-management to execute the suspend. When I execute this particular one manually, it skips all the /etc/pm/sleep.d/ scripts as I've been experiencing.


strange to me it would be in the session, i wonder what the difference between the two Suspends in session is ..

what about catch-all logging on all of policykit instead of logging of whats reaching pm-utils?

(policykit is basically the ear on pm-utils brain, right?)
Back to top
View user's profile Send private message
skiwarz
Apprentice
Apprentice


Joined: 23 Feb 2014
Posts: 263

PostPosted: Sun Feb 16, 2020 6:13 am    Post subject: Reply with quote

0azza0 wrote:
if you didnt get a notice for the PM i sent one about 'hibernate' vs 'suspend' either as a command-line or consolekit option being unique to timed sleep. <- there it is

..i didnt look too closely at the lid stuff because it reminded me of javascript show/hide logic and it made me go crosseyed too. i have basically the same thoughts about dbus. i think if there is an alternative it basically puts you in kde/qt ground. could be wrong.

Quote:
It seems that one of these, in the session bus, is being called by xfce4-power-manager to execute the suspend. When I execute this particular one manually, it skips all the /etc/pm/sleep.d/ scripts as I've been experiencing.


strange to me it would be in the session, i wonder what the difference between the two Suspends in session is ..

what about catch-all logging on all of policykit instead of logging of whats reaching pm-utils?

(policykit is basically the ear on pm-utils brain, right?)


I did... just replied
Where did you see the lid open/closed logic?
As far as I can tell, the Session suspends all do the same thing - skip my pm scripts...
You think maybe the session bus is trying but just doesn't have permissions to read from /etc/pm/sleep.d/ ? Any idea how to log all the policykit stuff? I've never changed any of its config files...

Also, in case anyone else ever stumbles on this forum, I found that "dev-util/d-feet" is a great help for exploring d-bus on Gtk-based machines. dev-qt/qdbusviewer does the same thing on kde/qt.
Back to top
View user's profile Send private message
0azza0
n00b
n00b


Joined: 16 Sep 2019
Posts: 15

PostPosted: Sun Feb 16, 2020 6:48 am    Post subject: Reply with quote

for lid check xfpm-power.c, a lid check is defined at line 269

the lid state is one of the elements of data on XfpmPower *power, you can see the properties of *power in the comments on 284.
that pointer is read from, written to and otherwise considered by functions all over the file...

one of the properties is can_hibernate, in consolekit it gets checked and set on line 190, consolekit might be asking your kernel and bunking something up before the script hack comes into play
Back to top
View user's profile Send private message
skiwarz
Apprentice
Apprentice


Joined: 23 Feb 2014
Posts: 263

PostPosted: Sun Feb 16, 2020 7:14 am    Post subject: Reply with quote

...
...
...
...
I have elogind installed... which means I have logind. Which means xfce4-power-manager invokes xfpm_systemd_sleep() instead of using consolekit.
...
...
...
Sure enough, when I manually run the org.freedesktop.login1.Suspend() method in dbus, it behaves exactly as I've experienced...
It was right there the whole time...
Back to top
View user's profile Send private message
skiwarz
Apprentice
Apprentice


Joined: 23 Feb 2014
Posts: 263

PostPosted: Sun Feb 16, 2020 7:34 am    Post subject: Reply with quote

Confirmed. I uninstalled elogind, restarted, and now power manager runs through consolekit and executes all the pm-util scripts as I wanted, and just like the code says.
I installed skypeforlinux a few weeks ago, and elogind is a dependency of it. Didn't know it would cause so many headaches.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum