[Tfug] Properly terminating a shell script after using X Windows esadyna3

John Gruenenfelder jetpackjohn at gmail.com
Fri Jan 25 14:55:04 MST 2013


On Fri, Jan 25, 2013 at 10:31 AM, Jeff Breadner <jeff at breadner.ca> wrote:
>
> So, I've not tested this at all, but a flash of inspiration struck:
> When you launch X, most systems will have an ~/.xsession script that
> is running as long as your session is active.  Kill ~/.xsession, and
> you kill the whole login.  This script is typically just a bash
> script.  On my system, ~/.xsession calls ~/.xinitrc, which is the file
> that actually calls the window manager.
>
> So, could one not trap a TERM signal to this script, and execute code
> when that is heard?
>
> ...
> exitx() {
>   your_code_here
> }
>
> trap exitx INT TERM QUIT
>
> gnome-session   # Or your WM of choice
> <EOF>
>
>
>
> Similarly, the .xinitrc script will run your window manager, but not
> launch it into the background; .xsession / .xinitrc will stay running
> until the WM exits, then presumably anything after that in the bash
> script is executed.  So, you can put the code you want to run on exit
> after the WM is launched.  To cover both options (a TERM and a natural
> exit), you could possibly do this:
>
> ...
> exitx() {
>   your_code_here
> }
>
> trap exitx INT TERM QUIT
>
> gnome-session   # Or your WM of choice
>
> exitx
>
> <EOF>
>
>
> Again, this is completely untested; I'm at work and can't look into it
> now, but it might be an avenue worth pursuing.

Jeff,

Thanks for the reply.  Both of these look like good ideas to try, but
I was hoping for something a little more general/generic.  For
example, .xinitrc is only executed if you launch X via the "startx"
command.  Similarly, .xsession is only executed if you choose "X
Session" (or whatever name it happens to have) from your login
manager.  If you use, say, "Gnome Session", which is likely the
default for most people, the .xsession file won't be read at all.
Since I am using "Gnome Session" on my computer, I put a config file
for my script in the autostart directory that Gnome looks at.

So... I guess what I'm getting at is that I, personally, could use any
number of methods to make sure the script exits on *my* computer.  I
would like to make this useful for other people, however, and the
fewer changes they are required to make to their X startup procedure,
the better.  That is why I am hoping to find, if possible, some fairly
general method of exiting the script when the user logs out so that it
"just works" in most cases.

I suppose, failing that, I could put together an instructions file
that includes a list of numerous methods of both starting and stopping
the script and then let the user chose the methods that best match how
their system is configured.  That's still far more manual a process
than I was hoping for, however.


--John Gruenenfelder    Systems Manager, MKS Imaging Technology, LLC.
Try Weasel Reader for Palm OS  --  http://weaselreader.org
"This is the most fun I've had without being drenched in the blood
of my enemies!"
        --Sam of Sam & Max



More information about the tfug mailing list