]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/console.c
Update doc
[bacula/bacula] / bacula / src / console / console.c
index 51f49961d02c90f223b7f2641b887023253fb0d2..d3f0fcd4e054fa00bd5568a754c1b76a87c8cbe7 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 /*
-   Copyright (C) 2000-2003 Kern Sibbald and John Walker
+   Copyright (C) 2000-2004 Kern Sibbald and John Walker
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
 #define clrbrk()
 #define usrbrk() 0  
 #endif
+
+#ifdef HAVE_WIN32
+#include <windows.h>
+#define isatty(fd) (fd==0)
+DWORD  g_platform_id = VER_PLATFORM_WIN32_WINDOWS;
+#endif
  
 /* Exported variables */
 
@@ -51,7 +57,7 @@ extern int rl_catch_signals;
 #endif
 
 /* Imported functions */
-int authenticate_director(JCR *jcr, DIRRES *director);
+int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
 
 
 
@@ -196,10 +202,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 +260,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);
       }
@@ -274,7 +294,7 @@ int main(int argc, char *argv[])
 
    init_stack_dump();
    my_name_is(argc, argv, "bconsole");
-   textdomain("bacula-console");
+   textdomain("bacula");
    init_msg(NULL, NULL);
    working_directory = "/tmp";
    args = get_pool_memory(PM_FNAME);
@@ -318,13 +338,16 @@ int main(int argc, char *argv[])
       init_signals(terminate_console);
    }
 
+#if !defined(HAVE_WIN32)
    /* Override Bacula default signals */
    signal(SIGCHLD, SIG_IGN);
+   signal(SIGQUIT, SIG_IGN);
    signal(SIGTSTP, got_sigstop);
    signal(SIGCONT, got_sigcontinue);
    signal(SIGTTIN, got_sigtin);
    signal(SIGTTOU, got_sigtout);
    trapctlc();
+#endif
 
    if (argc) {
       usage();
@@ -358,8 +381,14 @@ Without that I don't how to speak to the Director :-(\n"), configfile);
    memset(&jcr, 0, sizeof(jcr));
 
 
+#ifdef HAVE_WIN32
+   WSA_Init();                       /* Initialize Windows sockets */
+#endif
+
    if (ndir > 1) {
-      UA_sock = init_bsock(NULL, 0, "", "", 0);
+      struct sockaddr_in client_addr;
+      memset(&client_addr, 0, sizeof(client_addr));
+      UA_sock = init_bsock(NULL, 0, "", "", 0, &client_addr);
 try_again:
       sendit(_("Available Directors:\n"));
       LockRes();
@@ -398,7 +427,12 @@ try_again:
       return 1;
    }
    jcr.dir_bsock = UA_sock;
-   if (!authenticate_director(&jcr, dir)) {
+
+   LockRes();
+   CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, (RES *)NULL);
+   UnlockRes();
+   /* 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;
@@ -489,6 +523,9 @@ wait_for_data(int fd, int sec)
 {
    fd_set fdset;
    struct timeval tv;
+#ifdef HAVE_WIN32
+   return 1;                          /* select doesn't seem to work on Win32 */
+#endif
 
    tv.tv_sec = sec;
    tv.tv_usec = 0;
@@ -548,6 +585,9 @@ again:
       }
       break;
    }
+   if (usrbrk()) {
+      clrbrk();
+   }
    strip_trailing_junk(sock->msg);
    sock->msglen = strlen(sock->msg);
    return 1;
@@ -698,6 +738,8 @@ void sendit(char *buf)
     if (tee) {
        fputs(buf, stdout);
     }
-    fflush(stdout);
+    if (output == stdout || tee) {
+       fflush(stdout);
+    }
 #endif
 }