]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/console.c
Change dev->open() to return bool
[bacula/bacula] / bacula / src / console / console.c
index 10b9ebcae9d90ed4078a2a781a408ffecd52bbf8..999515fddf0bb09745b761d0181dfaee1aa8519c 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -31,7 +31,6 @@
  *
  *     Kern Sibbald, September MM
  *
- *     Version $Id$
  */
 
 #include "bacula.h"
@@ -127,6 +126,7 @@ PROG_COPYRIGHT
 "\nVersion: " VERSION " (" BDATE ") %s %s %s\n\n"
 "Usage: bconsole [-s] [-c config_file] [-d debug_level]\n"
 "       -D <dir>    select a Director\n"
+"       -l          list Directors defined\n"
 "       -c <file>   set configuration file to file\n"
 "       -d <nn>     set debug level to <nn>\n"
 "       -dt         print timestamp in debug output\n"
@@ -323,7 +323,7 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock)
       if (is_bnet_stop(UA_sock)) {
          break;                       /* error or term */
       } else if (stat == BNET_SIGNAL) {
-         if (UA_sock->msglen == BNET_PROMPT) {
+         if (UA_sock->msglen == BNET_SUB_PROMPT) {
             at_prompt = true;
          }
          Dmsg1(100, "Got poll %s\n", bnet_sig_to_ascii(UA_sock));
@@ -522,7 +522,7 @@ void get_items(const char *what)
 
 typedef enum 
 {
-   ITEM_ARG,       /* item with simple list like .job */
+   ITEM_ARG,       /* item with simple list like .jobs */
    ITEM_HELP       /* use help item=xxx and detect all arguments */
 } cpl_item_t;
 
@@ -597,7 +597,8 @@ static struct cpl_keywords_t cpl_keywords[] = {
    {"pool=",      ".pool"          },
    {"fileset=",   ".fileset"       },
    {"client=",    ".client"        },
-   {"job=",       ".job"           },
+   {"job=",       ".jobs"          },
+   {"restore_job=",".jobs type=R"  },
    {"level=",     ".level"         },
    {"storage=",   ".storage"       },
    {"schedule=",  ".schedule"      },
@@ -609,6 +610,7 @@ static struct cpl_keywords_t cpl_keywords[] = {
    {"mark",       ".ls"            },
    {"m",          ".ls"            },
    {"unmark",     ".lsmark"        },
+   {"catalog=",   ".catalogs"      },
    {"actiononpurge=", ".actiononpurge" }
 };
 #define key_size ((int)(sizeof(cpl_keywords)/sizeof(struct cpl_keywords_t)))
@@ -675,6 +677,11 @@ static int eolcmd(FILE *input, BSOCK *UA_sock)
    return 1;
 }
 
+/*
+ * Return 1 if OK
+ *        0 if no input
+ *       -1 error (must stop)
+ */
 int
 get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
 {
@@ -691,7 +698,7 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
        */
       line = readline((char *)prompt);   /* cast needed for old readlines */
       if (!line) {
-         exit(1);
+         return -1;                      /* error return and exit */
       }
       strip_trailing_junk(line);
       command = line;
@@ -701,7 +708,7 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
      sendit(_("Command logic problem\n"));
      sock->msglen = 0;
      sock->msg[0] = 0;
-     return 0;
+     return 0;                  /* No input */
    }
 
    /*
@@ -732,7 +739,7 @@ get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
       actuallyfree(line);       /* allocated by readline() malloc */
       line = NULL;
    }
-   return 1;
+   return 1;                    /* OK */
 }
 
 #else /* no readline, do it ourselves */
@@ -845,8 +852,9 @@ static int console_update_history(const char *histfile)
    int ret=0;
 
 #ifdef HAVE_READLINE
-/* first, try to truncate the history file, and if it
- * fail, the file is probably not present, and we
+/*
+ * first, try to truncate the history file, and if it
+ * fails, the file is probably not present, and we
  * can use write_history to create it
  */
 
@@ -855,7 +863,6 @@ static int console_update_history(const char *histfile)
    } else {
       ret = write_history(histfile);
    }
-
 #endif
 
    return ret;
@@ -866,7 +873,6 @@ static int console_init_history(const char *histfile)
    int ret=0;
 
 #ifdef HAVE_READLINE
-
    using_history();
    ret = read_history(histfile);
    /* Tell the completer that we want a complete . */
@@ -905,8 +911,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 +921,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 +1002,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 +1019,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 +1028,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 +1117,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);
@@ -1112,7 +1137,7 @@ int main(int argc, char *argv[])
    start_watchdog();                        /* Start socket watchdog */
 
    if(!select_director(director, &dir, &cons)) {
-      return 0;
+      return 1;
    }
 
    senditf(_("Connecting to Director %s:%d\n"), dir->address,dir->DIRport);
@@ -1317,6 +1342,7 @@ static int check_resources()
    return OK;
 }
 
+/* @version */
 static int versioncmd(FILE *input, BSOCK *UA_sock)
 {
    senditf("Version: " VERSION " (" BDATE ") %s %s %s\n",
@@ -1324,6 +1350,7 @@ static int versioncmd(FILE *input, BSOCK *UA_sock)
    return 1;
 }
 
+/* @input <input-filename> */
 static int inputcmd(FILE *input, BSOCK *UA_sock)
 {
    FILE *fd;
@@ -1348,13 +1375,15 @@ static int inputcmd(FILE *input, BSOCK *UA_sock)
    return 1;
 }
 
-/* Send output to both termina and specified file */
+/* @tee <output-filename> */
+/* Send output to both terminal and specified file */
 static int teecmd(FILE *input, BSOCK *UA_sock)
 {
    teeout = true;
    return do_outputcmd(input, UA_sock);
 }
 
+/* @output <output-filename> */
 /* Send output to specified "file" */
 static int outputcmd(FILE *input, BSOCK *UA_sock)
 {
@@ -1395,7 +1424,7 @@ static int do_outputcmd(FILE *input, BSOCK *UA_sock)
 }
 
 /*
- * exec "some-command" [wait-seconds]
+ * @exec "some-command" [wait-seconds]
 */
 static int execcmd(FILE *input, BSOCK *UA_sock)
 {
@@ -1432,6 +1461,7 @@ static int execcmd(FILE *input, BSOCK *UA_sock)
 }
 
 
+/* @echo xxx yyy */
 static int echocmd(FILE *input, BSOCK *UA_sock)
 {
    for (int i=1; i < argc; i++) {
@@ -1441,11 +1471,13 @@ static int echocmd(FILE *input, BSOCK *UA_sock)
    return 1;
 }
 
+/* @quit */
 static int quitcmd(FILE *input, BSOCK *UA_sock)
 {
    return 0;
 }
 
+/* @help */
 static int helpcmd(FILE *input, BSOCK *UA_sock)
 {
    int i;
@@ -1456,6 +1488,7 @@ static int helpcmd(FILE *input, BSOCK *UA_sock)
 }
 
 
+/* @sleep secs */
 static int sleepcmd(FILE *input, BSOCK *UA_sock)
 {
    if (argc > 1) {
@@ -1464,7 +1497,7 @@ static int sleepcmd(FILE *input, BSOCK *UA_sock)
    return 1;
 }
 
-
+/* @time */
 static int timecmd(FILE *input, BSOCK *UA_sock)
 {
    char sdt[50];