aboutsummaryrefslogtreecommitdiff
path: root/src/slave
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2014-01-24 16:52:47 -0500
committerGreg Hudson <ghudson@mit.edu>2014-02-20 20:42:47 -0500
commit6a4a4b7b5e3265e4a811a9fd72c2534e6c5f5fd4 (patch)
treec7dff9c0ec49836e715f901a97724d63088b8118 /src/slave
parent71d028f1054deb186807e7c8048218b82b478422 (diff)
downloadkrb5-6a4a4b7b5e3265e4a811a9fd72c2534e6c5f5fd4.zip
krb5-6a4a4b7b5e3265e4a811a9fd72c2534e6c5f5fd4.tar.gz
krb5-6a4a4b7b5e3265e4a811a9fd72c2534e6c5f5fd4.tar.bz2
Simplify ulog_map
Get rid of the caller parameter. The kproplog semantics (without -R) for mapping the ulog are simple and almost completely different from other users of the ulog, so implement them as a static helper in kproplog. With hierarchical iprop, kpropd will need the same semantics as FKCOMMAND and FKADMIND, which were already identical. Get rid of the db_args parameter, since ulog_map no longer opens the database after #7552. Remove an inoperative lseek() call when creating a new ulog file. Rename ulog_filesize to filesize and compute it from scratch each time we use it, for easier analysis. If kdb_hmagic is zero, init the ulog header but don't skip the rest of the function; it's possible that we need to expand the ulog file. Remove an unneeded conditional before calling extend_file_to for an existing ulog. ticket: 7855
Diffstat (limited to 'src/slave')
-rw-r--r--src/slave/kpropd.c2
-rw-r--r--src/slave/kproplog.c54
2 files changed, 35 insertions, 21 deletions
diff --git a/src/slave/kpropd.c b/src/slave/kpropd.c
index 65fb3e8..3573a26 100644
--- a/src/slave/kpropd.c
+++ b/src/slave/kpropd.c
@@ -1172,7 +1172,7 @@ parse_args(char **argv)
ulog_set_role(kpropd_context, IPROP_SLAVE);
if (ulog_map(kpropd_context, params.iprop_logfile,
- params.iprop_ulogsize, FKPROPD, db_args)) {
+ params.iprop_ulogsize)) {
com_err(progname, errno, _("Unable to map log!\n"));
exit(1);
}
diff --git a/src/slave/kproplog.c b/src/slave/kproplog.c
index 853aa06..ab49a0f 100644
--- a/src/slave/kproplog.c
+++ b/src/slave/kproplog.c
@@ -11,6 +11,7 @@
#include <locale.h>
#include <stdio.h>
#include <sys/types.h>
+#include <sys/mman.h>
#include <time.h>
#include <limits.h>
#include <locale.h>
@@ -409,6 +410,24 @@ print_update(kdb_hlog_t *ulog, uint32_t entry, uint32_t ulogentries,
}
}
+/* Return a read-only mmap of the ulog, or NULL on failure. Assumes fd is
+ * released on process exit. */
+static kdb_hlog_t *
+map_ulog(const char *filename)
+{
+ int fd;
+ struct stat st;
+ kdb_hlog_t *ulog;
+
+ fd = open(filename, O_RDONLY);
+ if (fd == -1)
+ return NULL;
+ if (fstat(fd, &st) < 0)
+ return NULL;
+ ulog = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ return (ulog == MAP_FAILED) ? NULL : ulog;
+}
+
int
main(int argc, char **argv)
{
@@ -418,7 +437,6 @@ main(int argc, char **argv)
uint32_t entry = 0;
krb5_context context;
kadm5_config_params params;
- kdb_log_context *log_ctx;
kdb_hlog_t *ulog = NULL;
setlocale(LC_ALL, "");
@@ -458,17 +476,23 @@ main(int argc, char **argv)
printf(_("\nKerberos update log (%s)\n"), params.iprop_logfile);
- if (ulog_map(context, params.iprop_logfile, 0,
- reset ? FKADMIND : FKPROPLOG, NULL)) {
- fprintf(stderr, _("Unable to map log file %s\n\n"),
- params.iprop_logfile);
- exit(1);
+ if (reset) {
+ if (ulog_map(context, params.iprop_logfile, params.iprop_ulogsize)) {
+ fprintf(stderr, _("Unable to map log file %s\n\n"),
+ params.iprop_logfile);
+ exit(1);
+ }
+ if (ulog_init_header(context) != 0) {
+ fprintf(stderr, _("Couldn't reinitialize ulog file %s\n\n"),
+ params.iprop_logfile);
+ exit(1);
+ }
+ printf(_("Reinitialized the ulog.\n"));
+ exit(0);
}
- log_ctx = context->kdblog_context;
- if (log_ctx) {
- ulog = log_ctx->ulog;
- } else {
+ ulog = map_ulog(params.iprop_logfile);
+ if (ulog == NULL) {
fprintf(stderr, _("Unable to map log file %s\n\n"),
params.iprop_logfile);
exit(1);
@@ -479,16 +503,6 @@ main(int argc, char **argv)
exit(1);
}
- if (reset) {
- if (ulog_init_header(context) != 0) {
- fprintf(stderr, _("Couldn't reinitialize ulog file %s\n\n"),
- params.iprop_logfile);
- exit(1);
- }
- printf(_("Reinitialized the ulog.\n"));
- exit(0);
- }
-
printf(_("Update log dump :\n"));
printf(_("\tLog version # : %u\n"), ulog->db_version_num);
printf(_("\tLog state : "));