From 15ae45934bf3980c9be446c41963ba892ee9679f Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 26 May 2008 11:38:47 +0200 Subject: [PATCH] Honor the --database_dir option. --- adu.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/adu.c b/adu.c index 9edcc58..26039ce 100644 --- a/adu.c +++ b/adu.c @@ -10,9 +10,6 @@ DEFINE_ERRLIST; -#define DATABASE_DIR "/tmp/adu" -#define UID_LIST DATABASE_DIR "/" "uid_list" - /** Command line and config file options. */ static struct gengetopt_args_info conf; @@ -176,7 +173,6 @@ static struct osl_table_description dir_table_desc = { .num_columns = NUM_DT_COLUMNS, .flags = 0, .column_descriptions = dir_table_cols, - .dir = DATABASE_DIR }; /** The columns of the id table. */ @@ -245,7 +241,7 @@ static int open_user_table(struct user_info *ui, int create) ui->desc->num_columns = NUM_UT_COLUMNS; ui->desc->flags = 0; ui->desc->column_descriptions = user_table_cols; - ui->desc->dir = para_strdup(DATABASE_DIR); + ui->desc->dir = para_strdup(conf.database_dir_arg); ui->desc->name = make_message("%u", (unsigned)ui->uid); num_uids++; INFO_LOG(".............................uid #%u: %u\n", @@ -291,6 +287,7 @@ static int create_tables(void) { int ret; + dir_table_desc.dir = para_strdup(conf.database_dir_arg); ret = osl_create_table(&dir_table_desc); if (ret < 0) return ret; @@ -692,9 +689,14 @@ static int print_statistics(void) return 1; } +static char *get_uid_list_name(void) +{ + return make_message("%s/uid_list", conf.database_dir_arg); +} + static int write_uid_list(void) { - char *buf; + char *buf, *filename; uint32_t count = 0; struct user_info *ui; size_t size = num_uids * sizeof(uint32_t); @@ -708,13 +710,17 @@ static int write_uid_list(void) continue; write_u32(buf + count++ * sizeof(uint32_t), ui->uid); } - ret = para_write_file(UID_LIST, buf, size); + filename = get_uid_list_name(); + ret = para_write_file(filename, buf, size); + free(filename); free(buf); return ret; } static int open_dir_table(void) { + if (!dir_table_desc.dir) /* we did not create the table */ + dir_table_desc.dir = para_strdup(conf.database_dir_arg); return osl_open_table(&dir_table_desc, &dir_table); } @@ -727,6 +733,7 @@ static void close_dir_table(void) ret = osl_close_table(dir_table, OSL_MARK_CLEAN); if (ret < 0) ERROR_LOG("failed to close dir table: %s\n", error_txt(-ret)); + free((char *)dir_table_desc.dir); dir_table = NULL; } @@ -783,11 +790,12 @@ out: static int read_uid_file(void) { - char *map; size_t size; - int ret = mmap_full_file(UID_LIST, O_RDONLY, (void **)&map, &size, NULL); uint32_t n; + char *filename = get_uid_list_name(), *map; + int ret = mmap_full_file(filename, O_RDONLY, (void **)&map, &size, NULL); + free(filename); if (ret < 0) return ret; num_uids = size / 4; -- 2.39.5