[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to cause a process started in .xsessionrc to terminate with x-session termination?



On Sun, Nov 21, 2021 at 07:18:23PM +0100, Arkadiusz Dabrowski wrote:
> Have you considered using my suggestion?  Put these two lines in .xsession:
> >
> > . /etc/X11/Xsession
> > pkill unison
> >
> > Keep your .xsessionrc which starts the unison program.  (Or you could
> > move it here, later, but for now I'm simply trying to do the bare
> > minimum needed to achieve a working setup.)
> >
> > That is even worse. I see that ~/.xsession is invoked from
> etc/X11/Xsession (indirectly by calling
> /etc/X11/Xsession.d/50x11-common_determine-startup)
> and after .xsessionrc (called prior from
> /etc/X11/Xsession.d/40x11-common_xsessionrc) so I ended-up with hundreds of
> unison instances instead of new X session.
> 
> But it is not so bad: I learned about X11 starting process so will be able
> to analyze it and invent something. So thanks a lot :)

Damn.  I was hoping I could come up with a nice, simple way for a novice
user to introduce a .xsession file and reap the benefits thereof, without
having to undergo all of the complexity of writing a full-blown .xsession
file.

Apparently this is not possible.  Debian does not provide a single entry
point which a .xsession file can call upon to do all of the things that
the default system session does when .xsession is absent.  That logic is
buried inside one of the dotted-in files (not scripts) in
/etc/X11/Xsession.d/.

So, if you want to be able to kill a process while logging out of
your X session, apparently you need to create a whole .xsession file.
Congratulations: you're graduating out of novice mode whether you like
it or not.

The first thing you'll have to do is figure out how to actually start
your MATE session.  There'll be some magic starting point that you can
call.  I have no idea what it is.  Debian is probably just using a
symlink from /usr/bin/x-session-manager or something, so if you can't
find it on Google or from your own knowledge of MATE, maybe you could
start with that.

Since you want the process-killing to be done after you terminate your
interactive session, you need to *not* use "exec" when you execute the
MATE session.  That way, the shell will still be there to carry on with
the commands after MATE, one of which will kill the unison process.

In the interests of simplicity, I'd also advise getting rid of the
.xsessionrc file.  You might as well put everything in one file, instead
of two files.  It'll be a lot easier to track things down in the future
when you need to make a change, if they're all in one file.

Putting the unison invocation and the unison kill both in the same file
also means you can kill it *properly*, by keeping its PID, instead of
using pkill.

So then, it would look something like this:

your unison thing &
unisonPID=$!
other things you want to run
magic MATE start command
kill "$unisonPID"

Expect to need to tweak it a few times.  And good luck.


Reply to: