* setenv and dlopen
@ 2005-10-25 17:52 Henry Margies
2005-10-25 18:20 ` Christoph Bussenius
2005-10-26 14:46 ` Glynn Clements
0 siblings, 2 replies; 4+ messages in thread
From: Henry Margies @ 2005-10-25 17:52 UTC (permalink / raw)
To: linux-c-programming
Hi all,
I have a problem using dlopen and setting the LD_LIBRARY_PATH with
putenv or setenv.
Here is my test code:
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <unistd.h>
int main(int argn, char** argv)
{
void* handle;
int ret;
putenv("LD_LIBRARY_PATH=.");
putenv("PATH=.");
handle = dlopen("libmylib.so", RTLD_LAZY);
if (NULL == handle) {
printf("error: %s\n", dlerror());
}
if (2 == argn)
return 0;
ret = execlp("dltest", "dltest", "break", NULL);
if (ret)
perror("Error in starting dltest: ");
return ret;
}
I also tried setenv and absolute path-names for LD_LIBRARY_PATH. Setting
LD_LIBRARY_PATH on the console works perfectly. And as you can see,
setting the PATH variable using putenv is also working for execlp.
Any suggestions?
Henry
--
Hi! I'm a .signature virus! Copy me into your
~/.signature to help me spread!
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: setenv and dlopen
2005-10-25 17:52 setenv and dlopen Henry Margies
@ 2005-10-25 18:20 ` Christoph Bussenius
2005-10-26 8:21 ` Henry Margies
2005-10-26 14:46 ` Glynn Clements
1 sibling, 1 reply; 4+ messages in thread
From: Christoph Bussenius @ 2005-10-25 18:20 UTC (permalink / raw)
To: Henry Margies; +Cc: linux-c-programming
On Tue, Oct 25, 2005 at 07:52:04PM +0200, Henry Margies wrote:
> Hi all,
Hi Henry,
> I have a problem using dlopen and setting the LD_LIBRARY_PATH with
> putenv or setenv.
I think this is because putenv does not really modify your process'es
environment (which is not possible afaik), but rather remembers the
given variable until you call some exec* function. libc will then pass
the new environment to execve so that the new program will have the
modified environment.
Regards,
Christoph
--
``There's no dark side of the moon, really
Matter of fact, it's all dark''
--Pink Floyd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: setenv and dlopen
2005-10-25 18:20 ` Christoph Bussenius
@ 2005-10-26 8:21 ` Henry Margies
0 siblings, 0 replies; 4+ messages in thread
From: Henry Margies @ 2005-10-26 8:21 UTC (permalink / raw)
To: linux-c-programming
Hi Christoph,
thank you for you answer.
> I think this is because putenv does not really modify your process'es
> environment (which is not possible afaik), but rather remembers the
> given variable until you call some exec* function. libc will then pass
> the new environment to execve so that the new program will have the
> modified environment.
Well, depends on the point of view. For the user-space processes side
the environment values are all stored in char **environ and I can
remove, add and change values. But you are right, the kernel also holds
the original values I cannot change (which are shown
in /proc/PID/environ).
So it seems like execlp uses the local values from char **environ
(because it reads my PATH value) as dlopen uses the kernel version of
the environment variables (and do not know about my changes to
LD_LIBARAY_PATH).
Maybe dlopen runs far beyond my local processes scope and has no access
to my local environment or it just don't care about :-)
Any solutions to tell dlopen within my c program to search also in my
paths?
Greetings,
Henry
--
Hi! I'm a .signature virus! Copy me into your
~/.signature to help me spread!
--
Hi! I'm a .signature virus! Copy me into your
~/.signature to help me spread!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: setenv and dlopen
2005-10-25 17:52 setenv and dlopen Henry Margies
2005-10-25 18:20 ` Christoph Bussenius
@ 2005-10-26 14:46 ` Glynn Clements
1 sibling, 0 replies; 4+ messages in thread
From: Glynn Clements @ 2005-10-26 14:46 UTC (permalink / raw)
To: Henry Margies; +Cc: linux-c-programming
Henry Margies wrote:
> I have a problem using dlopen and setting the LD_LIBRARY_PATH with
> putenv or setenv.
ld-linux.so.2 reads the value into a variable at startup, and uses the
stored value thereafter.
--
Glynn Clements <glynn@gclements.plus.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-10-26 14:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-25 17:52 setenv and dlopen Henry Margies
2005-10-25 18:20 ` Christoph Bussenius
2005-10-26 8:21 ` Henry Margies
2005-10-26 14:46 ` Glynn Clements
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).