123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- /*
- * 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 <http://www.gnu.org/licenses/>.
- */
-
- /**@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 <fcgiapp.h> /* fcgi library; put it first*/
-
- #include <netdb.h>
- #include <strings.h>
- #include <sys/socket.h>
- #include <sys/un.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
-
- #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"
- #include "stats.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 sockcli;
- int sockargs[3];
- pyfcgi_monitor_addr_t addr;
-
- };
-
- /**@brief Attempt to init unitialized IPC component
- *
- * If an error occured it will be logged, and the init should be retry latter.
- *
- * @note the monitor process uses IPC_WREQS to count requests IPC_SEMST for
- * SHM syn and IPC_SHMST for SHM initalization
- */
- int pyfcgi_monitor_IPC_init();
-
- /**@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);
- void pyfcgi_monitor_timeout(int signum);
-
- #endif
|