From : Mobydick To : Mobydick Date : Wed Dec 31 19:00:00 1969 Subject: Note 'Re: vi'------------------------------------------------------------------------------ Title: Re: vi From: Marauder Date: Fri Jul 30 I added "vi" to this driver about a year ago -- while I was working on Underdark. Unfortunately, I no longer have the diffs, I passed them on to Falchan@Underdark after I quit mega-mudding. I also posted a message to r.g.m.lp about how to do it -- I did not save that either. Alexus' is right, you have to put the telnet connection into char mode -- easy enough, check out the telnet sources. Interestingly enough, most connections to muds are in character mode because line mode has become obsolete on most telnet programs. After massaging the connection, you need to ioctl() it back into blocking I/O mode, as "vi" will expect this interaction -- just look at fcntl() or ioctl() for how to do this. Then set a bit in the socket select() masks to indicate that this connection must be ignored until "vi" returns. Next comes the tricky part, fork() of the vi process (ok, easy enough), but then you need to massage the file descriptor table to make vi think the socket is standard input and standard output, see dup() and dup2() for details on this hackery... Ok, now the really hard part ;-), you need to make a "reaper" that will asynchronously wait for the "vi" child process. This can be done with a signal handler that catches SIGCHILD, and then does a wait3(). There is an example of a "reaper" in the ftpd sources. Lastly, you need to handle all error condition on the child process and the socket, otherwise you will get defunct processes galore. Security is a pain. You'll need to hack out the subprocess option in "vi" and you'll also need to check read and write permission on the file name passed to "vi". In my implementation, I made a general sub-processes efun, that used callbacks in master.c to check validy of the subprocess and possibly check and change any arguments. It was not a major drain on the system, and it did not significantly slow down the net or the mud that I noticed. "vi" is by no means a high bandwidth program -- now check out an "xtrek" server with 15 active clients -- that's a bandwidth user! Regards, Marauder p.s. I never really even used the darn thing, I think ange-ftp in emacs is a much better (holistic) solution -- I did it mostly because many said it could not be done, I'd do it again right if I had the time... :(