Operating System - HP-UX
1823088 Members
3239 Online
109646 Solutions
New Discussion юеВ

putenv() in child process

 
Sup
Advisor

putenv() in child process

I have code something like this which is executed when different options selected from
X-motif GUI. The testme never startes. If I remove putenv then it works, Any thoughts..

if ((pid = fork()) == 0)
{
if ( strcmp(app,"testme") == 0 )
putenv(localTZ);
setpgrp();
if ( strcmp(app,"testme") == 0 )
execlp(path, app,"-26", (char *) 0);
else
execlp(path, app,(char *) 0);
_exit(1);
}
2 REPLIES 2
Caesar_3
Esteemed Contributor

Re: putenv() in child process

Hello!

Maybe the change of timezone, the fork start to work difrent because of the changes in time.

Caesar
A. Clay Stephenson
Acclaimed Contributor

Re: putenv() in child process

Best guess because not enough code is visible:

localTZ is an auto decalared variable that has gone out of scope because of a function exit. Move localTZ out to file scope or dynamically allocate it but don't free it.

If you are doing something like this:

int bad_myenv(char *tz)
{
int cc = 0;
char localTZ[128];

(void) sprintf(local_TZ,"TZ=%s",tz);
cc = putenv(localTZ);
return(cc)
} /* bad_myenv */

Change it to:


int good_myenv(char *tz)
{
int cc = 0;
static char localTZ[128];

(void) sprintf(local_TZ,"TZ=%s",tz);
cc = putenv(localTZ);
return(cc)
} /* good_myenv */

OR

static char localTZ[128];

int good_myenv2(char *tz)
{
int cc = 0;

(void) sprintf(local_TZ,"TZ=%s",tz);
cc = putenv(localTZ);
return(cc)
} /* good_myenv2 */
If it ain't broke, I can fix that.