X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=adu.c;h=37a086772fec78a8c099bbfb655e2cb5a734e0b2;hp=9fb70bed1446f41d4a6049db036e28c5bf6d971e;hb=560d397a66ba141f18e13557feae78ca94a25f98;hpb=d0bef44ffe5b6f985f4ba6a718e08afb50f096c6 diff --git a/adu.c b/adu.c index 9fb70be..37a0867 100644 --- a/adu.c +++ b/adu.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Andre Noll + * Copyright (C) 2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -12,7 +12,7 @@ * - 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 + * - Library-type functions: \ref fd.c, \ref format.c, \ref string.c, \ref portable_io.h, \ref bloom.c */ #include "adu.h" @@ -125,6 +125,25 @@ __printf_2_3 void __log(int ll, const char* fmt,...) va_end(argp); } +/** + * adu's version of strerror(3). + * + * \param num The error number. + * + * \return The error text of \a num. + */ +const char *adu_strerror(int num) +{ + assert(num > 0); + if (num == E_OSL) { + assert(osl_errno > 0); + return osl_strerror((osl_errno)); + } + if (IS_SYSTEM_ERROR(num)) + return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1)); + return adu_errlist[num]; +} + static void close_dir_table(void) { int ret; @@ -165,14 +184,24 @@ void check_signals(void) exit(EXIT_FAILURE); } +static int catch_signal(int sig) +{ + struct sigaction act; + + act.sa_handler = signal_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + return sigaction(sig, &act, NULL); +} + 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; - if (signal(SIGPIPE, &signal_handler) == SIG_ERR) - return -E_SIGNAL_SIG_ERR; + if (catch_signal(SIGINT) < 0) + return -E_SIGACTION; + if (catch_signal(SIGTERM) < 0) + return -E_SIGACTION; + if (catch_signal(SIGPIPE) < 0) + return -E_SIGACTION; return 1; } @@ -198,8 +227,10 @@ int open_dir_table(int create) goto out; NOTICE_LOG("creating dir table\n"); ret = osl(osl_create_table(&dir_table_desc)); - if (ret < 0) + if (ret < 0) { + ERROR_LOG("could not create %s\n", dir_table_desc.dir); goto out; + } } INFO_LOG("opening dir table\n"); return osl(osl_open_table(&dir_table_desc, &dir_table)); @@ -259,6 +290,27 @@ static void print_complete_help_and_die(void) exit(EXIT_FAILURE); } +static void get_database_dir_or_die(void) +{ + char *tmp; + + if (conf.database_dir_given) + tmp = adu_strdup(conf.database_dir_arg); + else + tmp = make_message("%s%s", + conf.database_root_arg, conf.base_dir_arg); + /* + * As we change the cwd during database creation, database_dir + * must be an absolute path. + */ + database_dir = absolute_path(tmp); + free(tmp); + if (database_dir) + return; + EMERG_LOG("failed to get absolute path of database dir\n"); + exit(EXIT_FAILURE); +} + /** * The main function of adu. * @@ -300,12 +352,7 @@ int main(int argc, char **argv) ret = init_signals(); if (ret < 0) goto out; - ret = -E_SYNTAX; - if (conf.database_dir_given) - database_dir = adu_strdup(conf.database_dir_arg); - else - database_dir = make_message("%s%s", - conf.database_root_arg, conf.base_dir_arg); + get_database_dir_or_die(); if (conf.select_given) ret = com_select(); else if (conf.create_given)