-/** \file adu.c The main functions used by all modes of operation. */
+/*
+ * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
+ *
+ * Licensed under the GPL v2. For licencing details see COPYING.
+ */
+
+/** \file adu.c \brief The main functions used by all modes of operation. */
+
+/**
+ * \mainpage adu API reference
+ *
+ * - Modes of operation: \ref select.c, \ref create.c, \ref interactive.c
+ * - User handling: \ref user.c
+ * - Error handling: \ref error.h
+ * - Library-type functions: \ref fd.c, \ref format.c, \ref string.c, \ref portable_io.h
+ */
+
#include "adu.h"
#include <dirent.h> /* readdir() */
#include <pwd.h>
#include "string.h"
#include "error.h"
+/** Define the array of error descriptions. */
DEFINE_ERRLIST;
+
+/**
+ * The error code of the last called osl library function.
+ *
+ * \sa osl().
+ */
int osl_errno;
/** In case a signal is received, its number is stored here. */
if (!dir_table)
return;
+ NOTICE_LOG("closing dir table\n");
ret = osl(osl_close_table(dir_table, OSL_MARK_CLEAN));
if (ret < 0)
ERROR_LOG("failed to close dir table: %s\n", adu_strerror(-ret));
dir_table = NULL;
}
-void close_all_tables(void)
+static void close_all_tables(void)
{
close_dir_table();
close_user_tables();
signum = s;
}
+/**
+ * Check whether to terminate adu.
+ *
+ * Check whether a signal was caught that should terminate the
+ * adu process. If yes, close all osl tables and exit gracefully.
+ */
void check_signals(void)
{
if (likely(!signum))
return 1;
}
+/**
+ * Open the directory table.
+ *
+ * \param create If non-zero, create the table first.
+ *
+ * \return Standard.
+ */
int open_dir_table(int create)
{
+
+ if (dir_table)
+ return 1;
dir_table_desc.dir = adu_strdup(conf.database_dir_arg);
if (create) {
+ NOTICE_LOG("creating dir table\n");
int ret = osl(osl_create_table(&dir_table_desc));
if (ret < 0) {
free((char *)dir_table_desc.dir);
return ret;
}
}
+ INFO_LOG("opening dir table\n");
return osl(osl_open_table(&dir_table_desc, &dir_table));
}
return 1;
}
-static int print_complete_help_and_die(void)
+static void print_complete_help_and_die(void)
{
const char **line;
exit(EXIT_FAILURE);
}
+/**
+ * The main function of adu.
+ *
+ * \param argc Usual argument count.
+ * \param argv Usual argument vector.
+ *
+ * Check command line options, init the signal handlers and
+ * call the main function of the selected mode.
+ *
+ * \return \p EXIT_SUCCESS on success, \p EXIT_FAILURE otherwise.
+ */
int main(int argc, char **argv)
{
int ret;
if (ret < 0)
goto out;
out:
+ close_all_tables();
if (ret < 0) {
ERROR_LOG("%s\n", adu_strerror(-ret));
return -EXIT_FAILURE;