Navigation


Changeset 1354:0dff6a604b0a in freeDiameter for extensions/acl_wl/acl_wl.c


Ignore:
Timestamp:
May 17, 2019, 7:59:19 PM (5 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

acl_wl: add reload support using SIGUSR1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/acl_wl/acl_wl.c

    r741 r1354  
    3838 */
    3939
     40#include <pthread.h>
     41#include <signal.h>
     42
    4043#include "acl_wl.h"
     44
     45static pthread_rwlock_t acl_wl_lock;
     46
     47#define MODULE_NAME "acl_wl"
     48
     49static char *acl_wl_config_file;
    4150
    4251/* The validator function */
     
    5463        /* Default to unknown result */
    5564        *auth = 0;
    56        
     65
     66        if (pthread_rwlock_rdlock(&acl_wl_lock) != 0) {
     67                fd_log_notice("%s: read-lock failed, skipping handler", MODULE_NAME);
     68                return 0;
     69        }
     70
    5771        /* Now search the peer in our tree */
    5872        CHECK_FCT( aw_tree_lookup(info->pi_diamid, &res) );
     73
     74        if (pthread_rwlock_unlock(&acl_wl_lock) != 0) {
     75                fd_log_notice("%s: read-unlock failed after aw_tree_lookup, exiting", MODULE_NAME);
     76                exit(1);
     77        }
     78
    5979        if (res < 0) {
    6080                /* The peer is not whitelisted */
     
    88108}
    89109
     110static volatile int in_signal_handler = 0;
     111
     112/* signal handler */
     113static void sig_hdlr(void)
     114{
     115        struct fd_list old_tree;
     116
     117        if (in_signal_handler) {
     118                fd_log_error("%s: already handling a signal, ignoring new one", MODULE_NAME);
     119                return;
     120        }
     121        in_signal_handler = 1;
     122
     123        if (pthread_rwlock_wrlock(&acl_wl_lock) != 0) {
     124                fd_log_error("%s: locking failed, aborting config reload", MODULE_NAME);
     125                return;
     126        }
     127
     128        /* save old config in case reload goes wrong */
     129        old_tree = tree_root;
     130        fd_list_init(&tree_root, NULL);
     131
     132        if (aw_conf_handle(acl_wl_config_file) != 0) {
     133                fd_log_error("%s: error reloading configuration, restoring previous configuration", MODULE_NAME);
     134                aw_tree_destroy();
     135                tree_root = old_tree;
     136        } else {
     137                struct fd_list new_tree;
     138                new_tree = tree_root;
     139                tree_root = old_tree;
     140                aw_tree_destroy();
     141                tree_root = new_tree;
     142        }
     143
     144        if (pthread_rwlock_unlock(&acl_wl_lock) != 0) {
     145                fd_log_error("%s: unlocking failed after config reload, exiting", MODULE_NAME);
     146                exit(1);
     147        }
     148
     149        fd_log_notice("%s: reloaded configuration", MODULE_NAME);
     150
     151        in_signal_handler = 0;
     152}
     153
     154
    90155/* entry point */
    91156static int aw_entry(char * conffile)
     
    93158        TRACE_ENTRY("%p", conffile);
    94159        CHECK_PARAMS(conffile);
    95        
     160
     161        acl_wl_config_file = conffile;
     162
     163        pthread_rwlock_init(&acl_wl_lock, NULL);
     164
     165        if (pthread_rwlock_wrlock(&acl_wl_lock) != 0) {
     166                fd_log_notice("%s: write-lock failed, aborting", MODULE_NAME);
     167                return EDEADLK;
     168        }
     169
    96170        /* Parse configuration file */
    97171        CHECK_FCT( aw_conf_handle(conffile) );
    98        
     172
    99173        TRACE_DEBUG(INFO, "Extension ACL_wl initialized with configuration: '%s'", conffile);
    100174        if (TRACE_BOOL(ANNOYING)) {
    101175                aw_tree_dump();
    102176        }
    103        
     177
     178        if (pthread_rwlock_unlock(&acl_wl_lock) != 0) {
     179                fd_log_notice("%s: write-unlock failed, aborting", MODULE_NAME);
     180                return EDEADLK;
     181        }
     182
     183        /* Register reload callback */
     184        CHECK_FCT(fd_event_trig_regcb(SIGUSR1, MODULE_NAME, sig_hdlr));
     185
    104186        /* Register the validator function */
    105187        CHECK_FCT( fd_peer_validate_register ( aw_validate ) );
     
    115197}
    116198
    117 EXTENSION_ENTRY("acl_wl", aw_entry);
     199EXTENSION_ENTRY(MODULE_NAME, aw_entry);
Note: See TracChangeset for help on using the changeset viewer.