MCPcopy Create free account
hub / github.com/apache/httpd / exipc_post_config

Function exipc_post_config

modules/examples/mod_example_ipc.c:119–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117 */
118
119static int exipc_post_config(apr_pool_t *pconf, apr_pool_t *plog,
120 apr_pool_t *ptemp, server_rec *s)
121{
122 apr_status_t rs;
123 exipc_data *base;
124 const char *tempdir;
125
126
127 /*
128 * Do nothing if we are not creating the final configuration.
129 * The parent process gets initialized a couple of times as the
130 * server starts up, and we don't want to create any more mutexes
131 * and shared memory segments than we're actually going to use.
132 */
133 if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG)
134 return OK;
135
136 /*
137 * The shared memory allocation routines take a file name.
138 * Depending on system-specific implementation of these
139 * routines, that file may or may not actually be created. We'd
140 * like to store those files in the operating system's designated
141 * temporary directory, which APR can point us to.
142 */
143 rs = apr_temp_dir_get(&tempdir, pconf);
144 if (APR_SUCCESS != rs) {
145 ap_log_error(APLOG_MARK, APLOG_ERR, rs, s, APLOGNO(02992)
146 "Failed to find temporary directory");
147 return HTTP_INTERNAL_SERVER_ERROR;
148 }
149
150 /* Create the shared memory segment */
151
152 /*
153 * Create a unique filename using our pid. This information is
154 * stashed in the global variable so the children inherit it.
155 */
156 shmfilename = apr_psprintf(pconf, "%s/httpd_shm.%ld", tempdir,
157 (long int)getpid());
158
159 /* Now create that segment */
160 rs = apr_shm_create(&exipc_shm, sizeof(exipc_data),
161 (const char *) shmfilename, pconf);
162 if (APR_SUCCESS != rs) {
163 ap_log_error(APLOG_MARK, APLOG_ERR, rs, s, APLOGNO(02993)
164 "Failed to create shared memory segment on file %s",
165 shmfilename);
166 return HTTP_INTERNAL_SERVER_ERROR;
167 }
168
169 /* Created it, now let's zero it out */
170 base = (exipc_data *)apr_shm_baseaddr_get(exipc_shm);
171 base->counter = 0;
172
173 /* Create global mutex */
174
175 rs = ap_global_mutex_create(&exipc_mutex, NULL, exipc_mutex_type, NULL,
176 s, pconf, 0);

Callers

nothing calls this directly

Calls 3

ap_state_queryFunction · 0.85
ap_global_mutex_createFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected