]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Test, exit value.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 15 Sep 2008 10:36:13 +0000 (10:36 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 15 Sep 2008 10:36:13 +0000 (10:36 +0000)
git-svn-id: file:///svn/unbound/trunk@1236 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
smallapp/unbound-control.c
testdata/09-unbound-control.tpkg [new file with mode: 0644]

index 261d51a57bba70916d9519d5933c57104a2ba9e9..f14071c433169bd3d122635f68a1c89eb16a14a8 100644 (file)
@@ -1,5 +1,6 @@
 15 September 2008: Wouter
        - working start, stop, reload commands for unbound-control.
+       - test for unbound-control working; better exit value for control.
 
 12 September 2008: Wouter
        - removed browser control mentions. Proto speccy.
index f4446c3c3bb38c0b1ea557f85814e86178a7d6ee..af34cb78c5f6e24bd6868186452b922b432cd680 100644 (file)
@@ -183,12 +183,13 @@ setup_ssl(SSL_CTX* ctx, int fd)
 }
 
 /** send command and display result */
-static void
+static int
 go_cmd(SSL* ssl, int argc, char* argv[])
 {
        char* pre="UBCT";
        char* space=" ";
        char* newline="\n";
+       int was_error = 0, first_line = 1;
        int r, i;
        char buf[1024];
        if(SSL_write(ssl, pre, (int)strlen(pre)) <= 0)
@@ -212,15 +213,19 @@ go_cmd(SSL* ssl, int argc, char* argv[])
                }
                buf[r] = 0;
                printf("%s", buf);
+               if(first_line && strncmp(buf, "error", 5) == 0)
+                       was_error = 1;
+               first_line = 0;
        }
+       return was_error;
 }
 
 /** go ahead and read config, contact server and perform command and display */
-static void
+static int
 go(char* cfgfile, char* svr, int argc, char* argv[])
 {
        struct config_file* cfg;
-       int fd;
+       int fd, ret;
        SSL_CTX* ctx;
        SSL* ssl;
 
@@ -238,12 +243,13 @@ go(char* cfgfile, char* svr, int argc, char* argv[])
        ssl = setup_ssl(ctx, fd);
        
        /* send command */
-       go_cmd(ssl, argc, argv);
+       ret = go_cmd(ssl, argc, argv);
 
        SSL_free(ssl);
        close(fd);
        SSL_CTX_free(ctx);
        config_delete(cfg);
+       return ret;
 }
 
 /** getopt global, in case header files fail to declare it. */
@@ -254,7 +260,7 @@ extern char* optarg;
 /** Main routine for unbound-control */
 int main(int argc, char* argv[])
 {
-       int c;
+       int c, ret;
        char* cfgfile = CONFIGFILE;
        char* svr = NULL;
        log_ident_set("unbound-control");
@@ -310,11 +316,11 @@ int main(int argc, char* argv[])
                }
        }
 
-       go(cfgfile, svr, argc, argv);
+       ret = go(cfgfile, svr, argc, argv);
 
 #ifdef USE_WINSOCK
         WSACleanup();
 #endif
        checklock_stop();
-       return 0;
+       return ret;
 }
diff --git a/testdata/09-unbound-control.tpkg b/testdata/09-unbound-control.tpkg
new file mode 100644 (file)
index 0000000..5316f27
Binary files /dev/null and b/testdata/09-unbound-control.tpkg differ