Skip to content
Permalink
Browse files

add server_init() and server_free()

so that src/lib/server/ can be initialized all at once.

And the callers then don't need to have a list of init/free
functions
  • Loading branch information
alandekok committed Aug 28, 2019
1 parent bd82e69 commit da857935628505476c531a3a0edfc173e28d8941
Showing with 145 additions and 160 deletions.
  1. +4 −81 src/bin/radiusd.c
  2. +3 −79 src/bin/unit_test_module.c
  3. +1 −0 src/lib/server/all.mk
  4. +134 −0 src/lib/server/base.c
  5. +3 −0 src/lib/server/base.h
@@ -521,11 +521,6 @@ int main(int argc, char *argv[])
*/
INFO("%s", fr_debug_state_to_msg(fr_debug_state));

/*
* Initialise trigger rate limiting
*/
trigger_exec_init(config->root_cs);

/*
* Call this again now we've loaded the configuration. Yes I know...
*/
@@ -671,49 +666,9 @@ int main(int argc, char *argv[])
/*
* Initialise the interpreter, registering operations.
*/
if (unlang_init() < 0) EXIT_WITH_FAILURE;

/*
* Initialize Auth-Type, etc. in the virtual servers
* before loading the modules. Some modules need those
* to be defined.
*/
if (virtual_servers_bootstrap(config->root_cs) < 0) EXIT_WITH_FAILURE;

/*
* Bootstrap the modules. This links to them, and runs
* their "bootstrap" routines.
*
* After this step, all dynamic attributes, xlats, etc. are defined.
*/
if (modules_bootstrap(config->root_cs) < 0) EXIT_WITH_FAILURE;
if (unlang_init() < 0) return -1;

/*
* And then load the virtual servers.
*
* This function also opens the listeners in each virtual
* server. These listeners MUST be started before the
* modules. If there is another server already running,
* we will discover it here and exit BEFORE opening
* connections to back-end DBs.
*/
if (virtual_servers_instantiate() < 0) EXIT_WITH_FAILURE;

/*
* Call the module's initialisation methods. These create
* connection pools and open connections to external resources.
*/
if (modules_instantiate() < 0) EXIT_WITH_FAILURE;

/*
* Instantiate "permanent" xlats
*/
if (xlat_instantiate() < 0) EXIT_WITH_FAILURE;

/*
* Instantiate "permanent" paircmps
*/
if (paircmp_init() < 0) EXIT_WITH_FAILURE;
if (server_init(config->root_cs) < 0) EXIT_WITH_FAILURE;

/*
* Everything seems to have loaded OK, exit gracefully.
@@ -970,45 +925,13 @@ int main(int argc, char *argv[])
*/
log_global_free();

/*
* Free xlat instance data, and call any detach methods
*/
xlat_instances_free();

/*
* Detach modules, connection pools, registered xlats
* paircmps / maps.
*/
modules_free();

/*
* The only paircmps remaining are the ones registered
* by the server core.
*/
paircmp_free();
server_free();

/*
* The only xlats remaining are the ones registered by
* the server core.
*/
xlat_free();

/*
* The only maps remaining are the ones registered by
* the server core.
*/
map_proc_free();

/*
* Free any resources used by the unlang interpreter.
* Free any resources used by the unlang interpreter.
*/
unlang_free();

/*
* Free information associated with the virtual servers.
*/
virtual_servers_free();

#ifdef HAVE_OPENSSL_CRYPTO_H
tls_free(); /* Cleanup any memory alloced by OpenSSL and placed into globals */
#endif
@@ -845,55 +845,12 @@ int main(int argc, char *argv[])
cf_data_add(server, dict_p, "dictionary", true);
}

/*
* Initialise the trigger rate limiting tree
*/
if (trigger_exec_init(config->root_cs) < 0) EXIT_WITH_FAILURE;

/*
* Initialise the interpreter, registering operations.
*/
if (unlang_init() < 0) EXIT_WITH_FAILURE;

/*
* Explicitly initialise the xlat tree, and perform dictionary lookups.
*/
if (xlat_init() < 0) EXIT_WITH_FAILURE;

/*
* Bootstrap the modules. This links to them, and runs
* their "bootstrap" routines.
*
* After this step, all dynamic attributes, xlats, etc. are defined.
*/
if (modules_bootstrap(config->root_cs) < 0) EXIT_WITH_FAILURE;

/*
* Initialize Auth-Type, etc. in the virtual servers
* before loading the modules. Some modules need those
* to be defined.
*/
if (virtual_servers_bootstrap(config->root_cs) < 0) EXIT_WITH_FAILURE;

