From a100e117dfb202768e7e34d5a81e39cacf81866b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Wed, 19 Mar 2003 11:56:38 +0000 Subject: [PATCH] (main): make sure we don't consider dead slave for select processing (write_stats): use slave_stats_file variable, check return value of strftime (args): allow specifying slave stats file (slave_dead): close the fd when the slave dies git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@11879 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/kadm5/ipropd_master.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/kadm5/ipropd_master.c b/lib/kadm5/ipropd_master.c index 41845f672..ad29e307f 100644 --- a/lib/kadm5/ipropd_master.c +++ b/lib/kadm5/ipropd_master.c @@ -38,6 +38,8 @@ RCSID("$Id$"); static krb5_log_facility *log_facility; +const char *slave_stats_file = KADM5_SLAVE_STATS; + static int make_signal_socket (krb5_context context) { @@ -123,6 +125,10 @@ slave_seen(slave *s) static void slave_dead(slave *s) { + if (s->fd >= 0) { + close (s->fd); + s->fd = -1; + } s->flags |= SLAVE_F_DEAD; slave_seen(s); } @@ -406,12 +412,12 @@ process_msg (krb5_context context, slave *s, int log_fd, static void write_stats(krb5_context context, slave *slaves, u_int32_t current_version) { - char str[30]; + char str[100]; rtbl_t tbl; time_t t = time(NULL); FILE *fp; - fp = fopen(KADM5_SLAVE_STATS, "w"); + fp = fopen(slave_stats_file, "w"); if (fp == NULL) return; @@ -457,8 +463,9 @@ write_stats(krb5_context context, slave *slaves, u_int32_t current_version) else rtbl_add_column_entry(tbl, SLAVE_STATUS, "Up"); - strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", - localtime(&slaves->seen)); + if (strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S %Z", + localtime(&slaves->seen)) == 0) + strlcpy(str, "Unknown time", sizeof(str)); rtbl_add_column_entry(tbl, SLAVE_SEEN, str); slaves = slaves->next; @@ -482,6 +489,7 @@ static struct getargs args[] = { { "keytab", 'k', arg_string, &keytab_str, "keytab to get authentication from", "kspec" }, { "database", 'd', arg_string, &database, "database", "file"}, + { "slave-stats-file", 0, arg_string, &slave_stats_file, "file"}, { "version", 0, arg_flag, &version_flag }, { "help", 0, arg_flag, &help_flag } }; @@ -566,6 +574,8 @@ main(int argc, char **argv) max_fd = max(max_fd, listen_fd); for (p = slaves; p != NULL; p = p->next) { + if (p->flags & SLAVE_F_DEAD) + continue; FD_SET(p->fd, &readset); max_fd = max(max_fd, p->fd); } @@ -584,8 +594,11 @@ main(int argc, char **argv) kadm5_log_get_version_fd (log_fd, ¤t_version); if (current_version > old_version) - for (p = slaves; p != NULL; p = p->next) + for (p = slaves; p != NULL; p = p->next) { + if (p->flags & SLAVE_F_DEAD) + continue; send_diffs (context, p, log_fd, database, current_version); + } } if (ret && FD_ISSET(signal_fd, &readset)) { @@ -604,12 +617,15 @@ main(int argc, char **argv) send_diffs (context, p, log_fd, database, current_version); } - for(p = slaves; ret && p != NULL; p = p->next) + for(p = slaves; ret && p != NULL; p = p->next) { + if (p->flags & SLAVE_F_DEAD) + continue; if (FD_ISSET(p->fd, &readset)) { --ret; if(process_msg (context, p, log_fd, database, current_version)) slave_dead(p); } + } if (ret && FD_ISSET(listen_fd, &readset)) { add_slave (context, keytab, &slaves, listen_fd);