From a1d3d95f0c0d1593559f5df28cd9cbf4f82ae8f9 Mon Sep 17 00:00:00 2001 From: Geoffrey King Date: Wed, 8 Jul 1998 09:12:05 +0000 Subject: [PATCH] These additions cause the KDC to react to SIGHUP by closing and reopening its log files, so that logfile management utilities may now compress old logs and then kill -HUP the KDC process to get them to use fresh log files. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10627 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/krb5/ChangeLog | 4 ++++ src/include/krb5/adm_proto.h | 1 + src/kdc/ChangeLog | 13 ++++++++++++ src/kdc/extern.c | 1 + src/kdc/extern.h | 1 + src/kdc/main.c | 33 +++++++++++++++++++++++++++++- src/kdc/network.c | 4 ++++ src/lib/kadm5/ChangeLog | 5 +++++ src/lib/kadm5/logger.c | 39 ++++++++++++++++++++++++++++++++++++ 9 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/include/krb5/ChangeLog b/src/include/krb5/ChangeLog index 66a0d0598..202608002 100644 --- a/src/include/krb5/ChangeLog +++ b/src/include/krb5/ChangeLog @@ -1,3 +1,7 @@ +Wed Jul 8 04:30:22 1998 Geoffrey King + + * adm_proto.h: Added prototype for new function krb5_klog_reopen() + Thu Apr 16 23:50:08 1998 Tom Yu * configure.in: Search for /var/tmp first when determining rcache diff --git a/src/include/krb5/adm_proto.h b/src/include/krb5/adm_proto.h index 1097b3cba..d66e010c4 100644 --- a/src/include/krb5/adm_proto.h +++ b/src/include/krb5/adm_proto.h @@ -137,6 +137,7 @@ krb5_error_code krb5_klog_init krb5_boolean)); void krb5_klog_close KRB5_PROTOTYPE((krb5_context)); int krb5_klog_syslog KRB5_PROTOTYPE((int, const char *, ...)); +void krb5_klog_reopen KRB5_PROTOTYPE((krb5_context)); /* alt_prof.c */ krb5_error_code krb5_aprof_init diff --git a/src/kdc/ChangeLog b/src/kdc/ChangeLog index 193202828..4e2264a51 100644 --- a/src/kdc/ChangeLog +++ b/src/kdc/ChangeLog @@ -1,3 +1,16 @@ +Wed Jul 8 04:36:28 1998 Geoffrey King + + * extern.h: Added declaration for new variable + signal_requests_hup, which is set when the KDC + is sent a SIGHUP + + * extern.c: Added definition for signal_requests_hup + + * main.c: Added new signal handling code for SIGHUP, including + the new function request_hup() + + * network.c: Check signal_requests_hup in the main KDC loop + Fri May 8 18:46:59 1998 Theodore Y. Ts'o * kerberos_v4.c (krb4_stime): Print 4 digit years in Krb4 log diff --git a/src/kdc/extern.c b/src/kdc/extern.c index 757df67b8..c3f92ac07 100644 --- a/src/kdc/extern.c +++ b/src/kdc/extern.c @@ -35,3 +35,4 @@ krb5_timestamp kdc_infinity = KRB5_INT32_MAX; /* XXX */ krb5_rcache kdc_rcache = (krb5_rcache) NULL; volatile int signal_requests_exit = 0; /* gets set when signal hits */ +volatile int signal_requests_hup = 0; /* ditto */ diff --git a/src/kdc/extern.h b/src/kdc/extern.h index 313f20e11..e8de8a7e3 100644 --- a/src/kdc/extern.h +++ b/src/kdc/extern.h @@ -95,4 +95,5 @@ extern krb5_timestamp kdc_infinity; /* greater than all other timestamps */ extern krb5_rcache kdc_rcache; /* replay cache */ extern volatile int signal_requests_exit; +extern volatile int signal_requests_hup; #endif /* __KRB5_KDC_EXTERN__ */ diff --git a/src/kdc/main.c b/src/kdc/main.c index d58ebc80e..bf2f71243 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -46,6 +46,7 @@ kdc_realm_t *find_realm_data PROTOTYPE((char *, krb5_ui_4)); void usage PROTOTYPE((char *)); krb5_sigtype request_exit PROTOTYPE((int)); +krb5_sigtype request_hup PROTOTYPE((int)); void setup_signal_handlers PROTOTYPE((void)); @@ -57,6 +58,10 @@ static int nofork = 0; static char *kdc_current_rcname = (char *) NULL; static int rkey_init_done = 0; +#ifdef POSIX_SIGNALS +static struct sigaction s_action; +#endif /* POSIX_SIGNALS */ + #define KRB5_KDC_MAX_REALMS 32 #ifdef USE_RCACHE @@ -565,12 +570,35 @@ request_exit(signo) #endif } +krb5_sigtype +request_hup(signo) + int signo; +{ + signal_requests_hup = 1; + +#ifdef POSIX_SIGTYPE + return; +#else + return(0); +#endif +} + void setup_signal_handlers() { +#ifdef POSIX_SIGNALS + (void) sigemptyset(&s_action.sa_mask); + s_action.saflags = 0; + s_action.sa_handler = request_exit; + (void) sigaction(SIGINT, &s_action, (struct sigaction *) NULL); + (void) sigaction(SIGTERM, &s_action, (struct sigaction *) NULL); + s_action.sa_handler = request_hup; + (void) sigaction(SIGHUP, &s_action, (struct sigaction *) NULL); +#else /* POSIX_SIGNALS */ signal(SIGINT, request_exit); - signal(SIGHUP, request_exit); signal(SIGTERM, request_exit); + signal(SIGHUP, request_hup); +#endif /* POSIX_SIGNALS */ return; } @@ -836,3 +864,6 @@ char *argv[]; return errout; } + + + diff --git a/src/kdc/network.c b/src/kdc/network.c index f2cc0b566..edc172dff 100644 --- a/src/kdc/network.c +++ b/src/kdc/network.c @@ -208,6 +208,10 @@ const char *prog; return KDC5_NONET; while (!signal_requests_exit) { + if (signal_requests_hup) { + krb5_klog_reopen(); + signal_requests_hup = 0; + } readfds = select_fds; nfound = select(select_nfds, &readfds, 0, 0, 0); if (nfound == -1) { diff --git a/src/lib/kadm5/ChangeLog b/src/lib/kadm5/ChangeLog index 26a14ad6c..ae8bb7e1b 100644 --- a/src/lib/kadm5/ChangeLog +++ b/src/lib/kadm5/ChangeLog @@ -1,3 +1,8 @@ +Wed Jul 8 04:48:50 1998 Geoffrey J. King + + * logger.c: Add the function krb5_klog_reopen() which closes + and reopens the log files. + Mon Apr 6 19:40:05 1998 Tom Yu * Makefile.in (includes): Don't call mkdir unless the directory diff --git a/src/lib/kadm5/logger.c b/src/lib/kadm5/logger.c index 379b5ffda..2677e448d 100644 --- a/src/lib/kadm5/logger.c +++ b/src/lib/kadm5/logger.c @@ -942,4 +942,43 @@ krb5_klog_syslog(priority, format, va_alist) va_end(pvar); return(retval); } + +/* + * krb5_klog_reopen() - Close and reopen any open (non-syslog) log files. + * This function is called when a SIGHUP is received + * so that external log-archival utilities may + * alert the Kerberos daemons that they should get + * a new file descriptor for the give filename. + */ +void +krb5_klog_reopen(kcontext) +krb5_context kcontext; +{ + int lindex; + FILE *f; + + /* + * Only logs which are actually files need to be closed + * and reopened in response to a SIGHUP + */ + for (lindex = 0; lindex < log_control.log_nentries; lindex++) { + if (log_control.log_entries[lindex].log_type == K_LOG_FILE) { + fclose(log_control.log_entries[lindex].lfu_filep); + /* + * In case the old logfile did not get moved out of the + * way, open for append to prevent squashing the old logs. + */ + f = fopen(log_control.log_entries[lindex].lfu_fname, "a+"); + if (f) { + log_control.log_entries[lindex].lfu_filep = f; + } else { + fprintf(stderr, "Couldn't open log file %s: %s\n", + log_control.log_entries[lindex].lfu_fname, + error_message(errno)); + } + } + } +} + #endif /* !defined(_MSDOS) */ + -- 2.26.2