+void close_all_tables(void)
+{
+ close_dir_table();
+ close_user_tables();
+ free_hash_table();
+}
+
+static void signal_handler(int s)
+{
+ signum = s;
+}
+
+void check_signals(void)
+{
+ if (likely(!signum))
+ return;
+ EMERG_LOG("caught signal %d\n", signum);
+ close_all_tables();
+ exit(EXIT_FAILURE);
+}
+
+static int init_signals(void)
+{
+ if (signal(SIGINT, &signal_handler) == SIG_ERR)
+ return -E_SIGNAL_SIG_ERR;
+ if (signal(SIGTERM, &signal_handler) == SIG_ERR)
+ return -E_SIGNAL_SIG_ERR;
+ 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 has never 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)
+ % uid_hash_table_size;
+}
+
+static int uid_is_admissible(uint32_t uid)
+{
+ int i;
+
+ for (i = 0; i < conf.uid_given; i++) {
+ struct uid_range *ur = admissible_uids + i;
+
+ if (ur->low <= uid && ur->high >= uid)
+ break;
+ }
+ i = !conf.uid_given || i < conf.uid_given;
+ DEBUG_LOG("uid %u is %sadmissible\n", (unsigned)uid,
+ i? "" : "not ");
+ return i;
+}
+
+int search_uid(uint32_t uid, enum search_uid_flags flags,
+ struct user_info **ui_ptr)
+{
+ uint32_t p;
+
+ for (p = 0; p < uid_hash_table_size; p++) {
+ struct user_info *ui = uid_hash_table + double_hash(uid, p);
+
+ if (!ui_used(ui)) {
+ int ret;
+ if (!flags)
+ return -E_BAD_UID;
+ ui->uid = uid;
+ ui->flags |= UI_FL_SLOT_USED;
+ if (!uid_is_admissible(uid))
+ return 0;
+ ui->flags |= UI_FL_ADMISSIBLE;
+ ret = open_user_table(ui, flags & CREATE_USER_TABLE);
+ if (ret < 0)
+ return ret;
+
+ if (ui_ptr)
+ *ui_ptr = ui;
+ return 1;
+ }
+ if (ui->uid != uid)
+ continue;
+ if (ui_ptr)
+ *ui_ptr = ui;
+ return 0;
+ }
+ return flags? -E_HASH_TABLE_OVERFLOW : -E_BAD_UID;
+}
+
+static int update_user_row(struct osl_table *t, uint64_t dir_num,