]> git.tuebingen.mpg.de Git - adu.git/blobdiff - adu.c
manual: Add short option example.
[adu.git] / adu.c
diff --git a/adu.c b/adu.c
index 7d8c9abd0191b6d4c84036bcc70e7e91d2cf03f3..37a086772fec78a8c099bbfb655e2cb5a734e0b2 100644 (file)
--- a/adu.c
+++ b/adu.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -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));