Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


updated module cleanup and added user space tools
[palacios.releases.git] / linux_usr / v3_monitor.c
1 /* 
2  * V3 Monitor utility
3  * (c) Lei Xia, 2010
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <fcntl.h> 
9 #include <sys/ioctl.h> 
10 #include <sys/stat.h> 
11 #include <sys/types.h> 
12 #include <unistd.h>
13 #include <string.h>
14 #include<linux/unistd.h>
15
16 #include "v3_ctrl.h"
17
18 int main(int argc, char* argv[]) {
19     int vm_fd;
20     int cons_fd;
21     fd_set rset;
22     char *vm_dev = NULL;
23     char *stream;
24
25     if (argc <= 3) {
26         printf("Usage: ./v3_cons vm_device stream_name\n");
27         return -1;
28     }
29
30     vm_dev = argv[1];
31     stream = argv[2];
32
33     vm_fd = open(vm_dev, O_RDONLY);
34     if (vm_fd == -1) {
35         printf("Error opening VM device: %s\n", vm_dev);
36         return -1;
37     }
38
39     cons_fd = ioctl(vm_fd, V3_VM_CONSOLE_CONNECT, stream); 
40
41     /* Close the file descriptor.  */ 
42     close(vm_fd); 
43     if (cons_fd < 0) {
44         printf("Error opening stream Console\n");
45         return -1;
46     }
47
48     while (1) {
49         int ret; 
50         char cons_buf[1024];
51         memset(cons_buf, 0, sizeof(cons_buf));
52         int bytes_read = 0;
53
54         FD_ZERO(&rset);
55         FD_SET(cons_fd, &rset);
56         
57         ret = select(cons_fd + 1, &rset, NULL, NULL, NULL);
58         
59         if (ret == 1) {
60             bytes_read = read(cons_fd, cons_buf, 1024);
61             cons_buf[bytes_read]='\0';
62             printf("%s", cons_buf);
63         } else {
64             printf("v3_monitor ERROR: select returned %d\n", ret);
65             return -1;
66         }
67     } 
68
69
70     return 0; 
71 }
72
73