Commit c57d52d2 authored by jan.koester's avatar jan.koester
Browse files

test

parent 6dac39ec
Loading
Loading
Loading
Loading
+5 −34
Changes for src/blogi.cpp: 5 added lines, 34 removed lines.
Original line number Diff line number Diff line
@@ -3546,7 +3546,6 @@ void blogi::Blogi::ResponseEvent(libhttppp::HttpRequest &curreq, const int tid,
// Binds the server socket(s) without starting the event loop.
// Used by the supervisor in pre-fork mode so the fd is inherited by all
// domain worker children before they diverge into separate processes.
#ifndef __WIN32
class HttpConDPreFork : public libhttppp::HttpD
{
public:
@@ -3559,13 +3558,8 @@ public:
                blogi::Blogi::Cfg->getsslpassword())
    {
        blogi::Blogi::HttpServer = this;
        for (auto* s : getServerSockets()) {
            s->bind();
            s->listen();
        }
    }
};
#endif

class HttpConD : public libhttppp::HttpD
{
@@ -4291,6 +4285,7 @@ int _tmain(int argc, TCHAR *argv[])
                    GetModuleFileNameW(NULL, exePath, MAX_PATH);

                    std::vector<HANDLE> workerHandles(domainCount, INVALID_HANDLE_VALUE);
                    std::vector<DWORD>  workerDomains(domainCount);

                    auto spawnWorker = [&](size_t d) -> HANDLE
                    {
@@ -4306,42 +4301,18 @@ int _tmain(int argc, TCHAR *argv[])
                        std::vector<wchar_t> cmdBuf(cmdLine.begin(), cmdLine.end());
                        cmdBuf.push_back(L'\0');

                        // Use chrootDir as working directory for filesystem isolation.
                        LPCWSTR lpDirectory = NULL;
                        std::wstring wChrootDir;
                        const std::string &chrootDir =
                            blogi::Blogi::Cfg->getDomainConfig(d).chrootDir;
                        if (!chrootDir.empty())
                        {
                            wChrootDir.assign(chrootDir.begin(), chrootDir.end());
                            lpDirectory = wChrootDir.c_str();
                        }

                        if (!CreateProcessW(NULL, cmdBuf.data(), NULL, NULL,
                                            FALSE, 0, NULL, lpDirectory, &si, &pi))
                                            FALSE, 0, NULL, NULL, &si, &pi))
                            return INVALID_HANDLE_VALUE;

                        // Assign to a Job Object so the worker is killed when the
                        // supervisor exits (KILL_ON_JOB_CLOSE).
                        HANDLE hJob = CreateJobObjectW(NULL, NULL);
                        if (hJob != NULL)
                        {
                            JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = {};
                            jeli.BasicLimitInformation.LimitFlags =
                                JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
                            SetInformationJobObject(hJob,
                                                    JobObjectExtendedLimitInformation,
                                                    &jeli, sizeof(jeli));
                            AssignProcessToJobObject(hJob, pi.hProcess);
                            CloseHandle(hJob);
                        }

                        CloseHandle(pi.hThread);
                        return pi.hProcess;
                    };

                    for (size_t d = 0; d < domainCount; ++d)
                    {
                        workerDomains[d] = (DWORD)d;
                        workerHandles[d] = spawnWorker(d);
                    }

                    // Supervisor watchdog: restart crashed workers.
                    while (true)