- if (!num_uids)
- return 0;
- buf = para_malloc(size);
- FOR_EACH_USER(ui) {
- if (!ui->table)
- continue;
- write_u32(buf + count++ * sizeof(uint32_t), ui->uid);
- }
- ret = para_write_file(UID_LIST, buf, size);
- free(buf);
- return ret;
-}
-
-static int open_dir_table(void)
-{
- return osl_open_table(&dir_table_desc, &dir_table);
-}
-
-static void close_dir_table(void)
-{
- int ret;
-
- if (!dir_table)
- return;
- ret = osl_close_table(dir_table, OSL_MARK_CLEAN);
- if (ret < 0)
- ERROR_LOG("failed to close dir table: %s\n", error_txt(-ret));
- dir_table = NULL;
-}
-
-static void close_user_table(struct user_info *ui)
-{
- int ret;
-
- if (!ui || !ui->table)
- return;
- ret = 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));
- free((char *)ui->desc->name);
- ui->desc->name = NULL;
- free((char *)ui->desc->dir);
- ui->desc->dir = NULL;
- free(ui->desc);
- ui->desc = NULL;
- ui->table = NULL;
-}
-
-static void close_user_tables(void)
-{
- struct user_info *ui;
-
- FOR_EACH_USER(ui)
- close_user_table(ui);
-}
-
-static void close_all_tables(void)
-{
- close_dir_table();
- close_user_tables();
- free_hash_table();
-}
-
-static int com_create(char *dirname)
-{
- int ret = create_tables();
- if (ret < 0)
- return ret;
- ret = open_dir_table();
- if (ret < 0)
- return ret;
- ret = scan_dir(dirname);
- if (ret < 0)
- goto out;
- ret = write_uid_list();
-out:
- close_all_tables();
- return ret;
-}
-
-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;
-
- if (ret < 0)
- return ret;
- num_uids = size / 4;
- /* hash table size should be a power of two and larger than the number of uids */
- uid_hash_table_size = 4;
- while (uid_hash_table_size < num_uids)
- uid_hash_table_size *= 2;
- create_hash_table();
- for (n = 0; n < num_uids; n++) {
- uint32_t uid = read_u32(map + n * sizeof(uid));
- ret = search_uid(uid, OPEN_USER_TABLE, NULL);
- if (ret < 0)
- goto out;
- }
-out:
- para_munmap(map, size);
- return ret;
-}
-
-static int com_select(void)
-{
- int ret;
-
- ret = open_dir_table();
- if (ret < 0)
- return ret;
- ret = read_uid_file();
- if (ret < 0)
- return ret;
- print_statistics();
- close_all_tables();
- return 1;
+ if (conf.help_given)
+ line = gengetopt_args_info_help;
+ else
+ line = gengetopt_args_info_detailed_help;
+
+ printf("adu command line options:\n");
+ printf("=========================\n");
+ for (; *line; line++)
+ printf("%s\n", *line);
+ if (conf.help_given)
+ line = select_args_info_help;
+ else
+ line = select_args_info_detailed_help;
+ printf("select options:\n");
+ printf("===============\n");
+ for (; *line; line++)
+ printf("%s\n", *line);
+ printf("interactive commands:\n");
+ printf("=====================\n");
+ print_interactive_help();
+ exit(EXIT_FAILURE);