2 * mainconf.c Handle the server's configuration.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2002,2006-2007 The FreeRADIUS server project
21 * Copyright 2002 Alan DeKok <aland@ox.org>
24 #include <freeradius-devel/ident.h>
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
29 #include <freeradius-devel/rad_assert.h>
33 #ifdef HAVE_SYS_RESOURCE_H
34 #include <sys/resource.h>
45 #ifdef HAVE_SYS_PRCTL_H
46 #include <sys/prctl.h>
53 #ifdef HAVE_SYS_STAT_H
61 struct main_config_t mainconfig;
62 char *request_log_file = NULL;
63 char *debug_condition = NULL;
65 typedef struct cached_config_t {
66 struct cached_config_t *next;
71 static cached_config_t *cs_cache = NULL;
74 * Temporary local variables for parsing the configuration
79 * Systems that have set/getresuid also have setuid.
81 static uid_t server_uid = 0;
82 static gid_t server_gid = 0;
83 static const char *uid_name = NULL;
84 static const char *gid_name = NULL;
86 static const char *chroot_dir = NULL;
87 static int allow_core_dumps = 0;
88 static const char *radlog_dest = NULL;
91 * These are not used anywhere else..
93 static const char *localstatedir = NULL;
94 static const char *prefix = NULL;
95 static char *syslog_facility = NULL;
96 static const FR_NAME_NUMBER str2fac[] = {
101 { "user", LOG_USER },
104 { "mail", LOG_MAIL },
107 { "daemon", LOG_DAEMON },
110 { "auth", LOG_AUTH },
116 { "news", LOG_NEWS },
119 { "uucp", LOG_UUCP },
122 { "cron", LOG_CRON },
125 { "authpriv", LOG_AUTHPRIV },
131 { "local0", LOG_LOCAL0 },
134 { "local1", LOG_LOCAL1 },
137 { "local2", LOG_LOCAL2 },
140 { "local3", LOG_LOCAL3 },
143 { "local4", LOG_LOCAL4 },
146 { "local5", LOG_LOCAL5 },
149 { "local6", LOG_LOCAL6 },
152 { "local7", LOG_LOCAL7 },
158 * Security configuration for the server.
160 static const CONF_PARSER security_config[] = {
161 { "max_attributes", PW_TYPE_INTEGER, 0, &fr_max_attributes, Stringify(0) },
162 { "reject_delay", PW_TYPE_INTEGER, 0, &mainconfig.reject_delay, Stringify(0) },
163 { "status_server", PW_TYPE_BOOLEAN, 0, &mainconfig.status_server, "no"},
164 { NULL, -1, 0, NULL, NULL }
169 * Logging configuration for the server.
171 static const CONF_PARSER logdest_config[] = {
172 { "destination", PW_TYPE_STRING_PTR, 0, &radlog_dest, "files" },
173 { "syslog_facility", PW_TYPE_STRING_PTR, 0, &syslog_facility, Stringify(0) },
175 { "file", PW_TYPE_STRING_PTR, 0, &mainconfig.log_file, "${logdir}/radius.log" },
176 { "requests", PW_TYPE_STRING_PTR, 0, &request_log_file, NULL },
177 { NULL, -1, 0, NULL, NULL }
181 static const CONF_PARSER serverdest_config[] = {
182 { "log", PW_TYPE_SUBSECTION, 0, NULL, (const void *) logdest_config },
183 { "log_file", PW_TYPE_STRING_PTR, 0, &mainconfig.log_file, NULL },
184 { "log_destination", PW_TYPE_STRING_PTR, 0, &radlog_dest, NULL },
185 { NULL, -1, 0, NULL, NULL }
189 static const CONF_PARSER log_config_nodest[] = {
190 { "stripped_names", PW_TYPE_BOOLEAN, 0, &log_stripped_names,"no" },
192 { "auth", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth, "no" },
193 { "auth_badpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_badpass, "no" },
194 { "auth_goodpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_goodpass, "no" },
195 { "msg_badpass", PW_TYPE_STRING_PTR, 0, &mainconfig.auth_badpass_msg, NULL},
196 { "msg_goodpass", PW_TYPE_STRING_PTR, 0, &mainconfig.auth_goodpass_msg, NULL},
198 { NULL, -1, 0, NULL, NULL }
203 * A mapping of configuration file names to internal variables
205 static const CONF_PARSER server_config[] = {
207 * FIXME: 'prefix' is the ONLY one which should be
208 * configured at compile time. Hard-coding it here is
209 * bad. It will be cleaned up once we clean up the
210 * hard-coded defines for the locations of the various
213 { "prefix", PW_TYPE_STRING_PTR, 0, &prefix, "/usr/local"},
214 { "localstatedir", PW_TYPE_STRING_PTR, 0, &localstatedir, "${prefix}/var"},
215 { "logdir", PW_TYPE_STRING_PTR, 0, &radlog_dir, "${localstatedir}/log"},
216 { "libdir", PW_TYPE_STRING_PTR, 0, &radlib_dir, "${prefix}/lib"},
217 { "radacctdir", PW_TYPE_STRING_PTR, 0, &radacct_dir, "${logdir}/radacct" },
218 { "hostname_lookups", PW_TYPE_BOOLEAN, 0, &fr_dns_lookups, "no" },
219 { "max_request_time", PW_TYPE_INTEGER, 0, &mainconfig.max_request_time, Stringify(MAX_REQUEST_TIME) },
220 { "cleanup_delay", PW_TYPE_INTEGER, 0, &mainconfig.cleanup_delay, Stringify(CLEANUP_DELAY) },
221 { "max_requests", PW_TYPE_INTEGER, 0, &mainconfig.max_requests, Stringify(MAX_REQUESTS) },
222 #ifdef DELETE_BLOCKED_REQUESTS
223 { "delete_blocked_requests", PW_TYPE_INTEGER, 0, &mainconfig.kill_unresponsive_children, Stringify(FALSE) },
225 { "pidfile", PW_TYPE_STRING_PTR, 0, &mainconfig.pid_file, "${run_dir}/radiusd.pid"},
226 { "checkrad", PW_TYPE_STRING_PTR, 0, &mainconfig.checkrad, "${sbindir}/checkrad" },
228 { "debug_level", PW_TYPE_INTEGER, 0, &mainconfig.debug_level, "0"},
231 { "proxy_requests", PW_TYPE_BOOLEAN, 0, &mainconfig.proxy_requests, "yes" },
233 { "log", PW_TYPE_SUBSECTION, 0, NULL, (const void *) log_config_nodest },
236 * People with old configs will have these. They are listed
237 * AFTER the "log" section, so if they exist in radiusd.conf,
238 * it will prefer "log_foo = bar" to "log { foo = bar }".
239 * They're listed with default values of NULL, so that if they
240 * DON'T exist in radiusd.conf, then the previously parsed
241 * values for "log { foo = bar}" will be used.
243 { "log_auth", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth, NULL },
244 { "log_auth_badpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_badpass, NULL },
245 { "log_auth_goodpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_goodpass, NULL },
246 { "log_stripped_names", PW_TYPE_BOOLEAN, 0, &log_stripped_names, NULL },
248 { "security", PW_TYPE_SUBSECTION, 0, NULL, (const void *) security_config },
250 { NULL, -1, 0, NULL, NULL }
253 static const CONF_PARSER bootstrap_config[] = {
254 { "user", PW_TYPE_STRING_PTR, 0, &uid_name, NULL },
255 { "group", PW_TYPE_STRING_PTR, 0, &gid_name, NULL },
256 { "chroot", PW_TYPE_STRING_PTR, 0, &chroot_dir, NULL },
257 { "allow_core_dumps", PW_TYPE_BOOLEAN, 0, &allow_core_dumps, "no" },
259 { NULL, -1, 0, NULL, NULL }
264 #define MAX_ARGV (256)
267 static size_t config_escape_func(char *out, size_t outlen, const char *in)
270 static const char *disallowed = "%{}\\'\"`";
274 * Non-printable characters get replaced with their
275 * mime-encoded equivalents.
278 if (outlen <= 3) break;
280 snprintf(out, outlen, "=%02X", (unsigned char) in[0]);
287 } else if (strchr(disallowed, *in) != NULL) {
288 if (outlen <= 2) break;
300 * Only one byte left.
320 * Xlat for %{config:section.subsection.attribute}
322 static size_t xlat_config(void *instance, REQUEST *request,
323 char *fmt, char *out,
325 RADIUS_ESCAPE_STRING func)
332 request = request; /* -Wunused */
333 instance = instance; /* -Wunused */
338 if (!radius_xlat(buffer, sizeof(buffer), fmt, request, config_escape_func)) {
342 ci = cf_reference_item(request->root->config,
343 request->root->config, buffer);
344 if (!ci || !cf_item_is_pair(ci)) {
349 cp = cf_itemtopair(ci);
352 * Ensure that we only copy what's necessary.
354 * If 'outlen' is too small, then the output is chopped to fit.
356 value = cf_pair_value(cp);
358 if (outlen > strlen(value)) {
359 outlen = strlen(value) + 1;
363 return func(out, outlen, value);
368 * Xlat for %{client:foo}
370 static size_t xlat_client(UNUSED void *instance, REQUEST *request,
371 char *fmt, char *out,
373 UNUSED RADIUS_ESCAPE_STRING func)
375 const char *value = NULL;
378 if (!fmt || !out || (outlen < 1)) return 0;
380 if (!request || !request->client) {
385 cp = cf_pair_find(request->client->cs, fmt);
386 if (!cp || !(value = cf_pair_value(cp))) {
391 strlcpy(out, value, outlen);
397 * Recursively make directories.
399 static int r_mkdir(const char *part)
401 char *ptr, parentdir[500];
404 if (stat(part, &st) == 0)
407 ptr = strrchr(part, FR_DIR_SEP);
412 snprintf(parentdir, (ptr - part)+1, "%s", part);
414 if (r_mkdir(parentdir) != 0)
417 if (mkdir(part, 0770) != 0) {
418 radlog(L_ERR, "mkdir(%s) error: %s\n", part, strerror(errno));
425 #ifdef HAVE_SYS_RESOURCE_H
426 static struct rlimit core_limits;
429 static void fr_set_dumpable(void)
432 * If configured, turn core dumps off.
434 if (!allow_core_dumps) {
435 #ifdef HAVE_SYS_RESOURCE_H
436 struct rlimit no_core;
439 no_core.rlim_cur = 0;
440 no_core.rlim_max = 0;
442 if (setrlimit(RLIMIT_CORE, &no_core) < 0) {
443 radlog(L_ERR, "Failed disabling core dumps: %s",
451 * Set or re-set the dumpable flag.
453 #ifdef HAVE_SYS_PRCTL_H
454 #ifdef PR_SET_DUMPABLE
455 if (prctl(PR_SET_DUMPABLE, 1) < 0) {
456 radlog(L_ERR,"Cannot re-enable core dumps: prctl(PR_SET_DUMPABLE) failed: '%s'",
463 * Reset the core dump limits to their original value.
465 #ifdef HAVE_SYS_RESOURCE_H
466 if (setrlimit(RLIMIT_CORE, &core_limits) < 0) {
467 radlog(L_ERR, "Cannot update core dump limit: %s",
474 static int doing_setuid = FALSE;
476 #if defined(HAVE_SETRESUID) && defined (HAVE_GETRESUID)
477 void fr_suid_up(void)
479 uid_t ruid, euid, suid;
481 if (getresuid(&ruid, &euid, &suid) < 0) {
482 radlog(L_ERR, "Failed getting saved UID's");
486 if (setresuid(-1, suid, -1) < 0) {
487 radlog(L_ERR, "Failed switching to privileged user");
491 if (geteuid() != suid) {
492 radlog(L_ERR, "Switched to unknown UID");
497 void fr_suid_down(void)
499 if (!doing_setuid) return;
501 if (setresuid(-1, server_uid, geteuid()) < 0) {
502 fprintf(stderr, "%s: Failed switching to uid %s: %s\n",
503 progname, uid_name, strerror(errno));
507 if (geteuid() != server_uid) {
508 fprintf(stderr, "%s: Failed switching uid: UID is incorrect\n",
516 void fr_suid_down_permanent(void)
518 if (!doing_setuid) return;
520 if (setresuid(server_uid, server_uid, server_uid) < 0) {
521 radlog(L_ERR, "Failed in permanent switch to uid %s: %s",
522 uid_name, strerror(errno));
526 if (geteuid() != server_uid) {
527 radlog(L_ERR, "Switched to unknown uid");
535 * Much less secure...
537 void fr_suid_up(void)
540 void fr_suid_down(void)
542 if (!uid_name) return;
544 if (setuid(server_uid) < 0) {
545 fprintf(stderr, "%s: Failed switching to uid %s: %s\n",
546 progname, uid_name, strerror(errno));
552 void fr_suid_down_permanent(void)
556 #endif /* HAVE_SETRESUID && HAVE_GETRESUID */
557 #else /* HAVE_SETUID */
558 void fr_suid_up(void)
561 void fr_suid_down(void)
565 void fr_suid_down_permanent(void)
569 #endif /* HAVE_SETUID */
574 * Do chroot, if requested.
576 * Switch UID and GID to what is specified in the config file
578 static int switch_users(CONF_SECTION *cs)
580 #ifdef HAVE_SYS_RESOURCE_H
582 * Get the current maximum for core files. Do this
583 * before anything else so as to ensure it's properly
586 if (getrlimit(RLIMIT_CORE, &core_limits) < 0) {
587 radlog(L_ERR, "Failed to get current core limit: %s", strerror(errno));
593 * Don't do chroot/setuid/setgid if we're in debugging
596 if (debug_flag && (getuid() != 0)) return 1;
598 if (cf_section_parse(cs, NULL, bootstrap_config) < 0) {
599 fprintf(stderr, "radiusd: Error: Failed to parse user/group information.\n");
609 gr = getgrnam(gid_name);
611 fprintf(stderr, "%s: Cannot get ID for group %s: %s\n",
612 progname, gid_name, strerror(errno));
615 server_gid = gr->gr_gid;
617 server_gid = getgid();
626 pw = getpwnam(uid_name);
628 fprintf(stderr, "%s: Cannot get passwd entry for user %s: %s\n",
629 progname, uid_name, strerror(errno));
633 if (getuid() == pw->pw_uid) {
637 server_uid = pw->pw_uid;
638 #ifdef HAVE_INITGROUPS
639 if (initgroups(uid_name, server_gid) < 0) {
640 fprintf(stderr, "%s: Cannot initialize supplementary group list for user %s: %s\n",
641 progname, uid_name, strerror(errno));
647 server_uid = getuid();
652 if (chroot(chroot_dir) < 0) {
653 fprintf(stderr, "%s: Failed to perform chroot %s: %s",
654 progname, chroot_dir, strerror(errno));
659 * Note that we leave chdir alone. It may be
660 * OUTSIDE of the root. This allows us to read
661 * the configuration from "-d ./etc/raddb", with
662 * the chroot as "./chroot/" for example. After
663 * the server has been loaded, it does a "cd
664 * ${logdir}" below, so that core files (if any)
665 * go to a logging directory.
667 * This also allows the configuration of the
668 * server to be outside of the chroot. If the
669 * server is statically linked, then the only
670 * things needed inside of the chroot are the
671 * logging directories.
677 if (gid_name && (setgid(server_gid) < 0)) {
678 fprintf(stderr, "%s: Failed setting group to %s: %s",
679 progname, gid_name, strerror(errno));
686 * Just before losing root permissions, ensure that the
687 * log files have the correct owner && group.
689 * We have to do this because the log file MAY have been
690 * specified on the command-line.
692 if (uid_name || gid_name) {
693 if ((mainconfig.radlog_dest == RADLOG_FILES) &&
694 (mainconfig.radlog_fd < 0)) {
695 mainconfig.radlog_fd = open(mainconfig.log_file,
696 O_WRONLY | O_APPEND | O_CREAT, 0640);
697 if (mainconfig.radlog_fd < 0) {
698 fprintf(stderr, "radiusd: Failed to open log file %s: %s\n", mainconfig.log_file, strerror(errno));
702 if (chown(mainconfig.log_file, server_uid, server_gid) < 0) {
703 fprintf(stderr, "%s: Cannot change ownership of log file %s: %s\n",
704 progname, mainconfig.log_file, strerror(errno));
718 * This also clears the dumpable flag if core dumps
723 if (allow_core_dumps) {
724 radlog(L_INFO, "Core dumps are enabled.");
729 #endif /* HAVE_SETUID */
732 static const FR_NAME_NUMBER str2dest[] = {
733 { "null", RADLOG_NULL },
734 { "files", RADLOG_FILES },
735 { "syslog", RADLOG_SYSLOG },
736 { "stdout", RADLOG_STDOUT },
737 { "stderr", RADLOG_STDERR },
738 { NULL, RADLOG_NUM_DEST }
745 * This function can ONLY be called from the main server process.
747 int read_mainconfig(int reload)
749 const char *p = NULL;
757 radlog(L_ERR, "Reload is not implemented");
761 if (stat(radius_dir, &statbuf) < 0) {
762 radlog(L_ERR, "Errors reading %s: %s",
763 radius_dir, strerror(errno));
768 if ((statbuf.st_mode & S_IWOTH) != 0) {
769 radlog(L_ERR, "Configuration directory %s is globally writable. Refusing to start due to insecure configuration.",
776 if (0 && (statbuf.st_mode & S_IROTH) != 0) {
777 radlog(L_ERR, "Configuration directory %s is globally readable. Refusing to start due to insecure configuration.",
783 radlog(L_INFO, "Starting - reading configuration files ...");
785 /* Read the configuration file */
786 snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf",
787 radius_dir, mainconfig.name);
788 if ((cs = cf_file_read(buffer)) == NULL) {
789 radlog(L_ERR, "Errors reading %s", buffer);
794 * If there was no log destination set on the command line,
797 if (mainconfig.radlog_dest == RADLOG_NULL) {
798 if (cf_section_parse(cs, NULL, serverdest_config) < 0) {
799 fprintf(stderr, "radiusd: Error: Failed to parse log{} section.\n");
800 cf_section_free(&cs);
805 fprintf(stderr, "radiusd: Error: No log destination specified.\n");
806 cf_section_free(&cs);
810 mainconfig.radlog_dest = fr_str2int(str2dest, radlog_dest,
812 if (mainconfig.radlog_dest == RADLOG_NUM_DEST) {
813 fprintf(stderr, "radiusd: Error: Unknown log_destination %s\n",
815 cf_section_free(&cs);
819 if (mainconfig.radlog_dest == RADLOG_SYSLOG) {
821 * Make sure syslog_facility isn't NULL
824 if (!syslog_facility) {
825 fprintf(stderr, "radiusd: Error: Syslog chosen but no facility was specified\n");
826 cf_section_free(&cs);
829 mainconfig.syslog_facility = fr_str2int(str2fac, syslog_facility, -1);
830 if (mainconfig.syslog_facility < 0) {
831 fprintf(stderr, "radiusd: Error: Unknown syslog_facility %s\n",
833 cf_section_free(&cs);
838 * Call openlog only once, when the
841 openlog(progname, LOG_PID, mainconfig.syslog_facility);
843 } else if (mainconfig.radlog_dest == RADLOG_FILES) {
844 if (!mainconfig.log_file) {
845 fprintf(stderr, "radiusd: Error: Specified \"files\" as a log destination, but no log filename was given!\n");
846 cf_section_free(&cs);
854 * Switch users as early as possible.
856 if (!switch_users(cs)) exit(1);
860 * Open the log file AFTER switching uid / gid. If we
861 * did switch uid/gid, then the code in switch_users()
862 * took care of setting the file permissions correctly.
864 if ((mainconfig.radlog_dest == RADLOG_FILES) &&
865 (mainconfig.radlog_fd < 0)) {
866 mainconfig.radlog_fd = open(mainconfig.log_file,
867 O_WRONLY | O_APPEND | O_CREAT, 0640);
868 if (mainconfig.radlog_fd < 0) {
869 fprintf(stderr, "radiusd: Failed to open log file %s: %s\n", mainconfig.log_file, strerror(errno));
870 cf_section_free(&cs);
875 /* Initialize the dictionary */
876 cp = cf_pair_find(cs, "dictionary");
877 if (cp) p = cf_pair_value(cp);
878 if (!p) p = radius_dir;
879 DEBUG2("including dictionary file %s/%s", p, RADIUS_DICTIONARY);
880 if (dict_init(p, RADIUS_DICTIONARY) != 0) {
881 radlog(L_ERR, "Errors reading dictionary: %s",
887 * This allows us to figure out where, relative to
888 * radiusd.conf, the other configuration files exist.
890 cf_section_parse(cs, NULL, server_config);
893 * Free the old configuration items, and replace them
896 * Note that where possible, we do atomic switch-overs,
897 * to ensure that the pointers are always valid.
899 cf_section_free(&mainconfig.config);
900 mainconfig.config = cs;
902 DEBUG2("%s: #### Loading Realms and Home Servers ####", mainconfig.name);
903 if (!realms_init(cs)) {
907 DEBUG2("%s: #### Loading Clients ####", mainconfig.name);
908 if (!clients_parse_section(cs)) {
913 * Register the %{config:section.subsection} xlat function.
915 xlat_register("config", xlat_config, NULL);
916 xlat_register("client", xlat_client, NULL);
919 * Starting the server, WITHOUT "-x" on the
920 * command-line: use whatever is in the config
923 if (debug_flag == 0) {
924 debug_flag = mainconfig.debug_level;
926 fr_debug_flag = debug_flag;
929 * Go update our behaviour, based on the configuration
934 * Sanity check the configuration for internal
937 if (mainconfig.reject_delay > mainconfig.cleanup_delay) {
938 mainconfig.reject_delay = mainconfig.cleanup_delay;
940 if (mainconfig.reject_delay < 0) mainconfig.reject_delay = 0;
942 /* Reload the modules. */
943 if (setup_modules(reload, mainconfig.config) < 0) {
948 if (chdir(radlog_dir) < 0) {
949 radlog(L_ERR, "Failed to 'chdir %s' after chroot: %s",
950 radlog_dir, strerror(errno));
955 cc = rad_malloc(sizeof(*cc));
956 memset(cc, 0, sizeof(*cc));
959 rad_assert(cs_cache == NULL);
966 * Free the configuration. Called only when the server is exiting.
968 int free_mainconfig(void)
970 cached_config_t *cc, *next;
972 virtual_servers_free(0);
975 * Free all of the cached configurations.
977 for (cc = cs_cache; cc != NULL; cc = next) {
979 cf_section_free(&cc->cs);
984 * Clean up the configuration data
988 listen_free(&mainconfig.listen);
994 void hup_mainconfig(void)
1000 radlog(L_INFO, "HUP - Re-reading configuration files");
1002 /* Read the configuration file */
1003 snprintf(buffer, sizeof(buffer), "%.200s/%.50s.conf",
1004 radius_dir, mainconfig.name);
1005 if ((cs = cf_file_read(buffer)) == NULL) {
1006 radlog(L_ERR, "Failed to re-read %s", buffer);
1010 cc = rad_malloc(sizeof(*cc));
1011 memset(cc, 0, sizeof(*cc));
1014 * Save the current configuration. Note that we do NOT
1015 * free older ones. We should probably do so at some
1016 * point. Doing so will require us to mark which modules
1017 * are still in use, and which aren't. Modules that
1018 * can't be HUPed always use the original configuration.
1019 * Modules that can be HUPed use one of the newer
1022 cc->created = time(NULL);
1024 cc->next = cs_cache;
1028 * Re-open the log file. If we can't, then keep logging
1029 * to the old log file.
1031 * The "open log file" code is here rather than in log.c,
1032 * because it makes that function MUCH simpler.
1034 if (mainconfig.radlog_dest == RADLOG_FILES) {
1037 fd = open(mainconfig.log_file,
1038 O_WRONLY | O_APPEND | O_CREAT, 0640);
1041 * Atomic swap. We'd like to keep the old
1042 * FD around so that callers don't
1043 * suddenly find the FD closed, and the
1044 * writes go nowhere. But that's hard to
1045 * do. So... we have the case where a
1046 * log message *might* be lost on HUP.
1048 old_fd = mainconfig.radlog_fd;
1049 mainconfig.radlog_fd = fd;
1054 radlog(L_INFO, "HUP - loading modules");
1057 * Prefer the new module configuration.
1059 module_hup(cf_section_sub_find(cs, "modules"));
1062 * Load new servers BEFORE freeing old ones.
1064 virtual_servers_load(cs);
1066 virtual_servers_free(cc->created - mainconfig.max_request_time * 4);