HP3000-L Archives

November 2000, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Gavin Scott <[log in to unmask]>
Reply To:
Gavin Scott <[log in to unmask]>
Date:
Tue, 21 Nov 2000 09:25:47 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (40 lines)
Gary writes:

> Although it does not solve the more general issue with calling intrinsics
> from gcc, the easiest and most portable way of getting environment
> variables is to use getenv():
>
> #include <stdlib.h>

> char *sysname = getenv("HPSYSNAME");

A good suggestion and one which will work perfectly in the current case, but
remember that the C 'environment' is static and inherited from process to
process.  When asked to retrieve an MPE VARIABLE, it will give you the value
that was recorded at the start time of the first "Posix" process in the
process tree, and not the current value of the variable.

So if you're getting something static like HPSYSNAME, this will work fine.
If you want something that changes dynamically, then you'll have to call
HPCIGETVAR (or eqivalent).

The C/Posix "environment" consists of an array of pointers to null
terminated strings that is local to each process.  When you "exec" a new
program, you can choose to have your environment retained by the new program
or you can specify a new 'environment' to be used by that process.

When you run a Posix/C program via :RUN/CREATEPROCESS rather than fork/exec,
then there is no place to inherit the old environment from, so what happens
at that point (IIRC) is that the C runtime startup will notice this and will
use HPCIGETVAR to load up all of the then current values of your MPE
variables to create the initial environment.

Once the first Posix program runs and loads up the environment in this way,
the same values will be inherited by any Posix program that is started via
the Posix 'exec' functions.  Typically the first Posix program that is run
is the Posix Shell, and all of the commands and programs run after that will
thus see the values of the MPE variables from the time that the user entered
the shell and not the current values.

G.

ATOM RSS1 RSS2