~ubuntu-branches/ubuntu/lucid/fpc/lucid-proposed

« back to all changes in this revision

Viewing changes to fpcsrc/packages/httpd22/src/ap_mpm.inc

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-10-09 23:29:00 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081009232900-553f61m37jkp6upv
Tags: 2.2.2-4
[ Torsten Werner ]
* Update ABI version in fpc-depends automatically.
* Remove empty directories from binary package fpc-source.

[ Mazen Neifer ]
* Removed leading path when calling update-alternatives to remove a Linitian
  error.
* Fixed clean target.
* Improved description of packages. (Closes: #498882)

Show diffs side-by-side

added added

removed removed

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