#include <dirent.h> /* readdir() */
#include "gcc-compat.h"
+#include "cmdline.h"
#include "osl.h"
#include "fd.h"
#include "hash.h"
#define DATABASE_DIR "/tmp/adu"
#define UID_LIST DATABASE_DIR "/" "uid_list"
+/** Command line and config file options. */
+static struct gengetopt_args_info conf;
+
struct user_info {
uint32_t uid;
struct osl_table *table;
time_t t1;
char str[255] = "";
- if (ll < 4)
+ if (ll < conf.loglevel_arg)
return;
outfd = stderr;
time(&t1);
return 1;
}
-
+/*
+ * We use a hash table of size s=2^uid_hash_bits to map the uids into the
+ * interval [0..s]. Hash collisions are treated by open addressing, i.e.
+ * unused slots in the table are used to store different uids that hash to the
+ * same slot.
+ *
+ * If a hash collision occurs, different slots are successively probed in order
+ * to find an unused slot for the new uid. Probing is implemented via a second
+ * hash function that maps the uid to h=(uid * PRIME2) | 1, which is always an
+ * odd number.
+ *
+ * An odd number is sufficient to make sure each entry of the hash table gets
+ * probed for probe_num between 0 and s-1 because s is a power of two, hence
+ * the second hash value never hash a common divisor with the hash table size.
+ * IOW: h is invertible in the ring [0..s].
+ */
static uint32_t double_hash(uint32_t uid, uint32_t probe_num)
{
return (uid * PRIME1 + ((uid * PRIME2) | 1) * probe_num)
free_hash_table();
}
-static int com_create(char *dirname)
+static int com_create()
{
int ret = create_tables();
if (ret < 0)
ret = open_dir_table();
if (ret < 0)
return ret;
- ret = scan_dir(dirname);
+ ret = scan_dir(conf.base_dir_arg);
if (ret < 0)
goto out;
ret = write_uid_list();
int main(int argc, char **argv)
{
- int ret = -E_SYNTAX;
- if (argc > 2)
- goto out;
- if (argc == 1)
+ int ret;
+ struct cmdline_parser_params params = {
+ .override = 0,
+ .initialize = 1,
+ .check_required = 0,
+ .check_ambiguity = 0,
+ .print_errors = 1
+ };
+
+ cmdline_parser_ext(argc, argv, &conf, ¶ms); /* aborts on errors */
+ ret = -E_SYNTAX;
+ if (conf.select_given)
ret = com_select();
else
- ret = com_create(argv[1]);
+ ret = com_create();
if (ret < 0)
goto out;
out: