You are not logged in.

#1 2018-05-11 23:33:23

daanjderuiter
Member
Registered: 2016-12-28
Posts: 44

Run script on X session login/resume.

I am looking for a way to run a certain script the moment I log in to an X session, meaning both the point I start the session after booting, and when I log in again after logging into it using a DM in combination with a session locker. I use i3 with LightDM/Light-locker, but I would like to keep the solution as general as possible, not specific to any DM-locker-combo (or not using any DM and using something like i3lock) or DE. The former (starting on the start of the session) is pretty straightforward and has many solutions, but having code run on resume has proven to be a problem. I have found solutions for running code after wakeup (through systemd) but that is not what I am looking for; I'd specifically like to run code after logging in. I am not very well versed in the inner workings of X, and figured I'd post here first to check if there is a nice standard solution for a problem like this.

Last edited by daanjderuiter (2018-05-11 23:35:46)

Offline

#2 2018-05-12 00:11:03

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Run script on X session login/resume.

Clearly I'm reading this wrong, but despite going back several times, these just look like completely opposite statements:

daanjderuiter wrote:

The former (starting on the start of the session) is pretty straightforward and has many solutions, but having code run on resume has proven to be a problem.

daanjderuiter wrote:

I have found solutions for running code after wakeup (through systemd) but that is not what I am looking for; I'd specifically like to run code after logging in.

Can you clarify what you are trying to accomplish?  Do you need help getting script to run on login, or not and on resume or not?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-05-12 00:18:08

daanjderuiter
Member
Registered: 2016-12-28
Posts: 44

Re: Run script on X session login/resume.

It might just be me being a bit tired and failing to type up a comprehensive summary, so I'll try to clarify. Running code the moment I first start the session, after boot, can be done in many ways (.xinitrc, DE-specific config; I use .desktop-files in ~/.config/autostart/), but I would like to run code after suspending, firing my machine back up, and then logging in again (in my case, through a DM-locker-combo), and only after I have resumed my session (so logging in via the DM, not just after waking the machine back up). Systemd can run code after wakeup, but that is not what I am looking for. I hope this clarifies things, sorry for the fuzzy writeup.

Offline

#4 2018-05-12 00:34:54

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Run script on X session login/resume.

Yes, that is clear, thanks.  I don't use DMs, but I'm pretty sure you'd need a DM/locker specific solution here as that's the only process that would lilkely be in the loop on this.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2018-05-12 00:37:32

daanjderuiter
Member
Registered: 2016-12-28
Posts: 44

Re: Run script on X session login/resume.

Ah, that's too bad, was already afraid this would become messy. I'll wait just a bit just in case someone does have a solution, then marked this closed in a day or so. But thanks, anyways.

Offline

#6 2018-05-12 06:43:57

seth
Member
Registered: 2012-09-03
Posts: 51,017

Re: Run script on X session login/resume.

The DM is usually NOT the locker, some DEs just make them look the same.

Both tend to go through PAM, but that also goes for "headless" (local) "logins" - it pretty much depends on whether the locker
a) uses PAM at all
b) rather uses system-local-login (good) or system-auth (bad, because that's everywhere)

You basically need

auth      optional  pam_exec.so /path/to/script

in the proper PAM stage config (as high as possible and sufficient, or the script needs to be able to deal with pointless invocation)
Please notice that uninformed messing with PAM can *completely* lock you out of your system, so be prepared to fix that offline (from a live system)
Also you need to ensure the script runs as the proper user and has the proper environment variables (this is not like running it from an interactive shell in your GUI session!)

Finally: this sounds a lot like an xy-problem, what do you *actually* want to achieve?

Offline

#7 2018-05-12 21:27:30

daanjderuiter
Member
Registered: 2016-12-28
Posts: 44

Re: Run script on X session login/resume.

seth wrote:

Finally: this sounds a lot like an xy-problem, what do you *actually* want to achieve?

I'm making a little script that manages monitor hotplugging on my laptop, since I plug it into other monitors quite regularly. Hotplug-events (udev) and lid-close-events (acpi) are easy enough, but changes between suspending my laptop and firing it up again, such as attaching it to my home setup after returning from uni, have proven a bit problematic; I could reach my DM login screen but not my WM (this was with a solution running the code to update the state of the script on resume). I was wondering what would happen if I would trigger the code on the moment of login, and how I would go about that in a way that was not altogether terrible.

Offline

#8 2018-05-13 05:10:46

seth
Member
Registered: 2012-09-03
Posts: 51,017

Re: Run script on X session login/resume.

changes between suspending my laptop and firing it up again, such as attaching it to my home setup after returning from uni, have proven a bit problematic; I could reach my DM login screen but not my WM

You might want to elaborate on that and also have a look at https://gist.github.com/AladW/de1c5676d93d05a5a0e1

Offline

Board footer

Powered by FluxBB