]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
patch from Jan-Piet Mens.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 18 Feb 2008 08:49:11 +0000 (08:49 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 18 Feb 2008 08:49:11 +0000 (08:49 +0000)
Error checking added.

git-svn-id: file:///svn/unbound/trunk@960 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
smallapp/unbound-host.c

index 5adc72ed3f8693b697a7457a3a70c30cb32d8733..3380ae39653eb389be2afaa478f0e36ac1cb23c7 100644 (file)
@@ -1,3 +1,7 @@
+18 February 2008: Wouter
+       - patch to unbound-host from Jan-Piet Mens.
+       - unbound host prints errors if fails to configure context.
+
 15 February 2008: Wouter
        - added FreeBSD rc.d script to contrib.
        - --prefix option for configure also changes directory: pidfile:
index b3f0404ae007f85395146f9e396a111e37a7ce44..480f7ab969ca0b3766a19f2ffeb783be52284f8c 100644 (file)
@@ -53,6 +53,7 @@ usage()
 {
        printf("Usage:  unbound-host [-vdh] [-c class] [-t type] hostname\n");
        printf("                     [-y key] [-f keyfile] [-F namedkeyfile]\n");
+       printf("                     [-C configfile]\n");
        printf("  Queries the DNS for information.\n");
        printf("  The hostname is looked up for IP4, IP6 and mail.\n");
        printf("  If an ip-address is given a reverse lookup is done.\n");
@@ -63,6 +64,7 @@ usage()
        printf("                        -y 'example.com DS 31560 5 1 1CFED8478...'\n");
        printf("    -f keyfile          read trust anchors from file, with lines as -y.\n");
        printf("    -F keyfile          read named.conf-style trust anchors.\n");
+       printf("    -C config           use the specified unbound.conf\n");
        printf("    -v                  be more verbose, shows nodata and security.\n");
        printf("    -d                  debug, traces the action, -d -d shows more.\n");
        printf("    -h                  show this usage help.\n");
@@ -378,6 +380,16 @@ lookup(struct ub_ctx* ctx, const char* nm, const char* qt, const char* qc)
        free(realq);
 }
 
+/** print error if any */
+static void
+check_ub_res(int r)
+{
+       if(r != 0) {
+               fprintf(stderr, "error: %s\n", ub_strerror(r));
+               exit(1);
+       }
+}
+
 /** getopt global, in case header files fail to declare it. */
 extern int optind;
 /** getopt global, in case header files fail to declare it. */
@@ -399,16 +411,19 @@ int main(int argc, char* argv[])
        }
 
        /* parse the options */
-       while( (c=getopt(argc, argv, "F:c:df:ht:vy:")) != -1) {
+       while( (c=getopt(argc, argv, "F:c:df:ht:vy:C:")) != -1) {
                switch(c) {
                case 'c':
                        qclass = optarg;
                        break;
+               case 'C':
+                       check_ub_res(ub_ctx_config(ctx, optarg));
+                       break;
                case 'd':
                        debuglevel++;
                        if(debuglevel < 2) 
                                debuglevel = 2; /* at least VERB_DETAIL */
-                       ub_ctx_debuglevel(ctx, debuglevel);
+                       check_ub_res(ub_ctx_debuglevel(ctx, debuglevel));
                        break;
                case 't':
                        qtype = optarg;
@@ -417,13 +432,13 @@ int main(int argc, char* argv[])
                        verb++;
                        break;
                case 'y':
-                       ub_ctx_add_ta(ctx, optarg);
+                       check_ub_res(ub_ctx_add_ta(ctx, optarg));
                        break;
                case 'f':
-                       ub_ctx_add_ta_file(ctx, optarg);
+                       check_ub_res(ub_ctx_add_ta_file(ctx, optarg));
                        break;
                case 'F':
-                       ub_ctx_trustedkeys(ctx, optarg);
+                       check_ub_res(ub_ctx_trustedkeys(ctx, optarg));
                        break;
                case '?':
                case 'h':