gerolima@Neon.Stanford.EDU (Mark Gerolimatos) (05/30/91)
>>>>>>> Assuming SunOS 4.1.1 <<<<<<<< I have a very silly brain dead program (binary only, SunOS) which for some silly reason assumes a bidirectional device (read: tty) as both its I and its O. No problem with that, but I want to use a swado-tty now, instead of tty{a,b}. First, I manually find an available swado-tty (yes, this is gross, but I have no choice: remember, binaries only!), and then try out: dd if=/etc/whatever of=/dev/ptyXX simultaneously with dd if=/dev/ttyXX of=/dev/tty Works (but only as long as the second process is started first! Weird!). Swapping the pty and tty also works (no matter which is run first!). So, I writes me a simple program to test this out myself (below). Now, I can write to ttyXX, and get the data from ptyXX (by running the program twice), BUT NOT THE OTHER WAY AROUND! Is there something I have to do to make this happen? Funny IOCTL (doubtful)? Run as root (please say no)? Additional note: When I open both the PTY and the TTY read/write, a write to the TTY followed by an immedeate read from it blocks on the read. BUT a write to the PTY followed by an immedeate read from it gets the data just written! Why? As time is of the essence, I'd appreceate mailed responses, as well as posted. Thanks! -Mark gerolima@neon.stanford.edu @wdl1.wdl.loral.com @wdl12.wdl.loral.com 8< 8< 8< cut here >8 >8 >8 /**** The problem described herein deals only with SunOS 4.1.1.... ***** does something totally different on some unremembered version ***** of ULTRIX ****/ /* compile, -o writer , then link the executable to some other name, say ** writer ** Then, note that: ** writer /dev/ttyXX (find a suitable pty[p-z][0-9a-f]) ** reader /dev/ptyXX ** gets the data from writer to reader, while ** writer /dev/ptyXX ** reader /dev/ttyXX ** doesn't (ie reader blocks on the read)! ** What gives?!? */ #include <stdio.h> #include <sys/file.h> die (st) char *st; { perror(st); exit(0); } main (argc,argv) int argc; char **argv; { int fd,result, writer = 0; char buffer[1024]; fd = open(argv[1],O_RDWR); if(fd < 0) die("open"); if(!strcmp(argv[0],"writer")) writer++; if(writer) { while(1) { fprintf(stderr,"-> "); if(gets(buffer) == NULL) { close(fd); exit(0); } result = write(fd,buffer,strlen(buffer)); /* note that placing a read here gets the same ** data that was just written when the output file ** is /dev/ptyXX */ if(result < 0) die("write"); } } else /*reader */ { while(1) { result = read(fd,buffer,80); if(result == 0) exit(0); if(result < 0) die("read"); buffer[result] = '\0'; fprintf(stderr,"%s\n",buffer); } } }