X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_usr%2Fv3_cons_sc.c;h=6d7e5229572d5dbcaf074c888ff0003af7057c37;hb=82d082daad3fe8afad4be97d97093a3dfb768e1f;hp=0986a9282167b6f8458d87c96c573d8087136926;hpb=7d2c818e3766b91ab6726f4c31e049a561cf3b9f;p=palacios.git diff --git a/linux_usr/v3_cons_sc.c b/linux_usr/v3_cons_sc.c index 0986a92..6d7e522 100644 --- a/linux_usr/v3_cons_sc.c +++ b/linux_usr/v3_cons_sc.c @@ -371,7 +371,32 @@ int send_char_to_palacios_as_scancodes(int fd, unsigned char c) } return 0; } - + + +#define MIN_TTY_COLS 80 +#define MIN_TTY_ROWS 25 +int check_terminal_size (void) +{ + unsigned short n_cols = 0; + unsigned short n_rows = 0; + struct winsize winsz; + + ioctl (fileno(stdin), TIOCGWINSZ, &winsz); + n_cols = winsz.ws_col; + n_rows = winsz.ws_row; + + if (n_cols < MIN_TTY_COLS || n_rows < MIN_TTY_ROWS) { + printf ("Your window is not large enough.\n"); + printf ("It must be at least %dx%d, but yours is %dx%d\n", + MIN_TTY_COLS, MIN_TTY_ROWS, n_cols, n_rows); + return (-1); + } + + /* SUCCESS */ + return (0); +} + + int main(int argc, char* argv[]) { int vm_fd; int cons_fd; @@ -381,10 +406,16 @@ int main(int argc, char* argv[]) { use_curses = 1; if (argc < 2) { - printf("Usage: ./v3_cons_sc \n"); + printf("usage: v3_cons_sc \n"); return -1; } + /* Check for minimum Terminal size at start */ + if (0 != check_terminal_size()) { + printf ("Error: terminal too small!\n"); + return -1; + } + vm_dev = argv[1]; vm_fd = open(vm_dev, O_RDONLY); @@ -450,13 +481,6 @@ int main(int argc, char* argv[]) { //ioctl(STDIN_FILENO, KDSKBMODE, K_RAW); - if (LINES<25 || COLS<80) { - printf("Your window is not large enough.\nIt must be at least 80x25, but yours is %dx%d\n",COLS,LINES); - close(cons_fd); - exit(-1); - } - - while (1) { int ret; int bytes_read = 0;