- while (1) {
- int ret;
- printf("vsys>");fflush(stdout);
- FD_SET(0, &set);
- FD_SET(vfd0, &set);
- ret = select(vfd0+1, &set, NULL, NULL, &tv);
- if (FD_ISSET(0,&set)) {
- char lineread[2048];
- int ret;
- ret=read(0,lineread,2048);
- write(vfd1,lineread,ret);
- FD_CLR(0,&set);
- } if (FD_ISSET(vfd0,&set)) {
- char lineread[2048];
- int ret;
- ret=read(vfd0,lineread,2048);
- write(1,lineread,ret);
- FD_CLR(vfd0,&set);
- }
- }
+ if (fcntl(vfd0, F_SETFL, O_RDONLY) == -1) {
+ printf("Error making pipe blocking: %m\n");
+ fatal=1;
+ }
+
+ if (fatal) { exit(1);}
+
+ if (argc<3) {
+ /* interactive mode */
+ fd_set set;
+ char do_input = 1, do_output = 1;
+
+ while (1) {
+ int ret;
+ printf("vsys>");fflush(stdout);
+ FD_ZERO(&set);
+ if (do_input)
+ FD_SET(0, &set);
+ if (do_output)
+ FD_SET(vfd0, &set);
+ ret = select(vfd0+1, &set, NULL, NULL, NULL);
+ if (FD_ISSET(0,&set)) {
+ char lineread[2048];
+ int ret;
+ ret=read(0,lineread,2048);
+ /*printf ("read=%d\n",ret);*/
+ if (ret == 0)
+ do_input = 0;
+ lineread[ret]='\0';
+ printf ("writing %s\n",lineread);
+ write(vfd1,lineread,ret);
+ }
+ if (FD_ISSET(vfd0,&set)) {
+ char lineread[2048];
+ int ret;
+ ret = read(vfd0,lineread,2048);
+ if (ret == 0)
+ break;
+ write(1,lineread,ret);
+ }
+ }