setenv from C

Hi all,
following problem:
i would set via little background proggi any ENV-vars
…sev
#include <stdio.h>
#include <time.h>
#include <env.h>

void main(void);
void main(void)
{
time_t start,now;
char buffer[80]=“00000 sec”;
int rc;
start=time(NULL);
while(1)
{
now=time(NULL);
sprintf(buffer,"%d sec",now-start);
rc=setenv(“UP_TIME”,buffer,1);
// printf("\rsetenv:%s rc:%d “,buffer,rc);
// printf (”\t\t\t getenv:%s",getenv(“UP_TIME”));
sleep(1);
}
}

/etc/config/sysinit.1


export UP_TIME=0
sev &

the proggi is running, but i can’t see the changing of UP_TIME

#echo $UP_TIME

if i uncomment the printf lines , i can see the setenv is the same like
getenv.
what can i do



\


Joerg Hering
Chief Developer VDR
e-mail: jhering@avecs-bergen.de
privat: hering.ruegen@t-online.de
mobile: jhering.ruegen@gmx.de

AVECS Bergen GmbH
development department
Billrothstraße 11a
D-18528 Bergen auf Rügen

Tel.: +49 3838 2119101
Fax: +49 3838 2119105
Mobile: +49 172 3896974
URL: http://www.avecs-bergen.de


Jörg Hering wrote:

Hi all,
following problem:
i would set via little background proggi any ENV-vars
…sev
#include <stdio.h
#include <time.h
#include <env.h

void main(void);
void main(void)
{
time_t start,now;
char buffer[80]=“00000 sec”;
int rc;
start=time(NULL);
while(1)
{
now=time(NULL);
sprintf(buffer,"%d sec",now-start);
rc=setenv(“UP_TIME”,buffer,1);
// printf("\rsetenv:%s rc:%d “,buffer,rc);
// printf (”\t\t\t getenv:%s",getenv(“UP_TIME”));
sleep(1);
}
}
… /etc/config/sysinit.1
.
.
export UP_TIME=0
sev &
.
.

the proggi is running, but i can’t see the changing of UP_TIME

#echo $UP_TIME

if i uncomment the printf lines , i can see the setenv is the same like
getenv.
what can i do

Re-write sev to simply printf("%dn sec", now-start), then in your sysinit:



export UP_TIME="$(sev)"


Rennie

Rennie Allen <rallen@csical.com> wrote:

Re-write sev to simply printf("%dn sec", now-start), then in your sysinit:
.
.
.
export UP_TIME="$(sev)"
.
.

I will add, a process’s evironment can not be modified by its child.
When you create a new program, even a shell, it can not possibly
add something to its parent’s environment. (I know same thing said,
but in a different way).

That is why the . command in the shell can be so usefull, it will
execute the commands in the current shell, where just running a
script will cause a new shell, example

[thomas@elmo] /home/thomas >cat > test_script
export st=tuesday
[thomas@elmo] /home/thomas >chmod +x test_script
[thomas@elmo] /home/thomas >set | grep st
[thomas@elmo] /home/thomas >./test_script
[thomas@elmo] /home/thomas >set | grep st
[thomas@elmo] /home/thomas >. ./test_script
[thomas@elmo] /home/thomas >set | grep st
st=tuesday
[thomas@elmo] /home/thomas >

Just standard Un*x.

regards,
Tom