mardi 1 septembre 2020

Environment variables from a system() call another program

I'm currently building a daemon in C++ and the children processes are created by a fork() statement. The children are listening incoming events from an Amazon SQS queue, and everything is working fine in the lifetime loop of the processes.

When a new message is read from the queue, the process must execute an external binary (already compiled in c++ with dynamic librairies). The execution of this binary is made by a system(my_binary_path); statement.

The thing is that the binary needs the DYLD_LIBRARY_PATH to be already set in the execution environment but it is not (because the execution is made by the child process and not the current user session).

I already tried to export the DYLD_LIBRARY_PATH env variable directly from the system("export DYLD_LIBRARY_PATH=<path-to-my-dylib-folder>") function. I also tried to set it through the setenv("DYLD_LIBRARY_PATH", <path-to-my-dylib-folder>) function, that didn't work either.

I don't know what's the correct way to set the env variable or make this working with dynamic librairies or if there's any other alternative to execute the external binary.

Thank you for your help in advance.

Aucun commentaire:

Enregistrer un commentaire