Special short-lived processes from executables like /lib/libc.so.6 and man setuid/setgid executables cannot be loaded with LD_PRELOAD. Since they're short-lived, we execute them while holding a lock delaying checkpointing.
| 353 | // Since they're short-lived, we execute them while holding a lock |
| 354 | // delaying checkpointing. |
| 355 | static void |
| 356 | execShortLivedProcessAndExit(const char *path, const char *argv[]) |
| 357 | { |
| 358 | unsetenv("LD_PRELOAD"); // /lib/ld.so won't let us preload if exec'ing lib |
| 359 | const unsigned int bufSize = 100000; |
| 360 | char *buf = (char *)JALLOC_HELPER_MALLOC(bufSize); |
| 361 | memset(buf, 0, bufSize); |
| 362 | FILE *output; |
| 363 | if (argv[0] == NULL) { |
| 364 | output = _real_popen(path, "r"); |
| 365 | } else { |
| 366 | string command = path; |
| 367 | for (int i = 1; argv[i] != NULL; i++) { |
| 368 | command = command + " " + argv[i]; |
| 369 | } |
| 370 | output = _real_popen(command.c_str(), "r"); |
| 371 | } |
| 372 | int numRead = fread(buf, 1, bufSize - 1, output); |
| 373 | numRead++, numRead--; // suppress unused-var warning |
| 374 | buf[bufSize - 1] = '\0'; // NULL terminate in case the last char is not null |
| 375 | |
| 376 | pclose(output); // /lib/libXXX process is now done; can checkpoint now |
| 377 | |
| 378 | // We are now the new /lib/libXXX process, and it's safe for DMTCP to ckpt |
| 379 | // us. |
| 380 | printf("%s", buf); // print buf, which is what /lib/libXXX would print |
| 381 | JALLOC_HELPER_FREE(buf); |
| 382 | |
| 383 | // Avoid running exit handlers of the parent process by calling _exit. |
| 384 | _exit(0); |
| 385 | } |
| 386 | |
| 387 | // FIXME: Unify this code with code prior to execvp in dmtcp_launch.cpp |
| 388 | // Can use argument to dmtcpPrepareForExec() or getenv("DMTCP_...") |
no test coverage detected