| 476 | } |
| 477 | |
| 478 | static string |
| 479 | getUpdatedLdPreload(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 | |
| 526 | static vector<string> |
| 527 | copyEnv(char *const envp[]) |
no test coverage detected