mod_heartbeat.c revision ab472f62f863daf6ddb31cf0ecdc6d8ccbb920e5
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "apr_strings.h"
#include "ap_mpm.h"
#include "scoreboard.h"
#ifndef HEARTBEAT_INTERVAL
#define HEARTBEAT_INTERVAL (1)
#endif
typedef struct hb_ctx_t
{
int active;
int server_limit;
int thread_limit;
volatile int keep_running;
const char *mutex_path;
} hb_ctx_t;
static const char *msg_format = "v=%u&ready=%u&busy=%u";
#define MSG_VERSION (1)
{
char buf[256];
int i, j;
apr_uint32_t ready = 0;
apr_uint32_t busy = 0;
for (i = 0; i < ctx->server_limit; i++) {
ps = ap_get_scoreboard_process(i);
for (j = 0; j < ctx->thread_limit; j++) {
int res;
ready++;
}
else if (res != SERVER_DEAD &&
busy++;
}
}
}
do {
SOCK_DGRAM, APR_PROTO_UDP, p);
if (rv) {
NULL, "Heartbeat: apr_socket_create failed");
break;
}
if (rv) {
NULL, "Heartbeat: apr_mcast_loopback failed");
break;
}
if (rv) {
NULL, "Heartbeat: apr_socket_sendto failed");
break;
}
} while (0);
if (sock) {
}
return OK;
}
#ifndef apr_time_from_msec
#define apr_time_from_msec(x) (x * 1000)
#endif
{
while (ctx->keep_running) {
if (rv == APR_SUCCESS) {
break;
}
}
while (ctx->keep_running) {
int mpm_state = 0;
if (rv != APR_SUCCESS) {
break;
}
if (mpm_state == AP_MPMQ_STOPPING) {
ctx->keep_running = 0;
break;
}
}
return NULL;
}
{
ctx->keep_running = 0;
return rv;
}
{
p);
if (rv) {
"Heartbeat: apr_thread_mutex_create failed");
return;
}
* cleanup was being invoked before the thread completely spawned.
*/
if (rv) {
"Heartbeat: apr_thread_create failed");
}
}
{
start_hb_worker(p, ctx);
"Heartbeat: Failed to start worker thread.");
return;
}
}
return;
}
server_rec *s)
{
return OK;
}
#else
#else
#endif
#endif
mech,
p);
if (rv) {
"Heartbeat: mutex failed creation at %s (type=%d)",
return !OK;
}
return OK;
}
static void hb_register_hooks(apr_pool_t *p)
{
}
{
return cfg;
}
{
char *path;
char *host_str;
char *scope_id;
apr_port_t port = 0;
return err;
}
}
else {
return "HeartbeatAddress: May only be specified once.";
}
if (rv) {
return "HeartbeatAddress: Unable to parse address.";
}
return "HeartbeatAddress: No host provided in address";
}
if (port == 0) {
return "HeartbeatAddress: No port provided in address";
}
p);
if (rv) {
return "HeartbeatAddress: apr_sockaddr_info_get failed.";
}
if (rv) {
return "HeartbeatAddress: unable to find temp directory.";
}
if (rv) {
return "HeartbeatAddress: unable to allocate temp file.";
}
if (rv) {
return "HeartbeatAddress: unable to get lockf name.";
}
return NULL;
}
static const command_rec hb_cmds[] = {
"Address to send heartbeat requests"),
{NULL}
};
NULL, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
hb_create_config, /* create per-server config structure */
NULL, /* merge per-server config structures */
hb_cmds, /* command apr_table_t */
};