Hacker News new | ask | show | jobs
by dmytroi 943 days ago
Mostly integration, for example some library can only be configured via env variables, but a developer might want to configure it from with-in the app it's integrated into and used from.

Also, few weeks ago I found a use for them when trying to pass configuration from Java/Kotlin to C++ library to be used during static constructors (invoked during dlopen) on Android, because at that phase native code cannot call back to JVM.

1 comments

> for example some library can only be configured via env variables

library has already loaded when you call setenv, so what you're saying doesn't work in most cases.

It seems to be a need to use poorly written libraries. You might consider fixing them instead.

I agree that would be a poor implementation, but the library could be loaded at runtime using dlopen or equivalent.

This issue with that “interface” is the environment is process global. If the library is being loaded dynamically (specifically for some task) it would seem that the parameters are local to that task and should be taken by some reentrent init method. Alternatively, the process could be forked and environment set in the child without concern for thread safety or polluting the environment (think of the children!).

The only library I've seen to use env vars is libc, which uses them to decide how malloc should behave for example.
Some libraries behaviour/API can be tweaked with env var. env var are read at runtime not loading time.
Can you link one such library here?