1830900 Members
3242 Online
110017 Solutions
New Discussion

inetd and $PATH variable

 
Sup
Advisor

inetd and $PATH variable

Hi ALL,

We are using inetd to start a server process.
This server process will fork() and create a child process. If I print $PATH in child process, it is empty :- (. Any idea?
9 REPLIES 9
harry d brown jr
Honored Contributor

Re: inetd and $PATH variable

One reason one should always include the full path to what they want to execute.


ie:
/usr/sbin/ping

instead of
ping

live free or die
harry
Live Free or Die
A. Clay Stephenson
Acclaimed Contributor

Re: inetd and $PATH variable

Inetd has TZ and LANG defined along with umask. The other components of the environment of the started server are completely up to the application developer.
If it ain't broke, I can fix that.
John Meissner
Esteemed Contributor

Re: inetd and $PATH variable

Sup - could your provide a little more info as to what you're starting and what the child is and why you would need to print $PATH from the child?
I think I may know why... but would like some more info
All paths lead to destiny
John Meissner
Esteemed Contributor

Re: inetd and $PATH variable

so What you're saying Clay is that he should state his path in the script or child....
i.e.
#script starts
PATH=$PATH:/bla/bla:/bla/bal
#rest of script
All paths lead to destiny
A. Clay Stephenson
Acclaimed Contributor

Re: inetd and $PATH variable

No,

Because this is c, he need to do a series of putenv() function calls.

e.g.
putenv("PATH=/usr/bin:/usr/local/bin");

This would apply to all environemnt variables not just PATH.

The programmer must also take care that the string arguments supplied to putenv() do not go "out of scope" and thus become undefined. Subsequent references to the env vars then result in absolute chaos.
If it ain't broke, I can fix that.
Sup
Advisor

Re: inetd and $PATH variable

The program started is C program. When inetd
started, will it have any value for PATH variable ? Will it inherit PATH set to root user ? like for Ex:

PATH=/usr/bin:/usr/local/bin

If it is, i guess process started by inetd will inherit the PATH variable values and child process or child's child process will have same value for PATH as above.

In my case I am not assigning any value to PATH
variable. I want to use existing value but nothing is assigned to PATH. It is BLANK?
I will check by restarting inetd.

Thanx


Sup
Advisor

Re: inetd and $PATH variable

In Solaris I get PATH=/usr/bin:/usr/sbin
A. Clay Stephenson
Acclaimed Contributor

Re: inetd and $PATH variable

You don't get a blank PATH, you get a NULL PATH. Let me try again: inetd ONLY exports
TZ and LANG - everything else is NULL.

If you want PATH (or anything else) set then you, the programmer, must explicitly set it either in your parent before the fork() or in the child.
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: inetd and $PATH variable

HP-UX keeps the default PATH in a file: /etc/PATH and this can be used to establish a PATH for the application program. However, for security reasons, I would never assume that the environment is inherently safe or complete so I would explicitly call putenv() for every value needed for the program. This would make the program both portable and secure, regardless as to how it was started.


Bill Hassell, sysadmin