From fce4a5ad73d3554df74a06f3eae5cf3ce0a7feda Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Wed, 24 Feb 2010 17:32:15 +0100 Subject: [PATCH] Add bconsole -l and tweak behavior of -D --- bacula/src/console/console.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 10b9ebcae9..761c21a561 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -127,6 +127,7 @@ PROG_COPYRIGHT "\nVersion: " VERSION " (" BDATE ") %s %s %s\n\n" "Usage: bconsole [-s] [-c config_file] [-d debug_level]\n" " -D select a Director\n" +" -l list Directors defined\n" " -c set configuration file to file\n" " -d set debug level to \n" " -dt print timestamp in debug output\n" @@ -905,8 +906,9 @@ bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret_cons) if (numdir == 1) { /* No choose */ dir = (DIRRES *)GetNextRes(R_DIRECTOR, NULL); - - } else if (director) { /* Command line choice */ + } + + if (director) { /* Command line choice overwrite the no choose option */ LockRes(); foreach_res(dir, R_DIRECTOR) { if (bstrcmp(dir->hdr.name, director)) { @@ -914,6 +916,10 @@ bool select_director(const char *director, DIRRES **ret_dir, CONRES **ret_cons) } } UnlockRes(); + if (!dir) { /* Can't find Director used as argument */ + senditf(_("Can't find %s in Director list\n"), director); + return 0; + } } if (!dir) { /* prompt for director */ @@ -991,6 +997,7 @@ int main(int argc, char *argv[]) { int ch; char *director=NULL; + bool list_directors=false; bool no_signals = false; bool test_config = false; JCR jcr; @@ -1007,7 +1014,7 @@ int main(int argc, char *argv[]) working_directory = "/tmp"; args = get_pool_memory(PM_FNAME); - while ((ch = getopt(argc, argv, "bc:d:nstu:D:?")) != -1) { + while ((ch = getopt(argc, argv, "D:lbc:d:nstu:?")) != -1) { switch (ch) { case 'D': /* Director */ if (director) { @@ -1016,6 +1023,11 @@ int main(int argc, char *argv[]) director = bstrdup(optarg); break; + case 'l': + list_directors = true; + test_config = true; + break; + case 'c': /* configuration file */ if (configfile != NULL) { free(configfile); @@ -1100,6 +1112,14 @@ int main(int argc, char *argv[]) con_init(stdin); } + if (list_directors) { + LockRes(); + foreach_res(dir, R_DIRECTOR) { + senditf("%s\n", dir->hdr.name); + } + UnlockRes(); + } + if (test_config) { terminate_console(0); exit(0); -- 2.39.5