🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1482

Re: Yet Another bourne shell query

#1482
From: Joseph S. D. Yao
Date: Fri, 12 Oct 1990 15:37
35 lines
2002 bytes
In article <437@minya.UUCP> jc@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@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 ...)
Technical Details
Message-ID: <915@hadron.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cos!hadron!jsdy
References: <437@minya.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cos!hadron!jsdy
From: jsdy@hadron.COM (Joseph S. D. Yao)
Newsgroups: comp.unix.shell
Subject: Re: Yet Another bourne shell query
Message-ID: <915@hadron.COM>
Date: 12 Oct 90 15:37:29 GMT
References: <437@minya.UUCP>
Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao)
Organization: Hadron, Inc., Fairfax, VA
Lines: 35