3 * (c) Jack lange & Lei Xia, 2010
10 #include <sys/ioctl.h>
12 #include <sys/types.h>
18 #include<linux/unistd.h>
25 #define STREAM_NAME_LEN 128
27 int main(int argc, char* argv[]) {
31 char stream[STREAM_NAME_LEN];
32 char cons_buf[BUF_LEN];
36 printf("Usage: ./v3_cons vm_device serial_number\n");
42 if (strlen(argv[2]) >= STREAM_NAME_LEN) {
43 printf("ERROR: Stream name longer than maximum size (%d)\n", STREAM_NAME_LEN);
47 memcpy(stream, argv[2], strlen(argv[2]));
49 vm_fd = open(vm_dev, O_RDONLY);
51 printf("Error opening VM device: %s\n", vm_dev);
55 stream_fd = ioctl(vm_fd, V3_VM_SERIAL_CONNECT, stream);
57 /* Close the file descriptor. */
61 printf("Error opening stream Console\n");
70 memset(cons_buf, 0, BUF_LEN);
74 FD_SET(stream_fd, &rset);
75 FD_SET(STDIN_FILENO, &rset);
77 ret = select(stream_fd + 1, &rset, NULL, NULL, NULL);
81 } else if (ret == -1) {
82 perror("Select returned error\n");
86 if (FD_ISSET(stream_fd, &rset)) {
88 bytes_read = read(stream_fd, cons_buf, BUF_LEN - 1);
90 cons_buf[bytes_read]='\0';
91 printf("%s", cons_buf);
94 } else if (FD_ISSET(STDIN_FILENO, &rset)) {
95 fgets(in_buf, 512, stdin);
97 if (write(stream_fd, in_buf, strlen(in_buf)) != strlen(in_buf)) {
98 fprintf(stderr, "Error sending input bufer\n");
102 printf("v3_cons ERROR: select returned %d\n", ret);