[4aa63a4] | 1 | /* |
---|
| 2 | * Copyright 2018 Fiona Klute |
---|
| 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 | |
---|
| 17 | #include "gnutls_watchdog.h" |
---|
| 18 | |
---|
| 19 | #include <httpd.h> |
---|
| 20 | #include <mod_watchdog.h> |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | struct mgs_watchdog* mgs_new_singleton_watchdog(server_rec *s, char *name, |
---|
| 24 | apr_pool_t* p) |
---|
| 25 | { |
---|
| 26 | APR_OPTIONAL_FN_TYPE(ap_watchdog_get_instance) *inst_fn = |
---|
| 27 | APR_RETRIEVE_OPTIONAL_FN(ap_watchdog_get_instance); |
---|
| 28 | APR_OPTIONAL_FN_TYPE(ap_watchdog_register_callback) *reg_callback_fn = |
---|
| 29 | APR_RETRIEVE_OPTIONAL_FN(ap_watchdog_register_callback); |
---|
| 30 | APR_OPTIONAL_FN_TYPE(ap_watchdog_set_callback_interval) *mod_callback_fn = |
---|
| 31 | APR_RETRIEVE_OPTIONAL_FN(ap_watchdog_set_callback_interval); |
---|
| 32 | |
---|
| 33 | /* Check if all functions are available */ |
---|
| 34 | if (inst_fn == NULL || reg_callback_fn == NULL || mod_callback_fn == NULL) |
---|
| 35 | { |
---|
| 36 | ap_log_error(APLOG_MARK, APLOG_WARNING, APR_EGENERAL, s, |
---|
| 37 | "Could not retrieve watchdog functions, has " |
---|
| 38 | "mod_watchdog been loaded?"); |
---|
| 39 | return NULL; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | apr_pool_t *wd_pool; |
---|
| 43 | apr_status_t rv = apr_pool_create(&wd_pool, p); |
---|
| 44 | if (rv != APR_SUCCESS) |
---|
| 45 | { |
---|
| 46 | ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, |
---|
| 47 | "Creating pool for watchdog instance failed!"); |
---|
| 48 | return NULL; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | struct mgs_watchdog *w = apr_palloc(wd_pool, sizeof(struct mgs_watchdog)); |
---|
| 52 | |
---|
| 53 | w->get_instance = inst_fn; |
---|
| 54 | w->register_callback = reg_callback_fn; |
---|
| 55 | w->set_callback_interval = mod_callback_fn; |
---|
| 56 | |
---|
| 57 | /* 0 -> run in child process, 1 -> singleton watchdog */ |
---|
| 58 | rv = w->get_instance(&w->wd, name, 0, 1, wd_pool); |
---|
| 59 | if (rv != APR_SUCCESS) |
---|
| 60 | { |
---|
| 61 | ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, |
---|
| 62 | "Retrieving watchdog instance '%s' failed!", name); |
---|
| 63 | apr_pool_destroy(wd_pool); |
---|
| 64 | return NULL; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, s, |
---|
| 68 | "watchdog init for %s", name); |
---|
| 69 | return w; |
---|
| 70 | } |
---|