[Xquartz-dev] 2.3.2_rc4
Cameron Simpson
cs at zip.com.au
Fri Dec 19 13:57:14 PST 2008
On 19Dec2008 08:17, Martin Costabel <costabel at wanadoo.fr> wrote:
> Cameron Simpson wrote:
>> On 19Dec2008 00:37, Martin Costabel <costabel at wanadoo.fr> wrote:
>>> I think the following works (does for me, anyway, but I haven\t
>>> tested it extensively):
>>> #!/bin/sh
>>> /usr/bin/login -pqf $USER <<EOF
>>> $*
>>> EOF
>>
>> Please no. That completey mangles the command line if any of the
>> app command line arguments have spaces.
>
> Which app command line arguments are you talking about? I am targeting
> specifically the startup procedure of X11 on Mac OS X Leopard, where the
> command corresponding to $* in the above is typically something like
>
> /Applications/Utilities/X11.app/Contents/MacOS/X11.bin -psn_0_716975
Maybe, it just grates to see something non-robust deployed.
Wrapper script (and the above _is_ a wrapper script) should preserve
their caller's arguments perfectly, not rely on the arguments typically
being what they expect.
> Do you have another suggestion how to fix Jeremy's current approach to
> starting X11 on Leopard, so that it works for users who have tcsh as
> their login shell?
Yep. [...]
>>> I wonder how Terminal.app is doing this. After all, it manages to
>>> start a login shell for everybody.
>>
>> Historically, if a shell is started with the first character of argv[0]
>> supplied as a dash then it runs as a login shell. That's how the magic
>> used to work; that way the caller doesn't need special per-shell
>> knowledge.
>
> How do you get that "-" into argv[0]? Are you suggesting that one should
> write a wrapper in C instead of a shell script?
I used to do exactly that (not for login shells but for something else). It's
a tiny program and handy. However, it seems the login(1) command lets us
avoid that anyway, so...
What's wrong with this?
#!/bin/bash
: ${USER:=`id -un`}
: ${SHELL:=/bin/sh}
qcmd=
for arg
do qcmd=$qcmd`printf " %q" "$arg"`
done
exec /usr/bin/login -pqf "$USER" "$SHELL" -c "$qcmd"
(That's bash instead of sh purely to use the %q printf extension.)
It correctly preserves command line strings while still using your
/usr/bin/login incantation to obtain the environment in a shell
independent manner.
It does rely on the shell accepting the -c command line option, but all
shells do that as otherwise they can't be used by programs with shell
escapes that hand off to the user's shell.
Comments?
>> Are we not spending a lot of effort in the wrong place?
>
> That may well be the case, but I don't see anyone spending any effort on
> rewriting once again the whole startup procedure for X11 on Leopard.
Surely we're doing that right now:-)
Cheers,
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
... It beeped and said "Countdown initiated." Is that bad?
More information about the Xquartz-dev
mailing list