From: Alan T. DeKok Date: Tue, 12 Feb 2013 14:56:29 +0000 (-0500) Subject: Added radmin command "hup main.log". Closes issue #121 X-Git-Tag: release_2_2_1~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70e3f4587f7871ce7216f62edffbeb8befef19a2;p=thirdparty%2Ffreeradius-server.git Added radmin command "hup main.log". Closes issue #121 --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index 0c77a010166..5db484e2446 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -616,6 +616,7 @@ extern struct main_config_t mainconfig; int read_mainconfig(int reload); int free_mainconfig(void); void hup_mainconfig(void); +void hup_logfile(void); void fr_suid_down(void); void fr_suid_up(void); void fr_suid_down_permanent(void); diff --git a/src/main/command.c b/src/main/command.c index 3f70fc010ea..5aae86b438d 100644 --- a/src/main/command.c +++ b/src/main/command.c @@ -305,6 +305,14 @@ static int command_hup(rad_listen_t *listener, int argc, char *argv[]) return 1; } + /* + * Hack a "main" HUP thingy + */ + if (strcmp(argv[0], "main.log") == 0) { + hup_logfile(); + return 1; + } + cs = cf_section_find("modules"); if (!cs) return 0; diff --git a/src/main/mainconfig.c b/src/main/mainconfig.c index 675118b937e..843101b8640 100644 --- a/src/main/mainconfig.c +++ b/src/main/mainconfig.c @@ -1016,6 +1016,29 @@ int free_mainconfig(void) return 0; } +void hup_logfile(void) +{ + int fd, old_fd; + + if (mainconfig.radlog_dest != RADLOG_FILES) return; + + fd = open(mainconfig.log_file, + O_WRONLY | O_APPEND | O_CREAT, 0640); + if (fd >= 0) { + /* + * Atomic swap. We'd like to keep the old + * FD around so that callers don't + * suddenly find the FD closed, and the + * writes go nowhere. But that's hard to + * do. So... we have the case where a + * log message *might* be lost on HUP. + */ + old_fd = mainconfig.radlog_fd; + mainconfig.radlog_fd = fd; + close(old_fd); + } +} + void hup_mainconfig(void) { cached_config_t *cc; @@ -1056,25 +1079,7 @@ void hup_mainconfig(void) * The "open log file" code is here rather than in log.c, * because it makes that function MUCH simpler. */ - if (mainconfig.radlog_dest == RADLOG_FILES) { - int fd, old_fd; - - fd = open(mainconfig.log_file, - O_WRONLY | O_APPEND | O_CREAT, 0640); - if (fd >= 0) { - /* - * Atomic swap. We'd like to keep the old - * FD around so that callers don't - * suddenly find the FD closed, and the - * writes go nowhere. But that's hard to - * do. So... we have the case where a - * log message *might* be lost on HUP. - */ - old_fd = mainconfig.radlog_fd; - mainconfig.radlog_fd = fd; - close(old_fd); - } - } + hup_logfile(); radlog(L_INFO, "HUP - loading modules");