tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: ejensen5 () csc ! com
To: tru64-unix-managers
Subject: SUMMARY: su -c error in DU 4.0B
Date: Tue, 09 Jun 1998 10:55:15 +0000	[thread overview]
Message-ID: <96078712011531.tru64-unix-managers.marc@archive.invalid> (raw)


Original:

this little script hangs my terminal:
   su - -c who
   print hit a key to Return
   read DUMMY

Answer:

It seems to be a Ksh-problem, the answer from Lars Bro included at buttom.


Work-arounds:

print -n Password:
su - -c who 2>/dev/null
print hit a key to Return
read DUMMY

or

rsh localhost su - -c who
print hit a key to Return
read DUMMY


Thanks to:

prageeth@xko.dec.com
sxdjd@ts.sois.alaska.edu
Mandell.Degerness@gems2.gov.bc.ca
lbro@dscc.dk


--
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

                 reply	other threads:[~1998-06-09 10:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox