| 472 | } |
| 473 | |
| 474 | void |
| 475 | startNewCoordinator(CoordinatorMode mode) |
| 476 | { |
| 477 | string host = ""; |
| 478 | int port = UNINITIALIZED_PORT; |
| 479 | getCoordHostAndPort(mode, &host, &port); |
| 480 | |
| 481 | JASSERT(strcmp(host.c_str(), "localhost") == 0 || |
| 482 | strcmp(host.c_str(), "127.0.0.1") == 0 || |
| 483 | jalib::Filesystem::GetCurrentHostname() == host.c_str()) |
| 484 | (host) (jalib::Filesystem::GetCurrentHostname()) |
| 485 | .Text("Won't automatically start coordinator because DMTCP_HOST" |
| 486 | " is set to a remote host."); |
| 487 | |
| 488 | // Create a socket and bind it to an unused port. |
| 489 | errno = 0; |
| 490 | jalib::JServerSocket coordinatorListenerSocket(jalib::JSockAddr::ANY, |
| 491 | port, 128); |
| 492 | JASSERT(coordinatorListenerSocket.isValid()) |
| 493 | (coordinatorListenerSocket.port()) (JASSERT_ERRNO) (host) (port) |
| 494 | .Text("Failed to create socket to connect to coordinator port." |
| 495 | "\n If the above message (sterror) is:" |
| 496 | "\n \"Address already in use\" or \"Bad file descriptor\"," |
| 497 | "\n then this may be an old coordinator." |
| 498 | "\n Or maybe you're joining an existing coordinator, and forgot" |
| 499 | "\n to use 'dmtcp_launch --join-coordinator'." |
| 500 | "\n Either:" |
| 501 | "\n (a) use '--join-coordinator; or" |
| 502 | "\n (b) kill the old coordinator with 'pkill -9 dmtcp_coord' or" |
| 503 | "\n (while using same host and port):" |
| 504 | "\n dmtcp_command ---coord-host XX --coord-port YY --quit; or" |
| 505 | "\n (c) if the old coordinator is already gone, wait a few seconds" |
| 506 | "\n or a minute for the O/S to free up that port again.\n"); |
| 507 | // Now dup the sockfd to |
| 508 | coordinatorListenerSocket.changeFd(PROTECTED_COORD_FD); |
| 509 | setCoordPort(coordinatorListenerSocket.port()); |
| 510 | |
| 511 | JTRACE("Starting a new coordinator automatically.") |
| 512 | (coordinatorListenerSocket.port()); |
| 513 | |
| 514 | if (fork() == 0) { |
| 515 | /* NOTE: This code assumes that dmtcp_launch (the current program) |
| 516 | * and dmtcp_coordinator are in the same directory. Namely, |
| 517 | * GetProgramDir() gets the dir of the current program (dmtcp_launch). |
| 518 | * Hence, if dmtcp_coordinator is in a different directory, then |
| 519 | * jalib::Filesystem::GetProgramDir() + "/dmtcp_coordinator" |
| 520 | * will not exist, and the child will fail. |
| 521 | */ |
| 522 | // We can't use Util::getPath() here since the SharedData has not been |
| 523 | // initialized yet. |
| 524 | string coordinator = |
| 525 | jalib::Filesystem::GetProgramDir() + "/dmtcp_coordinator"; |
| 526 | |
| 527 | char *modeStr = (char *)"--daemon"; |
| 528 | char *args[] = { |
| 529 | (char *)coordinator.c_str(), |
| 530 | (char *)"--quiet", |
| 531 |
no test coverage detected