/* * 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 monitoring Monitoring a running PyFCGI * * PyFCGI have the ability to listen on a UDP socket, replying to simple * queries (or simple stats). */ #ifndef _MONITOR__H___ #define _MONITOR__H___ #include "config.h" #include /* fcgi library; put it first*/ #include #include #include #include #include #include #define UNIX_SOCKPATH_MAX 108 #define PYFCGI_MONITOR_STREAM_BACKLOG 5 typedef struct pyfcgi_monitor_s pyfcgi_monitor_t; typedef union pyfcgi_monitor_addr_u pyfcgi_monitor_addr_t; #include "conf.h" #include "logger.h" union pyfcgi_monitor_addr_u { struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_un un; }; struct pyfcgi_monitor_s { int sockserv; int sockargs[3]; pyfcgi_monitor_addr_t addr; }; /**@brief Start the stats server monitoring server * @return PID of the child process and -1 on error * @note When called the configuration has to be parsed */ pid_t pyfcgi_spawn_monitor(); /**@brief Main function for socket stats server * * Create the socket & bind to indicated address. If bind fails, sleep 30s, then * exit, in order to retry the whole process */ void pyfcgi_monitor_loop(); void pyfcgi_monitor_stream_loop(); void pyfcgi_monitor_dgram_loop(); /**@brief Check socket URL validity * @param const char* the URL to check * @return -1 if error else 0 * @note Logs error using dprintf(2, ...) because this function will * be called when checking configuration */ int pyfcgi_monitor_check_sock(const char*); /**@brief Parse stored socket URL * @param const char* the URL to parse * @param int[3] socket creation arguments * @param pyfcgi_monitor_addr_t the addr to bind to * @return 0 if no error else -1 * @todo add support for xxx://[IPV6]:port */ int pyfcgi_monitor_parse_sock(const char*, int[3], pyfcgi_monitor_addr_t*); /**@brief Parse an addres:port string in a sockaddr_in * @param const char* the hostname:port string * @param int socket family * @param pyfcgi_monitor_addr_t* the addr pointer * @param int* if not NULL will be set to choosen domain * @return 0 if no erro else -1 * @todo add support for xxx://[IPV6]:port */ int pyfcgi_monitor_parse_inet_addr(const char*, int, pyfcgi_monitor_addr_t*, int*); void pyfcgi_monitor_sighandler(int signum); #endif