X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=adu.c;h=deb3e94ccd88bf309263b57a87e307de9e00944c;hp=5b70234913ad2f65933219de7f34961261a63c0b;hb=0fbaae7717847b41f4d1218ce44de44c755397c0;hpb=519fe9b24947295bca2ad54b84a232ccd692a4ae diff --git a/adu.c b/adu.c index 5b70234..deb3e94 100644 --- a/adu.c +++ b/adu.c @@ -9,6 +9,7 @@ #include "portable_io.h" DEFINE_ERRLIST; +int osl_errno; /** Command line and config file options. */ static struct gengetopt_args_info conf; @@ -303,8 +304,7 @@ static int add_directory(char *dirname, uint64_t *dir_num, uint64_t *parent_dir_ dir_objects[DT_BYTES].size = sizeof(*dir_size); dir_objects[DT_FILES].data = dir_files; dir_objects[DT_FILES].size = sizeof(*dir_files); - - return osl_add_row(dir_table, dir_objects); + return osl(osl_add_row(dir_table, dir_objects)); } static uint32_t num_uids; @@ -322,12 +322,12 @@ static int open_user_table(struct user_info *ui, int create) INFO_LOG(".............................uid #%u: %u\n", (unsigned)num_uids, (unsigned)ui->uid); if (create) { - ret = osl_create_table(ui->desc); + ret = osl(osl_create_table(ui->desc)); if (ret < 0) goto err; num_uids++; } - ret = osl_open_table(ui->desc, &ui->table); + ret = osl(osl_open_table(ui->desc, &ui->table)); if (ret < 0) goto err; return 1; @@ -365,7 +365,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); + ret = osl(osl_create_table(&dir_table_desc)); if (ret < 0) return ret; create_hash_table(); @@ -458,9 +458,9 @@ static int update_user_row(struct osl_table *t, uint64_t dir_num, struct osl_row *row; struct osl_object obj = {.data = &dir_num, .size = sizeof(dir_num)}; - int ret = osl_get_row(t, UT_DIR_NUM, &obj, &row); + int ret = osl(osl_get_row(t, UT_DIR_NUM, &obj, &row)); - if (ret < 0 && ret != -E_RB_KEY_NOT_FOUND) + if (ret == -E_OSL && osl_errno != E_OSL_RB_KEY_NOT_FOUND) return ret; if (ret < 0) { /* this is the first file we add */ struct osl_object objects[NUM_UT_COLUMNS]; @@ -473,25 +473,25 @@ static int update_user_row(struct osl_table *t, uint64_t dir_num, objects[UT_FILES].data = &num_files; objects[UT_FILES].size = sizeof(num_files); INFO_LOG("######################### ret: %d\n", ret); - ret = osl_add_row(t, objects); + ret = osl(osl_add_row(t, objects)); INFO_LOG("######################### ret: %d\n", ret); return ret; } else { /* add size and increment file count */ uint64_t num; struct osl_object obj1, obj2 = {.data = &num, .size = sizeof(num)}; - ret = osl_get_object(t, row, UT_BYTES, &obj1); + ret = osl(osl_get_object(t, row, UT_BYTES, &obj1)); if (ret < 0) return ret; num = *(uint64_t *)obj1.data + *add; - ret = osl_update_object(t, row, UT_BYTES, &obj2); + ret = osl(osl_update_object(t, row, UT_BYTES, &obj2)); if (ret < 0) return ret; - ret = osl_get_object(t, row, UT_FILES, &obj1); + ret = osl(osl_get_object(t, row, UT_FILES, &obj1)); if (ret < 0) return ret; num = *(uint64_t *)obj1.data + 1; - return osl_update_object(t, row, UT_FILES, &obj2); + return osl(osl_update_object(t, row, UT_FILES, &obj2)); } } @@ -576,10 +576,10 @@ static int get_dir_name_by_number(uint64_t *dirnum, char **name) int ret; again: - ret = osl_get_row(dir_table, DT_NUM, &obj, &row); + ret = osl(osl_get_row(dir_table, DT_NUM, &obj, &row)); if (ret < 0) goto out; - ret = osl_get_object(dir_table, row, DT_NAME, &obj); + ret = osl(osl_get_object(dir_table, row, DT_NAME, &obj)); if (ret < 0) goto out; if (result) { @@ -588,7 +588,7 @@ again: result = tmp; } else result = para_strdup((char *)obj.data); - ret = osl_get_object(dir_table, row, DT_PARENT_NUM, &obj); + ret = osl(osl_get_object(dir_table, row, DT_PARENT_NUM, &obj)); if (ret < 0) goto out; val = *(uint64_t *)obj.data; @@ -610,11 +610,11 @@ static int get_dir_name_of_row(struct osl_row *dir_table_row, char **name) char *this_dir, *prefix = NULL; *name = NULL; - ret = osl_get_object(dir_table, dir_table_row, DT_NAME, &obj); + ret = osl(osl_get_object(dir_table, dir_table_row, DT_NAME, &obj)); if (ret < 0) return ret; this_dir = para_strdup((char *)obj.data); - ret = osl_get_object(dir_table, dir_table_row, DT_PARENT_NUM, &obj); + ret = osl(osl_get_object(dir_table, dir_table_row, DT_PARENT_NUM, &obj)); if (ret < 0) goto out; if (!*(uint64_t *)obj.data) { @@ -700,7 +700,7 @@ static int global_stats_loop_function(struct osl_row *row, void *data) } if (summary || (gsi->count && (gsi->flags & GSF_PRINT_FILES))) { uint64_t files; - ret = osl_get_object(dir_table, row, DT_FILES, &obj); + ret = osl(osl_get_object(dir_table, row, DT_FILES, &obj)); if (ret < 0) return ret; files = *(uint64_t *)obj.data; @@ -715,7 +715,7 @@ static int global_stats_loop_function(struct osl_row *row, void *data) } if (summary || (gsi->count && (gsi->flags & GSF_PRINT_BYTES))) { uint64_t bytes; - ret = osl_get_object(dir_table, row, DT_BYTES, &obj); + ret = osl(osl_get_object(dir_table, row, DT_BYTES, &obj)); if (ret < 0) return ret; bytes = *(uint64_t *)obj.data; @@ -774,7 +774,6 @@ struct user_stats_info { static int user_stats_loop_function(struct osl_row *row, void *data) { struct user_stats_info *usi = data; - struct osl_row *dir_row; struct osl_object obj; int ret, summary = usi->flags & GSF_COMPUTE_SUMMARY; char formated_value[25]; @@ -783,7 +782,7 @@ static int user_stats_loop_function(struct osl_row *row, void *data) return -E_LOOP_COMPLETE; if (usi->count && (usi->flags & USF_PRINT_DIRNAME)) { char *dirname; - ret = osl_get_object(usi->ui->table, row, UT_DIR_NUM, &obj); + ret = osl(osl_get_object(usi->ui->table, row, UT_DIR_NUM, &obj)); if (ret < 0) return ret; ret = get_dir_name_by_number((uint64_t *)obj.data, &dirname); @@ -797,7 +796,7 @@ static int user_stats_loop_function(struct osl_row *row, void *data) } if (summary || (usi->count && (usi->flags & USF_PRINT_FILES))) { uint64_t files; - ret = osl_get_object(usi->ui->table, row, UT_FILES, &obj); + ret = osl(osl_get_object(usi->ui->table, row, UT_FILES, &obj)); if (ret < 0) return ret; files = *(uint64_t *)obj.data; @@ -813,7 +812,7 @@ static int user_stats_loop_function(struct osl_row *row, void *data) } if (summary || (usi->count && (usi->flags & USF_PRINT_BYTES))) { uint64_t bytes; - ret = osl_get_object(usi->ui->table, row, UT_BYTES, &obj); + ret = osl(osl_get_object(usi->ui->table, row, UT_BYTES, &obj)); if (ret < 0) return ret; bytes = *(uint64_t *)obj.data; @@ -848,13 +847,13 @@ static void print_user_stats(void) printf("************************************************ uid %u\n", (unsigned) ui->uid); printf("----------------- Largest dirs -------------------\n"); - osl_rbtree_loop_reverse(ui->table, UT_BYTES, &usi, - user_stats_loop_function); + osl(osl_rbtree_loop_reverse(ui->table, UT_BYTES, &usi, + user_stats_loop_function)); printf("---------- dirs containing most files ------------\n"); usi.count = conf.limit_arg, usi.flags = USF_PRINT_DIRNAME | USF_PRINT_FILES; - osl_rbtree_loop_reverse(ui->table, UT_FILES, &usi, - user_stats_loop_function); + osl(osl_rbtree_loop_reverse(ui->table, UT_FILES, &usi, + user_stats_loop_function)); } } @@ -867,16 +866,16 @@ static int print_statistics(void) }; printf("----------------- Largest dirs -------------------\n"); - ret = osl_rbtree_loop_reverse(dir_table, DT_BYTES, &gsi, - global_stats_loop_function); + ret = osl(osl_rbtree_loop_reverse(dir_table, DT_BYTES, &gsi, + global_stats_loop_function)); if (ret < 0 && ret != -E_LOOP_COMPLETE) return ret; gsi.count = conf.limit_arg; gsi.flags = GSF_PRINT_DIRNAME | GSF_PRINT_FILES; printf("---------- dirs containing most files ------------\n"); - ret = osl_rbtree_loop_reverse(dir_table, DT_FILES, &gsi, - global_stats_loop_function); + ret = osl(osl_rbtree_loop_reverse(dir_table, DT_FILES, &gsi, + global_stats_loop_function)); if (ret < 0 && ret != -E_LOOP_COMPLETE) return ret; @@ -922,7 +921,7 @@ 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); + return osl(osl_open_table(&dir_table_desc, &dir_table)); } static void close_dir_table(void) @@ -931,9 +930,9 @@ static void close_dir_table(void) if (!dir_table) return; - ret = osl_close_table(dir_table, OSL_MARK_CLEAN); + ret = osl(osl_close_table(dir_table, OSL_MARK_CLEAN)); if (ret < 0) - ERROR_LOG("failed to close dir table: %s\n", error_txt(-ret)); + ERROR_LOG("failed to close dir table: %s\n", adu_strerror(-ret)); free((char *)dir_table_desc.dir); dir_table = NULL; } @@ -944,10 +943,10 @@ static void close_user_table(struct user_info *ui) if (!ui || !ui_used(ui) || !ui_admissible(ui)) return; - ret = osl_close_table(ui->table, OSL_MARK_CLEAN); + ret = osl(osl_close_table(ui->table, OSL_MARK_CLEAN)); if (ret < 0) ERROR_LOG("failed to close user table %u: %s\n", - (unsigned) ui->uid, error_txt(-ret)); + (unsigned) ui->uid, adu_strerror(-ret)); free((char *)ui->desc->name); ui->desc->name = NULL; free((char *)ui->desc->dir); @@ -1042,11 +1041,22 @@ static int check_args(void) { int i, ret; + /* remove trailing slashes from base-dir arg */ + if (conf.base_dir_given) { + size_t len = strlen(conf.base_dir_arg); + for (;;) { + if (!len) /* empty string */ + return -ERRNO_TO_ERROR(EINVAL); + if (!--len) /* length 1 is always OK */ + break; + if (conf.base_dir_arg[len] != '/') + break; /* no trailing slash, also OK */ + conf.base_dir_arg[len] = '\0'; + } + } if (!conf.uid_given) return 0; - admissible_uids = para_malloc(conf.uid_given * sizeof(*admissible_uids)); - for (i = 0; i < conf.uid_given; i++) { ret = parse_uid_range(conf.uid_arg[i], admissible_uids + i); if (ret < 0) @@ -1084,7 +1094,7 @@ int main(int argc, char **argv) out: free(admissible_uids); if (ret < 0) { - ERROR_LOG("%s\n", error_txt(-ret)); + ERROR_LOG("%s\n", adu_strerror(-ret)); return -EXIT_FAILURE; } return EXIT_SUCCESS;