! 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 !
run on logout feature
Status:
RESOLVED: FIXED
Severity:
enhancement
Product:
Xfce4-session
Component:
General

Comments

Description god12 2013-06-12 18:07:07 CEST
It's trivial to run certain scripts during user login however it's impossible to do so on logout.

It would be great if xfce could run script upon session logout where user would write things which got to bo executed before session is finished - think some cleanup/graceful shutdown.
Comment 1 alexxcons editbugs 2015-08-07 23:22:05 CEST
I as well support this feature request. It took me some time to find a workaround:
http://stackoverflow.com/questions/7579438/how-to-execute-a-script-when-xfce-session-ends

A good solution from my POV would be if xfce4-session would source a file $HOME/.logout on regular exit.
Comment 2 xyzdr4gon333 2015-12-05 23:22:42 CET
I would need this feature in order to make a workaround for this bug: https://bugzilla.xfce.org/show_bug.cgi?id=10295
I would solve this bug by inserting the following code into xfce4-session/xfsm-manager.c (version 4.12.1) in xfsm_manager_save_yourself_global(..) after the call to xfsm_logout_dialog(...)


    /* Call logout scripts */
    switch ( manager->shutdown_type /* see xfsm-shutdown.h */ ) {
      case XFSM_SHUTDOWN_LOGOUT   :
        system("/bin/bash $HOME/.config/xfce4-session/hook-logout");
        break;
      case XFSM_SHUTDOWN_SHUTDOWN :
        run("/bin/bash $HOME/.config/xfce4-session/hook-shutdown");
        break;
      case XFSM_SHUTDOWN_RESTART  :
        run("/bin/bash $HOME/.config/xfce4-session/hook-restart");
        break;
      case XFSM_SHUTDOWN_SUSPEND  :
        run("/bin/bash $HOME/.config/xfce4-session/hook-suspend");
        break;
      case XFSM_SHUTDOWN_HIBERNATE:
        run("/bin/bash $HOME/.config/xfce4-session/hook-hibernate");
        break;
      default:
        break;
    }

It actually seems to work, but there may be better implementations regarding the system call, standard search paths and security features. (E.g. I'm not sure whether those script would be called with root privileges)

Unfortunately when I compile xfce4-session 4.12.1 from source the suspend and hibernate buttons are not shown in the logout-dialog and the reboot and shutdown buttons are grayed out/not clickable. So this is not really working for me. Hoping someone implements this correctly or solves the linked bug.

The scripts hook-restart, hook-shutdown and hook-logout would then contain:

    WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$|xfce4-panel$" | cut -f1 -d' ')
    for i in $WIN_IDs; do wmctrl -ic "$i"; done
    # Keep checking and waiting until all windows are closed
    while [ "$WIN_IDs" != "" ]; do
        sleep 0.1;
        WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$|xfce4-panel$" | cut -f1 -d' ')
    done
Comment 3 AlbHam 2017-04-19 13:36:18 CEST
I'm really interesting in this bug to be solved. It will make XFCE perfect.
Comment 4 yonux 2018-11-13 16:59:06 CET
I am too very interested in adding such a feature because it could help to solve an issue I encountered : https://forum.xfce.org/viewtopic.php?pid=50140#p50140
(which is certainly also related to #10295)

It is nearly impossible to execute a command at shutdown, processes are killed too quickly by systemd.
I thought about hacking into systemd configuration for it to send SIGTERM to processes instead of killing them brutally, but it does not help at all because xfce4-session is already gone at that point (so there is no more interesting variables to use by scripts).

The solution would be to implement what's proposed here : let xfce4-session do things BEFORE sending the shutdown command to the system.
Comment 5 alexxcons editbugs 2018-12-07 23:01:37 CET
Created attachment 8164 
Complete feature. Attention, not sure if it runs fine !

Attached a more integrated approach. The same API like for "run on login" is reused. An enum is added to pick from a list "on login", "on logout", "on shutdown", etc.

The patched "xfce4-session-settings" already works fine for me, and is fully backward compatible.

However so far I failed to get xfce-session to run (I as well failed to get xfce-session  master to run :/ ) ... possibly I need a fully blown xfce 4.13 installation first .. to be continued.
Comment 6 alexxcons editbugs 2018-12-07 23:03:27 CET
Created attachment 8165 
Screenshot of proposal for xfce4-session-settings extension
Comment 7 alexxcons editbugs 2019-02-26 11:25:03 CET
TODO: Add a dropdown inside the window, that's called by add/edit. Currently modification of the enum is only possible after adding a task.
Comment 8 alexxcons editbugs 2019-04-09 10:39:13 CEST
Created attachment 8391 
patch1 to move some methods which will be reused
Comment 9 alexxcons editbugs 2019-04-09 10:48:29 CEST
Created attachment 8392 
patch2 to introduce the feature

Ok, finally I have a good implementation.
I split the patch into two, in order to ease comparison. The first patch just moves some methods, used "on login" out of a .c file, since I am going to reuse them "on logout", "on shutdown", etc.
The second patch actually adds the new feature

- A gtk enum is used in order to allow translations of the corresponding strings
- I was finally able to test most cases (did not test "on hybrid sleep" .. though implementation wise there is no difference to the others )

Before I commit the patches to master, it would be good to have some testers.
So if you have time, please give the patches a try !
Comment 10 Simon Steinbeiss editbugs 2019-04-12 23:20:34 CEST
Both patches throw git warnings that would be good to get fixed.

Patch 1
.git/rebase-apply/patch:317: new blank line at EOF.

Patch 2
.git/rebase-apply/patch:522: trailing whitespace.
Comment 11 alexxcons editbugs 2019-04-15 13:11:24 CEST
Created attachment 8410 
patch1 to move some methods which will be reused

Ops .. git warnings fixed now.
Comment 12 alexxcons editbugs 2019-04-15 13:12:13 CEST
Created attachment 8411 
patch2 to introduce the feature
Comment 13 alexxcons editbugs 2019-04-24 00:47:53 CEST
To ease putting comments to the code:  https://github.com/alexxcons/xfce4-session/commits/RunOnLogout5
Comment 14 Git Bot editbugs 2019-04-25 01:06:06 CEST
Alexander Schwinn referenced this bugreport in commit 88346bde9ea6850caaf91e6868813b3132e76b10

Move three methods from startup.c to xfsm-global.c/.h

https://git.xfce.org/xfce/xfce4-session/commit?id=88346bde9ea6850caaf91e6868813b3132e76b10
Comment 15 Git Bot editbugs 2019-04-25 01:06:12 CEST
Alexander Schwinn referenced this bugreport in commit 9e7e160d6db39d39283bef6fafb7264f4a65d9e5

Optionally run commands on logout, suspend etc. (Bug #10172)

https://git.xfce.org/xfce/xfce4-session/commit?id=9e7e160d6db39d39283bef6fafb7264f4a65d9e5
Comment 16 Simon Steinbeiss editbugs 2019-04-25 01:07:06 CEST
Tested and reviewed the commits.

Just as feedback, there were a few more whitespace errors (in the sense of: missing or superfluous spaces), but I fixed them.
Comment 17 alexxcons editbugs 2019-04-25 08:20:56 CEST
Great, thanks Simon !

Bug #10172

Reported by:
god12
Reported on: 2013-06-12
Last modified on: 2020-04-05

People

Assignee:
alexxcons
CC List:
9 users

Version

Version:
Unspecified

Attachments

Additional information