FIXME: Unify this code with code prior to execvp in dmtcp_launch.cpp Can use argument to dmtcpPrepareForExec() or getenv("DMTCP_...") from DmtcpWorker constructor, to distinguish the two cases.
| 388 | // Can use argument to dmtcpPrepareForExec() or getenv("DMTCP_...") |
| 389 | // from DmtcpWorker constructor, to distinguish the two cases. |
| 390 | static void |
| 391 | dmtcpPrepareForExec(const char *path, |
| 392 | const char *argv[], |
| 393 | const char **filename, |
| 394 | const char ***newArgv) |
| 395 | { |
| 396 | JTRACE("Preparing for Exec") (path); |
| 397 | |
| 398 | const char *libPrefix = "/lib/lib"; |
| 399 | const char *lib64Prefix = "/lib64/lib"; |
| 400 | if (path != NULL && Util::strStartsWith(path, libPrefix)) { |
| 401 | execShortLivedProcessAndExit(path, argv); |
| 402 | } |
| 403 | if (path != NULL && Util::strStartsWith(path, lib64Prefix)) { |
| 404 | execShortLivedProcessAndExit(path, argv); |
| 405 | } |
| 406 | |
| 407 | // Needed for /usr/libexec/utempter/utempter and other short-lived |
| 408 | // setuid/setgid processes. |
| 409 | // FIXME: USE THIS FOR ALL setuid/setgid PROCESSES EXCEPT ONES THAT |
| 410 | // WE DIRECTLY HANDLE, LIKE 'screen'. (Need to name special routine, |
| 411 | // execScreenProcess() ??) |
| 412 | if (path != NULL && Util::strEndsWith(path, "/utempter")) { |
| 413 | JTRACE("Trying to exec: utempter")(path)(argv[0])(argv[1]); |
| 414 | string realPtsNameStr; |
| 415 | |
| 416 | // utempter takes a pts slave name as an argument. Since we virtualize |
| 417 | // ptys, the slave name points to a virtual slave name, thus we need to |
| 418 | // replace it with the real one. |
| 419 | for (size_t i = 0; argv[i] != NULL; i++) { |
| 420 | if (Util::strStartsWith(argv[i], VIRT_PTS_PREFIX_STR)) { |
| 421 | // FIXME: Potential memory leak if exec() fails. |
| 422 | char *realPtsNameStr = (char *)JALLOC_HELPER_MALLOC(PTS_PATH_MAX); |
| 423 | SharedData::getRealPtyName(argv[i], realPtsNameStr, |
| 424 | PTS_PATH_MAX); |
| 425 | |
| 426 | // Override const restriction |
| 427 | argv[i] = realPtsNameStr; |
| 428 | } |
| 429 | } |
| 430 | execShortLivedProcessAndExit(path, argv); |
| 431 | } |
| 432 | |
| 433 | // FIXME: SEE COMMENTS IN dmtcp_launch.cpp, rev. 1087; AND CHANGE THIS. |
| 434 | if (path != NULL && Util::isSetuid(path)) { |
| 435 | if (Util::isScreen(path)) { |
| 436 | Util::setScreenDir(); |
| 437 | } |
| 438 | |
| 439 | // THIS NEXT LINE IS DANGEROUS. MOST setuid PROGRAMS CAN'T RUN UNPRIVILEGED |
| 440 | Util::patchArgvIfSetuid(path, argv, newArgv); |
| 441 | |
| 442 | // BUG: Util::patchArgvIfSetuid() DOES NOT SET newArgv WHEN COPYING |
| 443 | // BINARY IN CODE RE-FACTORING FROM REVISION 911. |
| 444 | *filename = (*newArgv)[0]; |
| 445 | } else { |
| 446 | *filename = (char *)path; |
| 447 | *newArgv = argv; |
no test coverage detected