Skip to content

Commit

Permalink
Merge pull request #8 from RinHizakura/master
Browse files Browse the repository at this point in the history
Disable canonical mode on host
  • Loading branch information
jserv authored Feb 14, 2022
2 parents a872c4b + 0a3c225 commit 0b3c455
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <getopt.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>

#include "err.h"
#include "vm.h"
Expand All @@ -17,6 +19,31 @@ static void usage(const char *execpath)
print_option("-i, --initrd initrd", "Initial RAM disk image\n");
}

static struct termios saved_attributes;

static void reset_input_mode(void)
{
tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes);
}

static void set_input_mode(void)
{
struct termios tattr;
/* Make sure stdin is a terminal. */
if (!isatty(STDIN_FILENO)) {
fprintf(stderr, "Not a terminal.\n");
exit(EXIT_FAILURE);
}

/* Save the terminal attributes so we can restore them later. */
tcgetattr(STDIN_FILENO, &saved_attributes);
atexit(reset_input_mode);

tattr = saved_attributes;
tattr.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &tattr);
}

int main(int argc, char *argv[])
{
int option_index = 0;
Expand All @@ -43,6 +70,8 @@ int main(int argc, char *argv[])
}
}

set_input_mode();

vm_t vm;
if (vm_init(&vm) < 0)
return throw_err("Failed to initialize guest vm");
Expand All @@ -58,5 +87,8 @@ int main(int argc, char *argv[])

vm_run(&vm);
vm_exit(&vm);

reset_input_mode();

return 0;
}

0 comments on commit 0b3c455

Please sign in to comment.