MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / getUpdatedLdPreload

Function getUpdatedLdPreload

src/execwrappers.cpp:478–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476}
477
478static string
479getUpdatedLdPreload(const char *filename, const char *currLdPreload)
480{
481 string preload = getenv(ENV_VAR_HIJACK_LIBS);
482
483 bool isElf = false;
484 bool is32bitElf = false;
485
486 if (getenv(ENV_VAR_HIJACK_LIBS_M32) != NULL &&
487 // It should either be a valid script or a valid ELF executable
488 (Util::getInterpreterType(filename, &isElf, &is32bitElf) != -1 ||
489 Util::elfType(filename, &isElf, &is32bitElf) != -1) &&
490 isElf &&
491 is32bitElf) {
492 preload = getenv(ENV_VAR_HIJACK_LIBS_M32);
493 }
494
495 vector<string>pluginLibraries = tokenizeString(preload, ":");
496 for (size_t i = 0; i < pluginLibraries.size(); i++) {
497 // If the plugin doesn't exist, try to search it in the current install
498 // directory.
499 if (!jalib::Filesystem::FileExists(pluginLibraries[i])) {
500 pluginLibraries[i] =
501 Util::getPath(jalib::Filesystem::BaseName(pluginLibraries[i]).c_str(),
502 is32bitElf);
503 }
504 }
505
506 const char *preloadEnv = getenv("LD_PRELOAD");
507 if (currLdPreload != NULL && strlen(currLdPreload) > 0) {
508 pluginLibraries.push_back(currLdPreload);
509 setenv(ENV_VAR_ORIG_LD_PRELOAD, currLdPreload, 1);
510 } else if (preloadEnv != NULL && strlen(preloadEnv) > 0) {
511 pluginLibraries.push_back(preloadEnv);
512 setenv(ENV_VAR_ORIG_LD_PRELOAD, preloadEnv, 1);
513 }
514
515 string newPreload;
516 if (pluginLibraries.size() > 0) {
517 newPreload = pluginLibraries[0];
518 for (size_t i = 1; i < pluginLibraries.size(); i++) {
519 newPreload += ":" + pluginLibraries[i];
520 }
521 }
522
523 return newPreload;
524}
525
526static vector<string>
527copyEnv(char *const envp[])

Callers 1

patchUserEnvFunction · 0.85

Calls 2

tokenizeStringFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected