source: mod_gnutls/src/gnutls_watchdog.c

mod_gnutls/0.11.0
Last change on this file was 0484b31, checked in by Fiona Klute <fiona.klute@…>, 7 months ago

Set the module name for log messages from gnutls_watchdog.c

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  Copyright 2018-2020 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
22APLOG_USE_MODULE(gnutls);
23
24struct mgs_watchdog* mgs_new_singleton_watchdog(server_rec *s, char *name,
25                                                apr_pool_t* p)
26{
27    APR_OPTIONAL_FN_TYPE(ap_watchdog_get_instance) *inst_fn =
28        APR_RETRIEVE_OPTIONAL_FN(ap_watchdog_get_instance);
29    APR_OPTIONAL_FN_TYPE(ap_watchdog_register_callback) *reg_callback_fn =
30        APR_RETRIEVE_OPTIONAL_FN(ap_watchdog_register_callback);
31    APR_OPTIONAL_FN_TYPE(ap_watchdog_set_callback_interval) *mod_callback_fn =
32        APR_RETRIEVE_OPTIONAL_FN(ap_watchdog_set_callback_interval);
33
34    /* Check if all functions are available */
35    if (inst_fn == NULL || reg_callback_fn == NULL || mod_callback_fn == NULL)
36    {
37        ap_log_error(APLOG_MARK, APLOG_WARNING, APR_EGENERAL, s,
38                     "Could not retrieve watchdog functions, has "
39                     "mod_watchdog been loaded?");
40        return NULL;
41    }
42
43    apr_pool_t *wd_pool;
44    apr_status_t rv = apr_pool_create(&wd_pool, p);
45    if (rv != APR_SUCCESS)
46    {
47        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
48                     "Creating pool for watchdog instance failed!");
49        return NULL;
50    }
51
52    struct mgs_watchdog *w = apr_palloc(wd_pool, sizeof(struct mgs_watchdog));
53
54    w->get_instance = inst_fn;
55    w->register_callback = reg_callback_fn;
56    w->set_callback_interval = mod_callback_fn;
57
58    /* 0 -> run in child process, 1 -> singleton watchdog */
59    rv = w->get_instance(&w->wd, name, 0, 1, wd_pool);
60    if (rv != APR_SUCCESS)
61    {
62        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
63                     "Retrieving watchdog instance '%s' failed!", name);
64        apr_pool_destroy(wd_pool);
65        return NULL;
66    }
67
68    ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, s,
69                 "watchdog init for %s", name);
70    return w;
71}
Note: See TracBrowser for help on using the repository browser.