1832089 Members
3086 Online
110037 Solutions
New Discussion

INETD and environment

 
Rodger Williams
New Member

INETD and environment

When I run a C program main(argc, **arcv, **environ)from INETD (tcp), I find
that getenv() returns no env vars, and I cannot set env vars using putenv() or
env(). For example,
system("putenv SYBASE=/usr/Syb11.3");
fprintf(log_file, "SybPath: %s\n", getenv("SYBASE"); .

How do I set/get env vars from a process running via tcp INETD?
3 REPLIES 3
Juha Laiho
New Member

Re: INETD and environment

I the lack of environment variables is intentional;
you will have to set up your own PATH and such instead
of relying whatever is there.

As to why the 'system("putenv SYBASE=/usr/Syb11.3");'
fails for you is that there you create a new shell
process (see system(3) manual page) and set the
environment variable in there. As environment
variables are not inherited from a child process to
the parent, the effect of "putenv" ends as soon as
the subsequent shell exits (and the system() call returns).

To set an environment variable in the current process
(and to be inherited by child processes) you'll need
to call the putenv() function call directly without
an intervening shell:
putenv("SYBASE=/usr/Syb11.3");

Hope this helps,
..Juha
Rodger Williams
New Member

Re: INETD and environment

You're right about inheiritance, but the problem I'm having is that within a
process (main()) that's called by INETD, I am unable to successfully set
environment variables, such as by reading my .profile or by using setenv(). If
INETD calls a shell and then I spawn a child process, I can no longer pass data
to/from the client, so INETD must call main() directly.

Thanks, Rodger
Rodger Williams
New Member

Re: INETD and environment

My apologies to Mr. Laiho for not reading his email carefully enough before I
responded. Calling setenv() directly from main() does work. Thanks for the
help!

Rodger