3 * (c) Jack lange & Lei Xia, 2010
10 #include <sys/ioctl.h>
12 #include <sys/types.h>
18 #include<linux/unistd.h>
24 static int cons_fd = -1;
25 static pthread_t input_handler;
27 void *write_handler(void *val){
29 printf("Write handler active\n");
33 if(write(cons_fd, &read, sizeof(char)) < 0){
34 printf("WRITE ERROR");
40 int main(int argc, char* argv[]) {
47 printf("Usage: ./v3_cons vm_device serial_number\n");
54 vm_fd = open(vm_dev, O_RDONLY);
56 printf("Error opening VM device: %s\n", vm_dev);
60 cons_fd = ioctl(vm_fd, V3_VM_SERIAL_CONNECT, stream);
62 /* Close the file descriptor. */
65 printf("Error opening stream Console\n");
70 if(pthread_create(&input_handler,0,write_handler,0)){
71 perror("pthread_create");
79 memset(cons_buf, 0, sizeof(cons_buf));
83 FD_SET(cons_fd, &rset);
85 ret = select(cons_fd + 1, &rset, NULL, NULL, NULL);
88 bytes_read = read(cons_fd, cons_buf, 1024);
89 cons_buf[bytes_read]='\0';
90 printf("%s", cons_buf);
92 printf("v3_cons ERROR: select returned %d\n", ret);