]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/console.c
Fix DATE problem and minor compile stuff
[bacula/bacula] / bacula / src / console / console.c
index bbe0e3fd8c134102faac4c83c7110313c5333cec..2fd86cfbb49247db621e4cccb605c73a5632fd5c 100644 (file)
@@ -3,6 +3,8 @@
  *   Bacula Console interface to the Director
  *
  *     Kern Sibbald, September MM
+ *
+ *     Version $Id$
  */
 
 /*
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-#include <termios.h>
 #include "bacula.h"
 #include "console_conf.h"
 #include "jcr.h"
-
+#include <termios.h>
 /* Imported functions */
 int authenticate_director(JCR *jcr, DIRRES *director);
 
@@ -50,6 +52,7 @@ static char *configfile = NULL;
 static BSOCK *UA_sock = NULL;
 static DIRRES *dir; 
 static FILE *output = stdout;
+static int stop = FALSE;
 
 
 #define CONFIG_FILE "./console.conf"   /* default configuration file */
@@ -57,7 +60,7 @@ static FILE *output = stdout;
 static void usage()
 {
    fprintf(stderr,
-"\nVersion: " VERSION " (" DATE ")\n\n"
+"\nVersion: " VERSION " (" BDATE ")\n\n"
 "Usage: console [-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"
@@ -69,6 +72,28 @@ static void usage()
    exit(1);
 }
 
+
+void got_stop(int sig)
+{
+   stop = TRUE;
+}
+
+void got_continue(int sig)
+{
+   stop = FALSE;
+}
+
+void got_tout(int sig) 
+{
+// printf("Got tout\n");
+}
+
+void got_tin(int sig)
+{   
+// printf("Got tin\n");
+}
+
+
 static void read_and_process_input(FILE *input, BSOCK *UA_sock) 
 {
    char *prompt = "*";
@@ -95,7 +120,7 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock)
            stat = 1;
         }
       }
-      if (stat < 0) { 
+      if (stat < 0) {
         break;                       /* error */
       } else if (stat == 0) {        /* timeout */
          bnet_fsend(UA_sock, ".messages");
@@ -105,20 +130,26 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock)
            break;                    /* error */
         }
       }
-      if (strcmp(UA_sock->msg, "quit") == 0 || strcmp(UA_sock->msg, "exit") == 0) {
+      if (strcmp(UA_sock->msg, ".quit") == 0 || strcmp(UA_sock->msg, ".exit") == 0) {
         break;
       }
-      while ((stat = bnet_recv(UA_sock)) > 0) {
+      while ((stat = bnet_recv(UA_sock)) >= 0) {
         if (at_prompt) {
-            fprintf(output, "\n");
+           if (!stop) {
+               fprintf(output, "\n");
+           }
            at_prompt = FALSE;
         }
-         printf("%s", UA_sock->msg);
+        if (!stop) {
+            fprintf(output, "%s", UA_sock->msg);
+        }
       }
-      fflush(output);
-      if (stat < 0) {
-        break;                       /* error */
-      } else if (stat == 0) {
+      if (!stop) {
+        fflush(output);
+      }
+      if (is_bnet_stop(UA_sock)) {
+        break;                       /* error or term */
+      } else if (stat == BNET_SIGNAL) {
         if (UA_sock->msglen == BNET_PROMPT) {
            at_prompt = TRUE;
         }
@@ -180,6 +211,10 @@ int main(int argc, char *argv[])
       init_signals(terminate_console);
    }
    signal(SIGCHLD, SIG_IGN);
+   signal(SIGTSTP, got_stop);
+   signal(SIGCONT, got_continue);
+   signal(SIGTTIN, got_tin);
+   signal(SIGTTOU, got_tout);
 
    if (argc) {
       usage();
@@ -210,7 +245,7 @@ Without that I don't how to speak to the Director :-(\n", configfile);
    memset(&jcr, 0, sizeof(jcr));
 
    if (ndir > 1) {
-      UA_sock = init_bsock(0, "", "", 0);
+      UA_sock = init_bsock(NULL, 0, "", "", 0);
 try_again:
       fprintf(output, "Available Directors:\n");
       LockRes();
@@ -243,7 +278,7 @@ try_again:
       
 
    Dmsg2(-1, "Connecting to Director %s:%d\n", dir->address,dir->DIRport);
-   UA_sock = bnet_connect(&jcr, 5, 15, "Director daemon", dir->address, 
+   UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address, 
                          NULL, dir->DIRport, 0);
    if (UA_sock == NULL) {
       terminate_console(0);
@@ -351,8 +386,11 @@ int
 get_cmd(FILE *input, char *prompt, BSOCK *sock, int sec)
 {
    int len;  
-   fprintf(output, prompt);
-   fflush(output);
+   if (!stop) {
+      fprintf(output, prompt);
+      fflush(output);
+   }
+again:
    switch (wait_for_data(fileno(input), sec)) {
       case 0:
         return 0;                    /* timeout */
@@ -360,6 +398,9 @@ get_cmd(FILE *input, char *prompt, BSOCK *sock, int sec)
         return -1;                   /* error */
       default:
         len = sizeof_pool_memory(sock->msg) - 1;
+        if (stop) {
+           goto again;
+        }
         if (fgets(sock->msg, len, input) == NULL) {
            return -1;
         }