Yet Another bourne shell query
Joseph S. D. Yao
jsdy at hadron.COM
Sat Oct 13 01:37:29 AEST 1990
In article <437 at minya.UUCP> jc at minya.UUCP (John Chambers) writes:
>Recently, I've had the fun of modifying programs so they can be started
>by init and/or inetd, and still work. ...
>environ[0] == (char *)0), and with NO open files. ...
>But this causes interesting problems when the "program" is a shell
>script. In C, I know how to call fstat() and test the result for
>zero. In Bourne Shell, I don't know how to do the equivalent. I
>basically want to write something like:
> if [ <file 0 is open> ];then exec</dev/null;fi
With inetd, you should always have 0 and 1 open to the net connection;
no problem.
With init, you are either running out of one of the /etc/rc-type files,
or directly from inittab (assuming a System V-style init). In either
case, my suggestion is to use the Kobiyashi Maru alternative: if you
don't like the rules, change them! When calling the program from init,
explicitly call it:
/etc/my_shell_prog < /dev/null > /dev/null 2>&1
or even
HOME=/ /bin/ksh /etc/my_shell_prog < /dev/null > /dev/null 2>&1
Note that it is nowhere promised that there would be anything IN
environ, or even in argv, merely that they would be there. Program so
as to take into account the worst possibility, and things will usually
work out much better.
Joe Yao jsdy at hadron.COM
( jsdy%hadron.COM@{uunet.UU.NET,decuac.DEC.COM} )
arc,arinc,att,avatar,blkcat,cos,decuac,\
dtix,ecogong,grebyn,inco,insight,kcwc, \
lepton,lsw,netex,netxcom,phw5,research, >!hadron!jsdy
rlgvax,seismo,sms,smsdpg,sundc,telenet, /
uunet /
(Last I counted ...)
More information about the Comp.unix.shell
mailing list