ap_mpm.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. { Copyright 1999-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. //#include "apr_thread_proc.h"
  17. {
  18. * @package Multi-Processing Module library
  19. }
  20. {
  21. The MPM, "multi-processing model" provides an abstraction of the
  22. interface with the OS for distributing incoming connections to
  23. threads/process for processing. http_main invokes the MPM, and
  24. the MPM runs until a shutdown/restart has been indicated.
  25. The MPM calls out to the apache core via the ap_process_connection
  26. function when a connection arrives.
  27. The MPM may or may not be multithreaded. In the event that it is
  28. multithreaded, at any instant it guarantees a 1:1 mapping of threads
  29. ap_process_connection invocations.
  30. Note: In the future it will be possible for ap_process_connection
  31. to return to the MPM prior to finishing the entire connection; and
  32. the MPM will proceed with asynchronous handling for the connection;
  33. in the future the MPM may call ap_process_connection again -- but
  34. does not guarantee it will occur on the same thread as the first call.
  35. The MPM further guarantees that no asynchronous behaviour such as
  36. longjmps and signals will interfere with the user code that is
  37. invoked through ap_process_connection. The MPM may reserve some
  38. signals for its use (i.e. SIGUSR1), but guarantees that these signals
  39. are ignored when executing outside the MPM code itself. (This
  40. allows broken user code that does not handle EINTR to function
  41. properly.)
  42. The suggested server restart and stop behaviour will be "graceful".
  43. However the MPM may choose to terminate processes when the user
  44. requests a non-graceful restart/stop. When this occurs, the MPM kills
  45. all threads with extreme prejudice, and destroys the pchild pool.
  46. User cleanups registered in the pchild apr_pool_t will be invoked at
  47. this point. (This can pose some complications, the user cleanups
  48. are asynchronous behaviour not unlike longjmp/signal... but if the
  49. admin is asking for a non-graceful shutdown, how much effort should
  50. we put into doing it in a nice way?)
  51. unix/posix notes:
  52. - The MPM does not set a SIGALRM handler, user code may use SIGALRM.
  53. But the preferred method of handling timeouts is to use the
  54. timeouts provided by the BUFF abstraction.
  55. - The proper setting for SIGPIPE is SIG_IGN, if user code changes it
  56. for any of their own processing, it must be restored to SIG_IGN
  57. prior to executing or returning to any apache code.
  58. TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
  59. }
  60. {
  61. * This is the function that MPMs must create. This function is responsible
  62. * for controlling the parent and child processes. It will run until a
  63. * restart/shutdown is indicated.
  64. * @param pconf the configuration pool, reset before the config file is read
  65. * @param plog the log pool, reset after the config file is read
  66. * @param server_conf the global server config.
  67. * @return 1 for shutdown 0 otherwise.
  68. * @deffunc int ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf)
  69. }
  70. function ap_mpm_run(pconf, plog: Papr_pool_t; server_conf: Pserver_rec): Integer;
  71. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  72. external LibHTTPD name LibNamePrefix + 'ap_mpm_run' + LibSuff12;
  73. {
  74. * predicate indicating if a graceful stop has been requested ...
  75. * used by the connection loop
  76. * @return 1 if a graceful stop has been requested, 0 otherwise
  77. * @deffunc int ap_graceful_stop_signalled(*void)
  78. }
  79. function ap_graceful_stop_signalled: Integer;
  80. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  81. external LibHTTPD name LibNamePrefix + 'ap_graceful_stop_signalled' + LibSuff0;
  82. {
  83. * Spawn a process with privileges that another module has requested
  84. * @param r The request_rec of the current request
  85. * @param newproc The resulting process handle.
  86. * @param progname The program to run
  87. * @param const_args the arguments to pass to the new program. The first
  88. * one should be the program name.
  89. * @param env The new environment apr_table_t for the new process. This
  90. * should be a list of NULL-terminated strings.
  91. * @param attr the procattr we should use to determine how to create the new
  92. * process
  93. * @param p The pool to use.
  94. }
  95. function ap_os_create_privileged_process(
  96. const r: Prequest_rec;
  97. newproc: Papr_proc_t;
  98. const progname, args, env: PChar;
  99. attr: Papr_procattr_t; p: Papr_pool_t): apr_status_t;
  100. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  101. external LibHTTPD name LibNamePrefix + 'ap_os_create_privileged_process' + LibSuff28;
  102. const
  103. { Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED }
  104. AP_MPMQ_NOT_SUPPORTED = 0; { This value specifies whether }
  105. { an MPM is capable of }
  106. { threading or forking. }
  107. AP_MPMQ_STATIC = 1; { This value specifies whether }
  108. { an MPM is using a static # }
  109. { threads or daemons. }
  110. AP_MPMQ_DYNAMIC = 2; { This value specifies whether }
  111. { an MPM is using a dynamic # }
  112. { threads or daemons. }
  113. { Values returned for AP_MPMQ_MPM_STATE }
  114. AP_MPMQ_STARTING = 0;
  115. AP_MPMQ_RUNNING = 1;
  116. AP_MPMQ_STOPPING = 2;
  117. AP_MPMQ_MAX_DAEMON_USED = 1; { Max # of daemons used so far }
  118. AP_MPMQ_IS_THREADED = 2; { MPM can do threading }
  119. AP_MPMQ_IS_FORKED = 3; { MPM can do forking }
  120. AP_MPMQ_HARD_LIMIT_DAEMONS = 4; { The compiled max # daemons }
  121. AP_MPMQ_HARD_LIMIT_THREADS = 5; { The compiled max # threads }
  122. AP_MPMQ_MAX_THREADS = 6; { # of threads/child by config }
  123. AP_MPMQ_MIN_SPARE_DAEMONS = 7; { Min # of spare daemons }
  124. AP_MPMQ_MIN_SPARE_THREADS = 8; { Min # of spare threads }
  125. AP_MPMQ_MAX_SPARE_DAEMONS = 9; { Max # of spare daemons }
  126. AP_MPMQ_MAX_SPARE_THREADS = 10; { Max # of spare threads }
  127. AP_MPMQ_MAX_REQUESTS_DAEMON = 11; { Max # of requests per daemon }
  128. AP_MPMQ_MAX_DAEMONS = 12; { Max # of daemons by config }
  129. AP_MPMQ_MPM_STATE = 13; { starting, running, stopping }
  130. {
  131. * Query a property of the current MPM.
  132. * @param query_code One of APM_MPMQ_*
  133. * @param result A location to place the result of the query
  134. * @return APR_SUCCESS or APR_ENOTIMPL
  135. * @deffunc int ap_mpm_query(int query_code, int *result)
  136. }
  137. function ap_mpm_query(query_code: Integer; result: PInteger): apr_status_t;
  138. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  139. external LibHTTPD name LibNamePrefix + 'ap_mpm_query' + LibSuff8;
  140. { Defining GPROF when compiling uses the moncontrol() function to
  141. * disable gprof profiling in the parent, and enable it only for
  142. * request processing in children (or in one_process mode). It's
  143. * absolutely required to get useful gprof results under linux
  144. * because the profile itimers and such are disabled across a
  145. * fork(). It's probably useful elsewhere as well.
  146. }
  147. {#ifdef GPROF
  148. extern void moncontrol(int);
  149. #define AP_MONCONTROL(x) moncontrol(x)
  150. #else
  151. #define AP_MONCONTROL(x)
  152. #endif}
  153. {$ifdef AP_ENABLE_EXCEPTION_HOOK}
  154. type
  155. ap_exception_info_t = record
  156. sig: Integer;
  157. pid: pid_t;
  158. end;
  159. AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei))
  160. {$endif} {AP_ENABLE_EXCEPTION_HOOK}