On Fri, Apr 2, 2010 at 7:31 PM, Fred James <[email protected]>wrote:

> Denis Heidtmann wrote:
> > On Fri, Apr 2, 2010 at 2:01 PM, Fred James <[email protected]
> >wrote:
> >
> >
> >> Denis Heidtmann wrote:
> >>
> >>> On Fri, Apr 2, 2010 at 12:39 PM, Denis Heidtmann
> >>> <[email protected]>wrote:
> >>>
> >>>
> >>>
> >>>> On Fri, Apr 2, 2010 at 11:55 AM, Joe Pruett <[email protected]> wrote:
> >>>>
> >>>>
> >>>>
> >>>>> bash 3.2 on my system doesn't show this problem.  are you sure the
> full
> >>>>> path and relative path actually get to the same script?  could you be
> >>>>> accidentally running two different scripts?  or maybe it is some odd
> >>>>> bash bug, what version do you have?
> >>>>>
> >>>>>
> >>>>>
> >>>> Since /etc/gdm/PostSession/Default is a .sh script, I must use that
> >>>>
> >> shell,
> >>
> >>>> also known as dash.  Maybe bash will not show the problem.  I have
> >>>>
> >> version
> >>
> >>>> 3.2.48(1)-release (x86_64-pc-linux-gnu).
> >>>>
> >>>> -Denis
> >>>>
> >>>> It turns  out that I jumped to an  invalid conclusion.  The issue is
> not
> >>>>
> >>>>
> >>> with bash, but with dash.   But my problem remains.  I need to use
> dash,
> >>>
> >> and
> >>
> >>> the policy wants the script to be sourced.  My only solution at this
> time
> >>>
> >> is
> >>
> >>> to have a separate script with the argument coded into it.  I would
> >>>
> >> prefer
> >>
> >>> not to do that, but even more I would like to understand the behavior.
> >>>
> >>> -Denis
> >>>
> >>>
> >> Dennis Heidtmann
> >> Well, first let's see if we are on the same page ... OK?
> >>    I run Mandriva 2008 and ...
> >>    (1) /bin/sh -> bash
> >>    (2) instead of /etc/gdm/PostSession/Default I have
> >> /etc/X11/gdm/PostSession/Default
> >>    (2.1) I have included the text of /etc/X11/gdm/PostSession/Default
> >> below for comparison
> >>    (3) if we are anywhere near on the same  page ... could you show me
> >> what you are trying to do?
> >> ... hoping to help
> >> Regards
> >> Fred James
> >>
> >> [text of /etc/X11/gdm/PostSession/Default from Mandriva 2008]
> >> #!/bin/sh
> >>
> >> PATH="/usr/bin:$PATH:/bin:/usr/bin"
> >> OLD_IFS=$IFS
> >>
> >> gdmwhich () {
> >>  COMMAND="$1"
> >>  OUTPUT=
> >>  IFS=:
> >>  for dir in $PATH
> >>  do
> >>    if test -x "$dir/$COMMAND" ; then
> >>      if test "x$OUTPUT" = "x" ; then
> >>        OUTPUT="$dir/$COMMAND"
> >>      fi
> >>    fi
> >>  done
> >>  IFS=$OLD_IFS
> >>  echo "$OUTPUT"
> >> }
> >>
> >> exit 0
> >>
> >> I want to log the time of logoff.  I was directed to
> >>
> > gdm/PostSession/default by:
> >
> >
> http://people.uleth.ca/~daniel.odonnell/Blog/lost-in-logout-land-running-scripts-on-login-and-logout-partially-solved-but-interesting-anyway
> >
> > Method 1: /etc/gdm/PostLogin/Default, /etc/gdm/PreSession/Default, and
> > /etc/gdm/PostSession/Default
> >
> > "If you have a shell script that does not require user intervention, you
> can
> > run it automatically immediately after Login, immediately before the
> start
> > of the Gnome Session (i.e. before the desktop is drawn), and immediately
> > after your Gnome Session (i.e. after the Desktop closes down), by
> launching
> > it from /etc/gdm/PostLogin/Default, /etc/gdm/PreSession/Default, and
> > /etc/gdm/PostSession/Default respectively. "
> >
> > I do not understand the function gdmwhich.  I just added a line executing
> my
> > script, using the fully qualified path.  The argument of the script,
> Logoff,
> > is placed in my log file, since other events get put in that file as
> well.
> >  If I source my script rather than executing it, the argument does not
> get
> > received by my script.
> >
> > I am running ubuntu 9.04
> >
> > This is not a huge problem.  I can create a duplicate of my script which
> has
> > Logoff hard-coded into it.  But I would like to understand why dash does
> not
> > pass the argument when the script is sourced.
> >
> > Is there a way for my script to detect that it is sourced rather than
> > executed?
> >
> > -Denis
> >
> Denis Heidtmann (sorry ... I have been misspelling your name ... sorry)
> To be clear ...
> First, my system
>    does not have any files in the /PostLogin directory
>    does have a Default script in each of the PreSession and PostSession
> directories, but no other files are found there
> Second, I am not sure the Default files you have are exactly like the
> ones I have
>
> However ... assuming they are similar at least ...
>
> gdmwhich () {} ...
> Pre gdmwhich ()  the value of IFS is saved and then set to :
> Then the directories in $PATH are searched for a match to COMMAND (which
> is set to $1)
> If the COMMAND is found and it is executable (test -x) and if the OUTPUT
> is an empty variable (since OUTPUT= the "x$OUTPUT" should be "x")
>    set OUTPUT to be the directory in which COMMAND was found, followed
> by COMMAND (inserting the required /, of course)
> Reset IFS to its old value
> "echo" or return that value of $OUTPUT
>
> So far so good?
>
> Now ... in both my PreSession and PostSession, the PATH is set to
> include $PATH, /bin, and /usr/bin, although in PostSession /usr/bin is
> listed twice (see above in quoted message)
> In my PreSession there is the line ...
>       XSETROOT=`gdmwhich xsetroot`
> ... note that those are the forward single quotes (normally found on the
> '~' key?), which calls the function with the argument xsetroot, setting
> XSETROOT to whatever is returned (echo'd)
>    in other words the value of XSETROOT is whatever directory gdmwhich
> () finds xsetroot in, followed by /, followed by xsetroot - in my case
> that would be /usr/bin/xsetroot - your mileage may vary.
> That does assume that xsetroot is found, of course, otherwise OUTPUT is
> empty.
>
> Does any of that help, or did I miss something?
> Regards
> Fred James


Your explanation does indeed help me understand what gdmwhich() does.
Since my script resides in one of my directories not in the $PATH, I chose
to execute it above the setting of IFS to : using its fully qualified path.
 It executes fine, and does what is intended.  However, if I source my
script rather than execute it, the argument does not get passed.  I am
assuming now that this behavior is normal for dash.  My remedies are 1) to
execute my script in PostSession/default, in which case the argument is
passed as expected, or 2) source a special script which has the argument
hard-coded in it.

To decide which remedy to choose I would like to know why the Debian Policy
states that scripts used should be sourced.  If violating that policy would
cause no problem that would be my choice.  That is what I have set up at
present, and I have noticed no problems.  However, lacking the understanding
of the motivation for the Policy, I cannot be certain that a problem will
not arise.

So, in summary, my original question was: Why does the argument not get
passed with a sourced invocation? (answer: normal behavior of dash).  The
question now is: If I execute a script from PostSession/default will I cause
a problem?

Thanks so much for the effort you  have put in toward my education.

-Denis
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to