void PlatformLauncher::onExit()

in src/main/cpp/bootstrap/platformlauncher.cpp [669:735]


void PlatformLauncher::onExit() {
    logMsg("onExit()");
    if (exitStatus == -252) {
        logMsg("Exiting from CLI client, will not restart.");
        return;
    }
    
    if (exiting) {
        logMsg("Already exiting, no need to schedule restart");
        return;
    }
    
    exiting = true;

    if (separateProcess) {
        logMsg("JVM in separate process, no need to restart");
        return;
    }

    bool restart = (nextAction == ARG_NAME_LA_START_APP || (nextAction == ARG_NAME_LA_START_AU && shouldAutoUpdateClusters(false)));
    if (!restart && restartRequested()) {
        restart = true;
        nextAction = ARG_NAME_LA_START_APP;
    }

    if (restart) {
        string cmdLine = GetCommandLine();
        logMsg("Old command line: %s", cmdLine.c_str());
        string::size_type bslashPos = cmdLine.find_last_of('\\');
        string::size_type pos = cmdLine.find(ARG_NAME_LA_START_APP);
        if ((bslashPos == string::npos || bslashPos < pos) && pos != string::npos) {
            cmdLine.erase(pos, strlen(ARG_NAME_LA_START_APP));
        }
        pos = cmdLine.find(ARG_NAME_LA_START_AU);
        if ((bslashPos == string::npos || bslashPos < pos) && pos != string::npos) {
            cmdLine.erase(pos, strlen(ARG_NAME_LA_START_AU));
        }

        if (*cmdLine.rbegin() != ' ') {
            cmdLine += ' ';
        }
        if (!parentProcID.empty() && cmdLine.find(ARG_NAME_LA_PPID) == string::npos) {
            cmdLine += ARG_NAME_LA_PPID;
            cmdLine += ' ';
            cmdLine += parentProcID;
        }

        if (*cmdLine.rbegin() != ' ') {
            cmdLine += ' ';
        }
        cmdLine += nextAction;

        logMsg("New command line: %s", cmdLine.c_str());
        char cmdLineStr[32 * 1024] = "";
        strcpy(cmdLineStr, cmdLine.c_str());
        STARTUPINFO si = {0};
        PROCESS_INFORMATION pi = {0};
        si.cb = sizeof(STARTUPINFO);

        if (!CreateProcess(NULL, cmdLineStr, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) {
            logErr(true, true, "Failed to create process.");
            return;
        }
        CloseHandle(pi.hThread);
        CloseHandle(pi.hProcess);
    }
}