[Tfug] Properly terminating a shell script after using X Windows esadyna3
John Gruenenfelder
jetpackjohn at gmail.com
Mon Jan 28 02:03:01 MST 2013
On Sat, Jan 26, 2013 at 11:54 AM, Bexley Hall <bexley401 at yahoo.com> wrote:
>> 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
>
> -----------------------------------------------------^^^^^^^
>
> "Logs out" or "quits his X session"?
In this case, either.
>> 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.
>
> You either have to tell "something" (see my previous post)
> that you are running (and have that "something" kill you
> when X dies) *or* you have to sense when that "something"
> (X) dies and kill yourself!
The problem is knowing just what to register the script with. There
are numerous session managers available for X and a user could be
using any one of them, or possibly even none. Using this method would
probably mean just picking one, say gnome-session, and informing users
that the self-termination only works if they are using Gnome. This
also assumes that the Gnome session manager is easy enough to use from
the command line and without all the gnome libraries.
On the other hand, attempting to *sense* when to exit would be the
more general solution, though likely harder to make 100% reliable. I
originally mentioned that the script could perform checks to see if X
was still running and/or if the running user was still logged in and
act accordingly. This could still get complicated easily, but I think
I could add a configuration option that names the X process. As you
also noted, 'X' is often a link to the actual X server. More than
that, it is often even a hard link. I know on my system, and
presumably most all Debian systems, the process as found with 'ps' is
called simply 'X'. That should make a good default and be easy to
check for (I think).
I suppose the default settings would be to terminate if the user logs
out or if the X process dies. As long as this is configurable, I hope
it will be general enough to work for most people. Since the job of
the script is to first gather, from the Net, the data needed for the
current wallpaper and then to generate that wallpaper once every five
minutes, it makes sense to terminate if either X or the user goes
away.
That said, I am also trying to make the script more functional and
modular. The user should be able to pick the mode of operation, such
as fetch the data or generate a single wallpaper, in additional to the
standard all-in-one timed mode. Obviously, for those modes which will
only last a matter of seconds it no longer becomes necessary to
self-terminate early.
Another question would be how to best handle this status checking.
Currently, the delay between runs in simply handled by running 'sleep'
with a default time of five minutes. It is entirely possible that in
a five minute span a user could log out of an X session, cause X to
restart, and then log back in. I have taken precautions to prevent
the script from executing twice at the same time. I think this is
sufficient since when instructed to display a new wallpaper (via
Gnome), it does this by poking at the Gnome registry and this does not
seem to rely on a specific X connection, but rather just the presence
and accessibility of X. Should this cause trouble again in the
future, I can probably make the delay time a multiple of some smaller
value and then perform the checks every time that common factor
expires.
> I suspect somewhere there is a little scriptlet that already
> does all of this -- to varying degrees of pedantic-ness.
It wouldn't surprise me, though I haven't had much luck finding
anything via Google. If you're not careful in your query you end up
getting a lot of results where 'x' is used as a script variable or
scripts that use the "set -x" command. Not quite the same thing...
Anyway, these emails have given me some ideas to think about. My most
sought after solution is one which does not require any root-level
modifications on the user's system. I can see where that might be
desirable from an admin point of view, but I think that the audience
for this particular wallpaper "system" is small enough that it is best
to focus on its use user by user and not system-wide.
--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