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

Function patchUserEnv

src/execwrappers.cpp:575–642  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573}
574
575static vector<string>
576patchUserEnv(const char *env[], const char *filename)
577{
578 vector<string>result;
579 string userPreloadStr;
580
581 ostringstream out;
582 out << "non-DMTCP env vars:\n";
583
584 for (size_t i = 0; env[i] != NULL; i++) {
585 if (isImportantEnv(env[i])) {
586 if (dbg) {
587 out << " skipping: " << env[i] << '\n';
588 }
589 continue;
590 }
591 if (Util::strStartsWith(env[i], "LD_PRELOAD=")) {
592 userPreloadStr = &env[i][strlen("LD_PRELOAD=")];
593 continue;
594 }
595
596 result.push_back(env[i]);
597 if (dbg) {
598 out << " addenv[user]:" << result.back() << '\n';
599 }
600 }
601 JTRACE("Creating a copy of (non-DMTCP) user env vars...") (out.str());
602
603 // pack up our ENV into the new ENV
604 out.str("DMTCP env vars:\n");
605 for (size_t i = 0; i < ourImportantEnvsCnt; ++i) {
606 const char *v = getenv(ourImportantEnvs[i]);
607 const string e = ourImportantEnvs[i];
608 if (e == ENV_VAR_ORIG_LD_PRELOAD && !userPreloadStr.empty()) {
609 result.push_back(e + "=" + userPreloadStr);
610 } else if (v != NULL) {
611 result.push_back(e + '=' + v);
612 if (dbg) {
613 out << " addenv[dmtcp]:" << result.back() << '\n';
614 }
615 }
616 }
617
618 string ldPreloadStr = "LD_PRELOAD=";
619 ldPreloadStr += getUpdatedLdPreload(filename, userPreloadStr.c_str());
620
621 result.push_back(ldPreloadStr);
622
623 /*
624 * The path virtualization plugin tries to set the new prefix env var on
625 * restart. However, for some applications (e.g. bash), setenv() won't affect
626 * the envp area, possibly because the application has its private copy of
627 * the env vars. We need to patch the right env vars before calling execve().
628 * */
629 if (getenv("DMTCP_NEW_PATH_PREFIX")) {
630 string pathVirt = "DMTCP_NEW_PATH_PREFIX=";
631 pathVirt += getenv("DMTCP_NEW_PATH_PREFIX");
632 result.push_back(pathVirt);

Callers 1

dmtcp_execvpeFunction · 0.85

Calls 3

isImportantEnvFunction · 0.85
getUpdatedLdPreloadFunction · 0.85
strMethod · 0.45

Tested by

no test coverage detected