]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/console.c
make bconsole and bstmp
[bacula/bacula] / bacula / src / console / console.c
index f33bc816170a0d39996c963c3ef7b1327d3dcb3b..686ce2e2a05afc1fc1b03604024c55457013a643 100644 (file)
@@ -72,13 +72,13 @@ static int timecmd(FILE *input, BSOCK *UA_sock);
 static int sleepcmd(FILE *input, BSOCK *UA_sock);
 
 
-#define CONFIG_FILE "./console.conf"   /* default configuration file */
+#define CONFIG_FILE "./bconsole.conf"   /* default configuration file */
 
 static void usage()
 {
    fprintf(stderr, _(
 "\nVersion: " VERSION " (" BDATE ") %s %s %s\n\n"
-"Usage: console [-s] [-c config_file] [-d debug_level] [config_file]\n"
+"Usage: bconsole [-s] [-c config_file] [-d debug_level] [config_file]\n"
 "       -c <file>   set configuration file to file\n"
 "       -dnn        set debug level to nn\n"
 "       -s          no signals\n"
@@ -252,7 +252,7 @@ int main(int argc, char *argv[])
    JCR jcr;
 
    init_stack_dump();
-   my_name_is(argc, argv, "console");
+   my_name_is(argc, argv, "bconsole");
    textdomain("bacula-console");
    init_msg(NULL, NULL);
    working_directory = "/tmp";
@@ -260,31 +260,31 @@ int main(int argc, char *argv[])
 
    while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
       switch (ch) {
-         case 'c':                    /* configuration file */
-           if (configfile != NULL) {
-              free(configfile);
-           }
-           configfile = bstrdup(optarg);
-           break;
+      case 'c':                    /* configuration file */
+        if (configfile != NULL) {
+           free(configfile);
+        }
+        configfile = bstrdup(optarg);
+        break;
 
-         case 'd':
-           debug_level = atoi(optarg);
-           if (debug_level <= 0) {
-              debug_level = 1;
-           }
-           break;
+      case 'd':
+        debug_level = atoi(optarg);
+        if (debug_level <= 0) {
+           debug_level = 1;
+        }
+        break;
 
-         case 's':                    /* turn off signals */
-           no_signals = TRUE;
-           break;
+      case 's':                    /* turn off signals */
+        no_signals = TRUE;
+        break;
 
-         case 't':
-           test_config = TRUE;
-           break;
+      case 't':
+        test_config = TRUE;
+        break;
 
-         case '?':
-        default:
-           usage();
+      case '?':
+      default:
+        usage();
 
       }  
    }
@@ -377,6 +377,20 @@ try_again:
 
    Dmsg0(40, "Opened connection with Director daemon\n");
 
+   sendit(_("Enter a period to cancel a command.\n"));
+
+   char *env = getenv("HOME");
+   if (env) {
+      FILE *fd;
+      pm_strcpy(&UA_sock->msg, env);
+      pm_strcat(&UA_sock->msg, "/.bconsolerc");
+      fd = fopen(UA_sock->msg, "r");
+      if (fd) {
+        read_and_process_input(fd, UA_sock);
+        fclose(fd);
+      }
+   }
+
    read_and_process_input(stdin, UA_sock);
 
    if (UA_sock) {
@@ -423,9 +437,8 @@ get_cmd(FILE *input, char *prompt, BSOCK *sock, int sec)
    if (!line) {
       exit(1);
    }
-   strcpy(sock->msg, line);
-   strip_trailing_junk(sock->msg);
-   sock->msglen = strlen(sock->msg);
+   strip_trailing_junk(line);
+   sock->msglen = pm_strcpy(&sock->msg, line);
    if (sock->msglen) {
       add_history(sock->msg);
    }
@@ -518,17 +531,18 @@ static int inputcmd(FILE *input, BSOCK *UA_sock)
    FILE *fd;
 
    if (argc > 2) {
-      sendit(_("Too many arguments.\n"));
-      return 0;
+      sendit(_("Too many arguments on input command.\n"));
+      return 1;
    }
    if (argc == 1) {
-      sendit(_("First argument must be a filename.\n"));
-      return 0;
+      sendit(_("First argument to input command must be a filename.\n"));
+      return 1;
    }
    fd = fopen(argk[1], "r");
    if (!fd) {
-      sendit(_("Cannot open file. ERR=%s\n"), strerror(errno));
-      return 0; 
+      sendit(_("Cannot open file %s for input. ERR=%s\n"), 
+        argk[1], strerror(errno));
+      return 1; 
    }
    read_and_process_input(fd, UA_sock);
    fclose(fd);
@@ -554,7 +568,7 @@ static int do_outputcmd(FILE *input, BSOCK *UA_sock)
    char *mode = "a+";
 
    if (argc > 3) {
-      sendit(_("Too many arguments.\n"));
+      sendit(_("Too many arguments on output/tee command.\n"));
       return 1;
    }
    if (argc == 1) {
@@ -570,7 +584,8 @@ static int do_outputcmd(FILE *input, BSOCK *UA_sock)
    }
    fd = fopen(argk[1], mode);
    if (!fd) {
-      sendit(_("Cannot open file. ERR=%s\n"), strerror(errno));
+      sendit(_("Cannot open file %s for output. ERR=%s\n"), 
+        argk[1], strerror(errno));
       return 1; 
    }
    output = fd;