diff --git a/doc/Changelog b/doc/Changelog index 6317da9e0..4b1cb8b1b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ 27 September 2012: Wouter - include: directive in config file accepts wildcards. Patch from Paul Wouters. Suggested use: include: "/etc/unbound.d/conf.d/*" + - unbound-control -q option is quiet, patch from Mariano Absatz. 21 September 2012: Wouter - chdir to / after chroot call (suggested by Camiel Dobbelaar). diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index f458338c1..620fd3211 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -14,7 +14,7 @@ \- Unbound remote server control utility. .SH "SYNOPSIS" .B unbound\-control -.RB [ \-h ] +.RB [ \-hq ] .RB [ \-c .IR cfgfile ] .RB [ \-s @@ -38,6 +38,9 @@ config file @ub_conf_file@ is used. .B \-s \fIserver[@port] IPv4 or IPv6 address of the server to contact. If not given, the address is read from the config file. +.TP +.B \-q +quiet, if the option is given it does not print anything if it works ok. .SH "COMMANDS" There are several commands that the server understands. .TP diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index e438b3d20..cc48866c5 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -68,6 +68,7 @@ usage() printf("Options:\n"); printf(" -c file config file, default is %s\n", CONFIGFILE); printf(" -s ip[@port] server address, if omitted config is used.\n"); + printf(" -q quiet (don't print anything if it works ok).\n"); printf(" -h show this usage help.\n"); printf("Commands:\n"); printf(" start start server; runs unbound(8)\n"); @@ -263,7 +264,7 @@ send_file(SSL* ssl, FILE* in, char* buf, size_t sz) /** send command and display result */ static int -go_cmd(SSL* ssl, int argc, char* argv[]) +go_cmd(SSL* ssl, int quiet, int argc, char* argv[]) { char pre[10]; const char* space=" "; @@ -297,9 +298,12 @@ go_cmd(SSL* ssl, int argc, char* argv[]) ssl_err("could not SSL_read"); } buf[r] = 0; - printf("%s", buf); - if(first_line && strncmp(buf, "error", 5) == 0) + if(first_line && strncmp(buf, "error", 5) == 0) { + printf("%s", buf); was_error = 1; + } else if (!quiet) + printf("%s", buf); + first_line = 0; } return was_error; @@ -307,7 +311,7 @@ go_cmd(SSL* ssl, int argc, char* argv[]) /** go ahead and read config, contact server and perform command and display */ static int -go(const char* cfgfile, char* svr, int argc, char* argv[]) +go(const char* cfgfile, char* svr, int quiet, int argc, char* argv[]) { struct config_file* cfg; int fd, ret; @@ -328,7 +332,7 @@ go(const char* cfgfile, char* svr, int argc, char* argv[]) ssl = setup_ssl(ctx, fd); /* send command */ - ret = go_cmd(ssl, argc, argv); + ret = go_cmd(ssl, quiet, argc, argv); SSL_free(ssl); #ifndef USE_WINSOCK @@ -350,6 +354,7 @@ extern char* optarg; int main(int argc, char* argv[]) { int c, ret; + int quiet = 0; const char* cfgfile = CONFIGFILE; char* svr = NULL; #ifdef USE_WINSOCK @@ -392,7 +397,7 @@ int main(int argc, char* argv[]) } /* parse the options */ - while( (c=getopt(argc, argv, "c:s:h")) != -1) { + while( (c=getopt(argc, argv, "c:s:qh")) != -1) { switch(c) { case 'c': cfgfile = optarg; @@ -400,6 +405,9 @@ int main(int argc, char* argv[]) case 's': svr = optarg; break; + case 'q': + quiet = 1; + break; case '?': case 'h': default: @@ -418,7 +426,7 @@ int main(int argc, char* argv[]) } } - ret = go(cfgfile, svr, argc, argv); + ret = go(cfgfile, svr, quiet, argc, argv); #ifdef USE_WINSOCK WSACleanup();