/*
* Instantiate the modules
*/
if (modules_instantiate() < 0) EXIT_WITH_FAILURE;

/*
* And then load the virtual servers.
*/
if (virtual_servers_instantiate() < 0) EXIT_WITH_FAILURE;

/*
* Call xlat instantiation functions (after the xlats have been compiled)
*/
if (xlat_instantiate() < 0) EXIT_WITH_FAILURE;
if (unlang_init() < 0) return -1;

/*
* Instantiate "permanent" paircmps
*/
if (paircmp_init() < 0) EXIT_WITH_FAILURE;
if (server_init(config->root_cs) < 0) EXIT_WITH_FAILURE;

/*
* Create a dummy event list
@@ -1121,46 +1078,13 @@ int main(int argc, char *argv[])
*/
log_global_free();

/*
* Free xlat instance data, and call any detach methods
*/
xlat_instances_free();

/*
* Unregister poke *after* freeing instances that depend on it
*/
xlat_unregister("poke");

/*
* Detach modules, connection pools, registered xlats / paircmps / maps.
*/
modules_free();

/*
* The only paircmps remaining are the ones registered by the server core.
*/
paircmp_free();

/*
* The only xlats remaining are the ones registered by the server core.
*/
xlat_free();

/*
* The only maps remaining are the ones registered by the server core.
*/
map_proc_free();
server_free();

/*
* Free any resources used by the unlang interpreter.
*/
unlang_free();

/*
* Free information associated with the virtual servers.
*/
virtual_servers_free();

/*
* And now nothing should be left anywhere except the
* parsed configuration items.
@@ -1,6 +1,7 @@
TARGET := libfreeradius-server.a

SOURCES := \
base.c \
auth.c \
cf_file.c \
cf_parse.c \
@@ -0,0 +1,134 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/

/**
* $Id$
*
* @file src/lib/server/base.c
* @brief Functions to bootstrap this library
*
* @copyright 2019 The FreeRADIUS server project
*/

RCSID("$Id$")

#include <freeradius-devel/server/base.h>

/** Initialize src/lib/server/
*
* This is just so that the callers don't need to call a million functions.
*
* @param cs The root configuration section.
* @return
* - 0 on success.
* - -1 on failure.
*/
int server_init(CONF_SECTION *cs)
{
/*
* Initialise the trigger rate limiting tree
*/
if (trigger_exec_init(cs) < 0) return -1;

/*
* Explicitly initialise the xlat tree, and perform dictionary lookups.
*/
if (xlat_init() < 0) return -1;

/*
* Initialize Auth-Type, etc. in the virtual servers
* before loading the modules. Some modules need those
* to be defined.
*/
if (virtual_servers_bootstrap(cs) < 0) return -1;

/*
* Bootstrap the modules. This links to them, and runs
* their "bootstrap" routines.
*
* After this step, all dynamic attributes, xlats, etc. are defined.
*/
if (modules_bootstrap(cs) < 0) return -1;

/*
* And then load the virtual servers.
*/
if (virtual_servers_instantiate() < 0) return -1;

/*
* Instantiate the modules
*/
if (modules_instantiate() < 0) return -1;

/*
* Call xlat instantiation functions (after the xlats have been compiled)
*/
if (xlat_instantiate() < 0) return -1;

/*
* Instantiate "permanent" paircmps
*/
if (paircmp_init() < 0) return -1;

/*
* Set up dictionaries and attributes for password comparisons
*/
if (password_init() < 0) return -1;

return 0;
}

/** Free src/lib/server/
*
* This is just so that the callers don't need to call a million functions.
*/
void server_free(void)
{
/*
* Free password dictionaries
*/
password_free();

/*
* Free xlat instance data, and call any detach methods
*/
xlat_instances_free();

/*
* Detach modules, connection pools, registered xlats / paircmps / maps.
*/
modules_free();

/*
* The only paircmps remaining are the ones registered by the server core.
*/
paircmp_free();

/*
* The only xlats remaining are the ones registered by the server core.
*/
xlat_free();

/*
* The only maps remaining are the ones registered by the server core.
*/
map_proc_free();

/*
* Free information associated with the virtual servers.
*/
virtual_servers_free();
}
@@ -70,3 +70,6 @@ RCSIDH(base_h, "$Id$")
#include <freeradius-devel/server/xlat.h>

#include <freeradius-devel/util/base.h>

int server_init(CONF_SECTION *cs);
void server_free(void);

0 comments on commit da85793

Please sign in to comment.
You can’t perform that action at this time.