--
Ena Jensen
Hi
The following is an answer, I gave some of my colleagues as they
encountered what I think is the same problem. I hope you can use this,
feel free to ask questions.
I have many times been asked why shell scripts that use the su command
get blocked unexpectedly. First an example:
The script below:
su - ingres -c /bin/true
su - ingres -c /bin/true
Hangs in the "stty dec" command in ~ingres/profile when line 2 is
executed. This happens independently of what shell is used to run the
script.
But if you type the commands at the shell prompt, they wont hang of
course.
The explanation is as follows:
When a Korn shell runs a command from the tty, it assigns a process
group to that command and notifies the tty that that process group is
in the foreground. When the command terminates, the Korn shell makes
its own process group the foreground process group.
When a korn shell runs commands from a script, it does not take any
special measures and of course assumes that the commands do not mess
around with the controlling tty.
However in the script above, the "su -" command starts an
"interactive" shell that makes its own process group owner of the tty.
When this shell exits, the calling shell is supposed to reset the
ownership of the tty. Unfortunately, the caller is a script which does
not do anything.
When the first process exits, a 0 is placed for "foreground process
group", since the process group is dead. The script does not do
anything and the next "su -" command will see itself as being in the
background. The first eg. stty command will hang.
The script below:
su - ingres -c /bin/true
stty echoe
Will also hang in the stty command.
So, Don't use commands that mess around with the controlling tty and
such. If we HAVE TO, make a new tty for each invocation For example
like this:
rsh localhost su - ingres -c /bin/true
rsh localhost su - ingres -c /bin/true
The rsh makes a new pseudotty. It fortunately dies with the command so
we need not care.
When you have to su and make use of the environment, run
su ingres ". ~/.profile; /bin/true"
Yours,
Lars Bro
Received on Tue Jun 09 1998 - 12:55:03 NZST
This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:37 NZDT