Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

monitor.h 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2019 Weber Yann
  3. *
  4. * This file is part of PyFCGI.
  5. *
  6. * PyFCGI is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * PyFCGI is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**@defgroup monitoring Monitoring a running PyFCGI
  20. *
  21. * PyFCGI have the ability to listen on a UDP socket, replying to simple
  22. * queries (or simple stats).
  23. */
  24. #ifndef _MONITOR__H___
  25. #define _MONITOR__H___
  26. #include "config.h"
  27. #include <fcgiapp.h> /* fcgi library; put it first*/
  28. #include <netdb.h>
  29. #include <strings.h>
  30. #include <sys/socket.h>
  31. #include <sys/un.h>
  32. #include <netinet/in.h>
  33. #include <arpa/inet.h>
  34. #define UNIX_SOCKPATH_MAX 108
  35. typedef struct pyfcgi_monitor_s pyfcgi_monitor_t;
  36. typedef union pyfcgi_monitor_addr_u pyfcgi_monitor_addr_t;
  37. #include "conf.h"
  38. #include "logger.h"
  39. union pyfcgi_monitor_addr_u
  40. {
  41. struct sockaddr_in in;
  42. struct sockaddr_in6 in6;
  43. struct sockaddr_un un;
  44. };
  45. /**@brief Local structure storing monitor process informations */
  46. struct pyfcgi_monitor_s
  47. {
  48. /**@brief Socket fd */
  49. int sock_serv;
  50. /**@brief domain type & protocol */
  51. int sock_args[3];
  52. /**@brief Address to bind to */
  53. pyfcgi_monitor_addr_t addr;
  54. };
  55. /**@brief Start the stats server monitoring server
  56. * @return PID of the child process and -1 on error
  57. * @note When called the configuration has to be parsed */
  58. pid_t pyfcgi_spawn_monitor();
  59. void pyfcgi_monitor_init();
  60. void pyfcgi_monitor_loop();
  61. /**@brief Check socket URL validity
  62. * @param const char* the URL to check
  63. * @return -1 if error else 0
  64. * @note Logs error using dprintf(2, ...) because this function will
  65. * be called when checking configuration
  66. */
  67. int pyfcgi_monitor_check_sock(const char*);
  68. /**@brief Parse stored socket URL
  69. * @param const char* the URL to parse
  70. * @param int[3] socket creation arguments
  71. * @param pyfcgi_monitor_addr_t the addr to bind to
  72. * @return 0 if no error else -1
  73. */
  74. int pyfcgi_monitor_parse_sock(const char*, int[3], pyfcgi_monitor_addr_t*);
  75. /**@brief Parse an addres:port string in a sockaddr_in
  76. * @param const char* the hostname:port string
  77. * @param int socket family
  78. * @param pyfcgi_monitor_addr_t* the addr pointer
  79. * @param int* if not NULL will be set to choosen domain
  80. * @return 0 if no erro else -1
  81. */
  82. int pyfcgi_monitor_parse_inet_addr(const char*, int, pyfcgi_monitor_addr_t*, int*);
  83. #endif