]> git.tuebingen.mpg.de Git - adu.git/blobdiff - adu.c
Make close_all_tables() static.
[adu.git] / adu.c
diff --git a/adu.c b/adu.c
index ed1b4fa32aee7dac5a7650f2074f8f37df2820d1..bc0689320ffe1823da87e04f7682d5648f51a3f8 100644 (file)
--- a/adu.c
+++ b/adu.c
@@ -1,4 +1,10 @@
-/** \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. */
 #include "adu.h"
 #include <dirent.h> /* readdir() */
 #include <pwd.h>
@@ -106,6 +112,7 @@ static void close_dir_table(void)
 
        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));
@@ -113,7 +120,7 @@ static void close_dir_table(void)
        dir_table = NULL;
 }
 
-void close_all_tables(void)
+static void close_all_tables(void)
 {
        close_dir_table();
        close_user_tables();
@@ -146,15 +153,20 @@ static int init_signals(void)
 
 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));
 }
 
@@ -182,7 +194,6 @@ static int check_args(void)
 static int print_complete_help_and_die(void)
 {
        const char **line;
-       select_cmdline_parser_init(&select_conf);
 
        printf("%s-%s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
        printf("%s\n\n", gengetopt_args_info_purpose);
@@ -205,6 +216,8 @@ static int print_complete_help_and_die(void)
 
        printf("Interactive commands:\n");
        print_interactive_help();
+       cmdline_parser_free(&conf);
+       select_cmdline_parser_free(&select_conf);
        exit(EXIT_FAILURE);
 }
 
@@ -212,16 +225,19 @@ int main(int argc, char **argv)
 {
        int ret;
        struct cmdline_parser_params params = {
-               .override = 0,
+               .override = 1,
                .initialize = 1,
                .check_required = 0,
                .check_ambiguity = 0,
                .print_errors = 0
        };
+       select_cmdline_parser_init(&select_conf);
+       cmdline_parser_init(&conf);
        /* ignore errors and print complete help if --help was given */
        cmdline_parser_ext(argc, argv, &conf, &params);
        if (conf.help_given || conf.detailed_help_given)
                print_complete_help_and_die();
+       cmdline_parser_free(&conf);
        params.check_required = 1;
        params.check_ambiguity = 1;
        params.print_errors = 1;
@@ -245,9 +261,12 @@ int main(int argc, char **argv)
        if (ret < 0)
                goto out;
 out:
+       close_all_tables();
        if (ret < 0) {
                ERROR_LOG("%s\n", adu_strerror(-ret));
                return -EXIT_FAILURE;
        }
+       cmdline_parser_free(&conf);
+       select_cmdline_parser_free(&select_conf);
        return EXIT_SUCCESS;
 }