]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/console.c
Implement Qmsg() + conio linking
[bacula/bacula] / bacula / src / console / console.c
index 8ea78bbbad7833e7bf3e61b3fb78cfc998395c07..614951411754f432c660b06e794e292173aa19aa 100644 (file)
@@ -51,7 +51,7 @@ extern int rl_catch_signals;
 #endif
 
 /* Imported functions */
-int authenticate_director(JCR *jcr, DIRRES *director, char *name);
+int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
 
 
 
@@ -196,10 +196,19 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock)
       }
       if (tty_input) {
         stat = get_cmd(input, prompt, UA_sock, 30);
-        clrbrk();
+        if (usrbrk() == 1) {
+           clrbrk();
+        }
+        if (usrbrk()) {
+           break;
+        }
       } else {
+        /* Reading input from a file */
         int len = sizeof_pool_memory(UA_sock->msg) - 1;
-        if (fgets(UA_sock->msg, len, input) == NULL || usrbrk()) {
+        if (usrbrk()) {
+           break;
+        }
+        if (fgets(UA_sock->msg, len, input) == NULL) {
            stat = -1;
         } else {
            sendit(UA_sock->msg);  /* echo to terminal */
@@ -245,6 +254,11 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock)
            sendit(UA_sock->msg);
         }
       }
+      if (usrbrk() > 1) {
+        break;
+      } else {
+        clrbrk();
+      }
       if (!stop) {
         fflush(stdout);
       }
@@ -404,13 +418,8 @@ try_again:
    LockRes();
    CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
    UnlockRes();
-   char *con_name;
-   if (cons) {
-      con_name = cons->hdr.name;
-   } else {
-      con_name = "*UserAgent*";
-   }
-   if (!authenticate_director(&jcr, dir, con_name)) {
+   /* If cons==NULL, default console will be used */
+   if (!authenticate_director(&jcr, dir, cons)) {
       fprintf(stderr, "ERR=%s", UA_sock->msg);
       terminate_console(0);
       return 1;
@@ -560,6 +569,9 @@ again:
       }
       break;
    }
+   if (usrbrk()) {
+      clrbrk();
+   }
    strip_trailing_junk(sock->msg);
    sock->msglen = strlen(sock->msg);
    return 1;