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);
static BSOCK *UA_sock = NULL;
static DIRRES *dir;
static FILE *output = stdout;
+static int stop = FALSE;
#define CONFIG_FILE "./console.conf" /* default configuration file */
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"
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 = "*";
stat = 1;
}
}
- if (stat < 0) {
+ if (stat < 0) {
break; /* error */
} else if (stat == 0) { /* timeout */
bnet_fsend(UA_sock, ".messages");
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;
}
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();
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();
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);
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 */
return -1; /* error */
default:
len = sizeof_pool_memory(sock->msg) - 1;
+ if (stop) {
+ goto again;
+ }
if (fgets(sock->msg, len, input) == NULL) {
return -1;
}