From: Brian J. <bjj...@us...> - 2002-07-24 20:39:30
|
Folks, Here's an improved version of my subprocess-as-serial-port patch. It lets you pipe serial input/output to programs instead of actual ports, as requested in the second-to-last item of the "TODO" file. Here's the URL: ftp://ftp.frontiernet.net/pub/users/brianj1/B2_pty_020724.patch As before, just put a pipe character ("|") at the beginning of the port device file name, and BII will allocate a pseudoterminal, connect the master side to the BII serial infrastructure, and run the rest of the port device file name as a program using "/bin/sh -c", with the slave side of the pty as its standard input, output, and error. I.e. BII will treat the process as a serial port, and the process will think it's talking to a normal terminal. This seems to work rather well on Irix: I can run a Unix shell, complete with command line editing, job control, and curses. I can even run a PPP daemon and get TCP/IP networking via PPP (see Irix/README.networking)! I could also imagine using this facility to pipe data to lpr... I'm sure people will come up with lots of other creative uses. I replaced the awfully ugly GNU screen pty code with a much cleaner version from openssh. I also had to add openssh's strlcpy() implementation, for platforms (like Irix) which don't have it in libc. The configure changes should take care of selecting which one to use. I also moved the pipe open code into a subroutine, and now clean up the subprocess when closing the serial port. (If the process exits before the serial port closes, it will sit around as a zombie until the close happens. This is a bit ugly, but I couldn't easily figure out a way to detect child process termination without using SIGCHLD. And using signals would be way too much per-platform porting work.) One question: I currently call waitpid() from SERDPort::close(). Is waitpid() available on all supported platforms? It's POSIX. Does BSD have it these days, or does it need to use wait3()? I'd appreciate it if people could try it out on different platforms. I *think* I got all the configure stuff copied over from openssh properly.... Suggestions and fixes are most welcome. Thanks, Brian J. Johnson -------------------------------------------------------------------- "Computer, end program." -- Mr. Barclay |