/* * Copyright (C) 2019 Weber Yann * * This file is part of PyFCGI. * * PyFCGI is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * PyFCGI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with PyFCGI. If not, see . */ /**@defgroup work_master_proc Worker handler process * @brief This process use the @ref responder_loop() function as "main" function * * @section work_master_spawn Spawning workers * This subprocess handle worker spawning using @ref spawn(). A POSIX semaphore * allow to know when the worker pool is idle or not : * * @subsection work_master_spawn_sem Semaphore idle & busy detection * When a new worker is ready (idle) it add 1 to the semaphore, when processing * a request it substract 1 to the semaphore (done in @ref work() function in * @ref worker_process ) * * When semtimedop blocks on wait_for_zero operation it means that the pool is * idle. Instead, if the semtimedop returns imediately it means a new worker * can be spawned. * * @ingroup processes * @ingroup main_proc */ /**@file responder.h * @ingroup work_master_proc */ #ifndef _RESPONDER__H___ #define _RESPONDER__H___ #include "config.h" #include /* fcgi library; put it first*/ #include #include #include #include #include #include #include #include #include #include "logger.h" #include "pyworker.h" void init_context(); /**@brief Start a new pool_handler process * @return the new PID or -1 if error */ pid_t spawn_pool_handler(); /**@brief The responder loop * @ingroup work_master_proc * The main function of the fcgi app fork child * @param int max_requests : exit normally after this number of requests. If * 0 given never exit. * @param char* python_entrymodule a python module name * @param char* python_entrymodule a python callable name from entry module * @param unsigned int max_requests before exiting worker * @param unsigned int minimum workers count * @param unsigned int maximum wrokers count * @return 0 on success */ int responder_loop(); /**@brief Spawn a worker given an entrypoint * @ingroup work_master_proc * Spawn a new worker process and prepare ENV & request forwarding * @param int worker uid * @return child PID */ pid_t spawn(int); /**@deprecated Not used */ int pyfcgi_pool_state(); /**@brief Check if the pool is idle : if not able to timedwait the pool is busy * @param const struct timespec timeout * @return 1 if busy else 0 * @note exit on error */ int pyfcgi_pool_idle(const struct timespec *timeout); /**@brief Handle signals and forward it to workers */ void pool_sighandler(int signum); /**@brief Handle watchdog alarm signal */ void pool_wd_sighandler(int signum); #endif