uipc.p5

Bradley Smith bes at holin.ATT.COM
Sun Aug 13 02:39:51 AEST 1989


: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
echo 'Extracting src/Makefile'
sed 's/^X//' > src/Makefile << '+ END-OF-FILE src/Makefile'
X# Merged Makefile from pty drive below
X#
X#       Eric H. Herrin II
X#	University of Kentucky Mathematical Sciences Laboratories
X# 	915 Patterson Office Tower
X#	University of Kentucky
X#	Lexington, KY 40506
X#	eric at ms.uky.edu, ..!cbosgd!ukma!eric 
X#
X#
X# and Makefile from socket stuff 
X#
X#	@(#)Makefile	1.1	(Alex Crain) 6/20/89
X#
X# Makefile for UnixPc uipc driver.
X# Written By Alex Crain
X#
X
X#
X# All this done by Bradley Smith
X#
XSHELL=/bin/sh
XMV=/bin/mv
XRM=/bin/rm
X
X# on my gcc I need to add -v flag to CFLAGS or else
X# gcc will die on me periodically - bes
X#
X# CC=gcc
X# CC=cc
XIFLAGS=-I../
XOFLAG=-O
X# define DEBUG for debuggin messages
XDEFS=   -UDEBUG -DSYSV -DUNIXPC
XCFLAGS=$(OFLAG) $(IFLAGS) -DKERNEL=1 $(DEFS) $(VFLAG)
XLD=/bin/ld
X#LIBS=-lgcc
XLIBS=/usr/local/lib/gcc-gnulib
XLINT=lint
X
XSOURCES=mbuf.c domain.c socket1.c socket2.c syscalls.c proto.c usrreq.c \
X	interface.c debug.c sysent.m4 pty.c linesw.c
X
XOBJS=mbuf.o domain.o socket1.o socket2.o syscalls.o proto.o usrreq.o \
X	interface.o debug.o pty.o linesw.o
X
Xall: ../pty.o
X
X
Xremove:
X	(cd ..;${SHELL} Remove)
X
X../support/socket_init:
X	(cd ../support;make)
X
X
X$(SOURCES):
X	$(GET) $(GFLAGS) -p ../sccs/src/s.$@ > $@
X
X.c.o:
X	$(CC) $(CFLAGS) -c $*.c
X
Xsysent.h: ../sysconfig.m4 sysent.m4
X	m4 sysent.m4 > sysent.h
X
X../pty.o: $(OBJS)
X	ld -r -n -o ../pty.o $(OBJS) $(LIBS) 
X
Xdepend: sysent.h
X	cat Makefile | sed -e "/^### DEPEND LINE/q" > Make.tmp
X	$(CC) $(IFLAGS) -M $(SOURCES) >> Make.tmp
X	$(MV) Make.tmp Makefile
X
Xclean:
X	$(RM) -f *.o ../pty.o core sysent.h
X
Xlint:
X	$(LINT) $(IFLAGS) $(SOURCES) > lint.out
X
X### DEPEND LINE --- do not delete!
Xmbuf.o : mbuf.c /usr/include/sys/types.h /usr/include/sys/param.h \
X  /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h ..//uipc/socketvar.h ..//uipc/conf.h \
X  ..//uipc/protosw.h ..//uipc/conf.h ..//uipc/domain.h \
X  ..//uipc/conf.h ..//uipc/mbuf.h ..//uipc/conf.h ..//uipc/fproto.h 
Xdomain.o : domain.c /usr/include/sys/types.h /usr/include/sys/param.h \
X  /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h ..//uipc/socketvar.h ..//uipc/conf.h \
X  ..//uipc/socket.h ..//uipc/conf.h ..//uipc/protosw.h \
X  ..//uipc/conf.h ..//uipc/domain.h ..//uipc/conf.h ..//uipc/mbuf.h \
X  ..//uipc/conf.h ..//uipc/fproto.h 
Xsocket1.o : socket1.c /usr/include/sys/types.h /usr/include/sys/param.h \
X  /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h /usr/include/sys/user.h /usr/include/sys/types.h \
X  /usr/include/sys/param.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/file.h /usr/include/sys/dmap.h /usr/include/sys/types.h \
X  /usr/include/sys/signal.h /usr/include/sys/vlimit.h \
X  /usr/include/sys/dir.h /usr/include/sys/types.h /usr/include/sys/proc.h \
X  /usr/include/sys/file.h /usr/include/sys/var.h /usr/include/sys/errno.h \
X  ..//uipc/mbuf.h ..//uipc/conf.h ..//uipc/socket.h ..//uipc/conf.h \
X  ..//uipc/socketvar.h ..//uipc/conf.h ..//uipc/domain.h \
X  ..//uipc/conf.h ..//uipc/protosw.h ..//uipc/conf.h \
X  ..//uipc/fproto.h 
Xsocket2.o : socket2.c /usr/include/sys/types.h /usr/include/sys/param.h \
X  /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h /usr/include/sys/errno.h /usr/include/sys/proc.h \
X  /usr/include/sys/var.h ..//uipc/mbuf.h ..//uipc/conf.h \
X  ..//uipc/socket.h ..//uipc/conf.h ..//uipc/socketvar.h \
X  ..//uipc/conf.h ..//uipc/protosw.h ..//uipc/conf.h \
X  ..//uipc/domain.h ..//uipc/conf.h ..//uipc/fproto.h 
Xsyscalls.o : syscalls.c /usr/include/sys/types.h /usr/include/sys/param.h \
X  /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h /usr/include/sys/user.h /usr/include/sys/types.h \
X  /usr/include/sys/param.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/file.h /usr/include/sys/dmap.h /usr/include/sys/types.h \
X  /usr/include/sys/signal.h /usr/include/sys/vlimit.h \
X  /usr/include/sys/dir.h /usr/include/sys/types.h /usr/include/sys/file.h \
X  /usr/include/sys/buf.h /usr/include/sys/errno.h /usr/include/sys/systm.h \
X  ..//uipc/mbuf.h ..//uipc/conf.h ..//uipc/socket.h ..//uipc/conf.h \
X  ..//uipc/socketvar.h ..//uipc/conf.h ..//uipc/domain.h \
X  ..//uipc/conf.h ..//uipc/protosw.h ..//uipc/conf.h \
X  ..//uipc/un.h ..//uipc/conf.h ..//uipc/fproto.h ..//uipc/pty.h \
X  ..//uipc/number-ptys.h 
Xproto.o : proto.c /usr/include/sys/types.h /usr/include/sys/param.h \
X  /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h ..//uipc/mbuf.h ..//uipc/conf.h \
X  ..//uipc/socket.h ..//uipc/conf.h ..//uipc/socketvar.h \
X  ..//uipc/conf.h ..//uipc/protosw.h ..//uipc/conf.h \
X  ..//uipc/domain.h ..//uipc/conf.h ..//uipc/fproto.h 
Xusrreq.o : usrreq.c /usr/include/sys/types.h ..//uipc/conf.h \
X  /usr/include/sys/param.h /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h /usr/include/sys/user.h /usr/include/sys/types.h \
X  /usr/include/sys/param.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/file.h /usr/include/sys/dmap.h /usr/include/sys/types.h \
X  /usr/include/sys/signal.h /usr/include/sys/vlimit.h \
X  /usr/include/sys/dir.h /usr/include/sys/types.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/stat.h /usr/include/sys/types.h \
X  /usr/include/sys/var.h /usr/include/sys/tune.h /usr/include/sys/types.h \
X  /usr/include/sys/errno.h ..//uipc/mbuf.h ..//uipc/conf.h \
X  ..//uipc/socket.h ..//uipc/conf.h ..//uipc/socketvar.h \
X  ..//uipc/conf.h ..//uipc/protosw.h ..//uipc/conf.h \
X  ..//uipc/domain.h ..//uipc/conf.h ..//uipc/unpcb.h \
X  ..//uipc/conf.h ..//uipc/un.h ..//uipc/conf.h ..//uipc/fproto.h 
Xinterface.o : interface.c /usr/include/sys/types.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/types.h \
X  /usr/include/sys/sysmacros.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h /usr/include/sys/errno.h /usr/include/sys/user.h \
X  /usr/include/sys/types.h /usr/include/sys/param.h /usr/include/sys/proc.h \
X  /usr/include/sys/inode.h /usr/include/sys/file.h /usr/include/sys/dmap.h \
X  /usr/include/sys/types.h /usr/include/sys/signal.h \
X  /usr/include/sys/vlimit.h /usr/include/sys/dir.h /usr/include/sys/types.h \
X  ..//uipc/socketvar.h ..//uipc/conf.h ..//uipc/mbuf.h \
X  ..//uipc/conf.h ..//uipc/protosw.h ..//uipc/conf.h \
X  ..//uipc/domain.h ..//uipc/conf.h ..//uipc/fproto.h \
X  sysent.h 
Xdebug.o : debug.c /usr/include/sys/types.h /usr/include/sys/param.h \
X  /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h /usr/include/sys/errno.h /usr/include/sys/proc.h \
X  ..//uipc/mbuf.h ..//uipc/conf.h ..//uipc/socket.h ..//uipc/conf.h \
X  ..//uipc/socketvar.h ..//uipc/conf.h ..//uipc/protosw.h \
X  ..//uipc/conf.h ..//uipc/domain.h ..//uipc/conf.h 
Xpty.o : pty.c ..//uipc/pty.h ..//uipc/number-ptys.h \
X  /usr/include/sys/param.h /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
X  /usr/include/sys/systm.h /usr/include/sys/param.h /usr/include/sys/inode.h \
X  /usr/include/sys/proc.h /usr/include/sys/types.h /usr/include/sys/text.h \
X  /usr/include/sys/types.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/param.h /usr/include/sys/shm.h /usr/include/sys/ipc.h \
X  /usr/include/sys/types.h /usr/include/sys/pte.h /usr/include/sys/param.h \
X  /usr/include/sys/pte.h /usr/include/sys/buf.h /usr/include/sys/param.h \
X  /usr/include/sys/inode.h /usr/include/sys/proc.h /usr/include/sys/filsys.h \
X  /usr/include/sys/param.h /usr/include/sys/ino.h /usr/include/sys/file.h \
X  /usr/include/sys/types.h /usr/include/sys/inode.h /usr/include/sys/filsys.h \
X  /usr/include/sys/cmap.h /usr/include/sys/file.h /usr/include/sys/conf.h \
X  /usr/include/sys/types.h /usr/include/sys/iobuf.h /usr/include/sys/param.h \
X  /usr/include/sys/buf.h /usr/include/sys/proc.h /usr/include/sys/dir.h \
X  /usr/include/sys/types.h /usr/include/sys/tty.h /usr/include/sys/types.h \
X  /usr/include/sys/signal.h /usr/include/sys/user.h /usr/include/sys/types.h \
X  /usr/include/sys/param.h /usr/include/sys/proc.h /usr/include/sys/inode.h \
X  /usr/include/sys/file.h /usr/include/sys/dmap.h /usr/include/sys/types.h \
X  /usr/include/sys/signal.h /usr/include/sys/vlimit.h \
X  /usr/include/sys/dir.h /usr/include/sys/errno.h /usr/include/sys/termio.h \
X  /usr/include/sys/ttold.h 
+ END-OF-FILE src/Makefile
chmod 'u=rw,g=r,o=r' 'src/Makefile'
echo '	-rw-r--r--   1 bes      HSJ        14549 Aug 12 12:26 src/Makefile        (as sent)'
echo '	\c'
/bin/ls -l src/Makefile
echo 'Extracting src/debug.c'
sed 's/^X//' > src/debug.c << '+ END-OF-FILE src/debug.c'
X
X#ifndef LINT
Xstatic char * sccsdef = "@(#)debug.c	1.1	(Alex Crain)	6/20/89";
X#endif
X
X#include <sys/types.h>
X#include <sys/param.h>
X#include <sys/systm.h>
X#include <sys/errno.h>
X#include <sys/proc.h>
X#include <uipc/mbuf.h>
X#include <uipc/socket.h>
X#include <uipc/socketvar.h>
X#include <uipc/protosw.h>
X#include <uipc/domain.h>
X
X#define PRINTF eprintf	/* */
X/* #define PRINTF printf	/* */
X
Xvoid
Xdump_mbuf (m, func)
X  struct mbuf * m;
X  char *func;
X{
X#ifdef OLDWAY
X   (void) PRINTF ("MBUF DUMP [%x]\n", m); 
X   (void) PRINTF ("[m_next : %x] [m_off : %x] [m_len : %x] [m_type : %x]\n",
X	  m->m_next, m->m_off, m->m_len, m->m_type);
X   if (m->m_type == MT_SOCKET)
X    {
X       struct socket * so = mtod (m, struct socket *);
X       (void) PRINTF ("[so_type %x] [so_state %x]\n", so->so_type, so->so_state);
X    }
X   (void) PRINTF ("MBUF DUMP [done]\n");
X#else
X   if (m->m_type == MT_SOCKET)
X    {
X       struct socket * so = mtod (m, struct socket *);
X   PRINTF ("FUNCTION %s: MBUF DUMP [%x]\n[m_next : %x] [m_off : %x] \
X[m_len : %x] [m_type : %x]\n[so_type %x] [so_state %x]\n",
X	 func, m, m->m_next, m->m_off, m->m_len, m->m_type,
X	so->so_type, so->so_state);
X    } else {
X   PRINTF ("FUNCTION %s: MBUF DUMP [%x]\n[m_next : %x] [m_off : %x] \
X[m_len : %x] [m_type : %x]\n",
X	 func, m, m->m_next, m->m_off, m->m_len, m->m_type);
X    }
X#endif
X}
X
+ END-OF-FILE src/debug.c
chmod 'u=rw,g=rw,o=rw' 'src/debug.c'
echo '	-rw-rw-rw-   1 bes      HSJ         1343 Aug 12 12:26 src/debug.c        (as sent)'
echo '	\c'
/bin/ls -l src/debug.c
echo 'Extracting src/domain.c'
sed 's/^X//' > src/domain.c << '+ END-OF-FILE src/domain.c'
X#ifndef LINT
Xstatic char * sccsdef = "@(#)domain.c	1.1	(Alex Crain) 6/20/89";
X#endif
X
X/*
X *  domain.c - routines for handling domains
X *
X *  Written by Alex Crain.
X *
X *  This file is loosly based in the Berkeley file uipc_domain.c,
X *  but is *not* guarenteed to be in any way compatable. It is
X *  close enough to the Berkeley code that the following applies...
X *
X *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
X *  All rights reserved.
X * 
X *  Redistribution and use in source and binary forms are permitted
X *  provided that this notice is preserved and that due credit is given
X *  to the University of California at Berkeley. The name of the University
X *  may not be used to endorse or promote products derived from this
X *  software without specific prior written permission. This software
X *  is provided "as is" without express or implied warranty.
X *
X */
X
X#include <sys/types.h>
X#include <sys/param.h>
X#include <sys/systm.h>
X#include <uipc/socketvar.h>
X#include <uipc/socket.h>
X#include <uipc/protosw.h>
X#include <uipc/domain.h>
X#include <uipc/mbuf.h>
X#include <uipc/fproto.h>
X
X#ifndef __STDC__
X#define ADDDOMAIN(x) \
X {  extern struct domain x/**/domain;	\
X    x/**/domain.dom_next = domains;	\
X    domains = &x/**/domain; }
X#else
X#define ADDDOMAIN(x) \
X {  extern struct domain x ## domain;	\
X    x ## domain.dom_next = domains;	\
X    domains = &x ## domain; }
X#endif
X
Xvoid
Xdomaininit ()
X{
X   register struct domain * dp;
X   register struct protosw * pr;
X
X   ADDDOMAIN (unix);
X
X#ifdef INET
X   ADDDOMAIN (inet);
X#endif
X   
X   for (dp = domains; dp; dp = dp->dom_next)
X    {
X       if (dp->dom_init)
X	   (* dp->dom_init) ();
X       for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
X	   if (pr->pr_init)
X	       (* pr->pr_init) ();
X    }
X}
X	    
Xstruct protosw *
Xpffindtype (family, type)
X  int family, type;
X{
X   register struct domain * dp;
X   register struct protosw * pr;
X   
X   for (dp = domains; dp; dp = dp->dom_next)
X       if (dp->dom_family == family)
X	   goto found;
X   return 0;
X found:
X   for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
X       if (pr->pr_type && pr->pr_type == type)
X	   return pr;
X   return 0;
X}
X
Xstruct protosw *
Xpffindproto (family, protocol, type)
X  int family, protocol, type;
X{
X   register struct domain * dp;
X   register struct protosw * pr;
X   struct protosw * maybe = 0;
X
X   for (dp = domains; dp; dp = dp->dom_next)
X       if (dp->dom_family == family)
X	   goto found;
X   return 0;
X found:
X   for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
X    {
X       if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
X	   return pr;
X
X#ifdef SOCK_RAW
X       if ((type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
X	    pr->pr_protocol == 0 && maybe = (struct protosw *) 0))
X	   maybe = pr;
X#endif
X    }
X   return maybe;
X}
+ END-OF-FILE src/domain.c
chmod 'u=rw,g=rw,o=rw' 'src/domain.c'
echo '	-rw-rw-rw-   1 bes      HSJ         2835 Aug 12 12:26 src/domain.c        (as sent)'
echo '	\c'
/bin/ls -l src/domain.c
echo 'Extracting src/interface.c'
sed 's/^X//' > src/interface.c << '+ END-OF-FILE src/interface.c'
X#ifndef LINT
Xstatic char * sccsdef = "@(#)interface.c	1.1	(Alex Crain) 6/20/89";
X#endif
X
X/*
X *  interface.c - loadable driver interface.
X *
X *  Written By Alex Crain.
X *
X *  This file contains the driver interface routines for the uipc driver, as
X *    discribed in drivers(7). These interface routines are:
X *	uipcinit ();
X *
X */
X
X#include <sys/types.h>
X#include <sys/systm.h>
X#include <sys/errno.h>
X#include <sys/user.h>
X#include <sys/conf.h>
X#include <uipc/socketvar.h>
X#include <uipc/mbuf.h>
X#include <uipc/protosw.h>
X#include <uipc/domain.h>
X#include <uipc/fproto.h>
X#include <uipc/pty.h>
X
X#include "sysent.h"
X
Xextern void (* sock_read)();
Xextern void (* sock_write)();
Xextern void (* sock_close)();
X
X
Xvoid
Xptyinit ()
X{
X   int i;
X
X   /*
X    * add our own system call processor.
X    */
X
X   sysent[SYSL_LOCSYS].sy_call = (int (*)()) dosyscall;
X   sysent[SYSL_LOCSYS].sy_narg = 3;
X
X   /*
X    *  link to the existing hooks in the kernal.
X    */
X
X   sock_read = uipc_read;
X   sock_write = uipc_write;
X   sock_close = uipc_close;
X
X   /*
X    *  Initialize the system.
X    */
X
X   mbinit ();
X   domaininit ();
X
X   /*
X    * find out where the pty major device is
X    */
X   for(i=0;i<cdevcnt;i++) {
X	if(cdevsw[i].d_open == ptyopen)
X		pty_major = i; /* got it */
X   }
X   so_linesw_setup();
X}
X
Xvoid
Xdosyscall()
X{
X   int index = u.u_ap[0] - SYSL_FIRST;
X   /*
X    * Intercept our calls
X    */
X
X   if (index >= 0 && index <= (SYSL_LAST - SYSL_FIRST))
X    {
X       /*
X	*  syscall arguments are available via the users %sp, at u.u_ar0[15].
X	*  These arguments must be copied to the argument vector u.u_arg[]
X	*  for access by the kernal. Noting that the stack looks like:
X	*	%sp -> [ frame link, &67, arg1, arg2 ... ]
X	*/
X       int arg = 0;
X       int * ap = (int *) (u.u_ar0[15]) + 2;
X       while (arg < sysentries[index].sy_narg)
X	   u.u_arg[arg++] = fuword(ap++);
X
X       /*
X	*  Perform the call.
X	*/
X       (* sysentries[index].sy_call) ();
X    }
X   else
X       locsys ();
X}
X
Xint
Xuipcrelease ()
X{
X   int mbmem_ref;
X   int s = spl5();
X   struct mbuf * m;
X   
X   for (m = mbmem; m < &mbmem[NMBUF+1]; m++)
X       if (m->m_type == MT_SOCKET)
X	   if (soclose (mtod (m, struct socket *)))
X	        return EBUSY;
X   for (mbmem_ref =0, m = mbmem; m < &mbmem[NMBUF+1]; m++, mbmem_ref++)
X       if (m->m_type != MT_FREE)
X	{
X	   int * i;
X	   (void) printf ("\n\n\nUIPC: Illegal mbuf type %d.\n", m->m_type);
X	   (void) printf ("m = ([*|%x] [m_next|%x] [m_len|%x] [m_type|%x])\n",
X			  m, m->m_next, m->m_len, m->m_type);
X	   (void) printf ("mbmem_ref=%d, NMBUF=%d\n", mbmem_ref, NMBUF);
X	   for (i = mtod (m, int *); 
X		i < ((int *) ((caddr_t) m + MSIZE - MTAIL));
X		i+=4)
X	       (void) printf ("%x %x %x %x\n", *i, *(i+1), *(i+2), *(i+3));
X	   panic ("uipc_release");
X	}
X
X   splx (s);
X   so_linesw_release();
X   return 0;
X}
X
X/*
X *  rdwr() uses this for reading sockets. 
X *
X *  There are no arguments, pertinant info is available as:
X *	u.u_ap[0] -	The file descriptor number
X *	u.u_base - 	IO buffer address
X *	u.u_count -	size of buffer.
X *	u.u_segflg -	IO buffer location
X *
X *  Errors do not return, rather an error condition is handled with a longjmp
X *  to u.u_qsav, with some non-zero argument. the call will return -1 to the 
X *  user, passing the error in errno (u.u_error). Since the jump returns
X *  directly to trap(), we need to do any houskeeping here.
X */
X
Xvoid
Xuipc_write ()
X{
X   struct file * fp = getf (u.u_ap[0]);
X
X   u.u_error = sosend (filesock (fp), (struct mbuf *) 0, 0, (struct mbuf *) 0);
X   
X   /*
X    *  process errors
X    */
X
X   if (u.u_error)
X       longjmp (u.u_qsav, 1);
X}
X
Xvoid
Xuipc_read ()
X{
X   struct file * fp = getf (u.u_ap[0]);
X
X   u.u_error = 
X       soreceive (filesock (fp), (struct mbuf **) 0, 0, (struct mbuf **) 0);
X			  
X			  
X   
X   /*
X    *  process errors
X    */
X
X   if (u.u_error)
X       longjmp (u.u_qsav, 1);
X}
X
Xvoid
Xuipc_close (sp)
X  off_t sp;
X{
X   u.u_error = soclose (mtod (ptom (sp), struct socket *));
X
X   /*
X    *  process errors
X    */
X
X   if (u.u_error)
X       longjmp (u.u_qsav, 1);
X}
X
X
X/*
X *  General utilities for the BSD<->sysV mix.
X */
X
X#ifdef unixpc
X
Xasm("	global bzero	");
Xasm("bzero:		");
Xasm("	mov.l	4(%sp),%a0");
Xasm("	mov.w	10(%sp),%d0");
Xasm("	sub.w	&1,%d0	");
Xasm("	bmi	end	");
Xasm("loop:		");
Xasm("	mov.b	&0,(%a0)+");
Xasm("	dbf	%d0,loop");
Xasm("end:		");
Xasm("	rts		");
X
X#else
X
Xvoid
Xbzero (s, n)
X  char * s; 
X  int n;
X{
X   while (n--)
X       *s++ = '\0';
X}
X
X#endif
X
Xint
Xufavail ()
X{
X   int avail = 0, fd = 0;
X
X   for (fd = 0; fd < 80; fd++)
X       if (u.u_ofile[fd] == 0)
X	   avail++;
X
X   return avail;
X}
+ END-OF-FILE src/interface.c
chmod 'u=rw,g=rw,o=rw' 'src/interface.c'
echo '	-rw-rw-rw-   1 bes      HSJ         4561 Aug 12 12:26 src/interface.c        (as sent)'
echo '	\c'
/bin/ls -l src/interface.c
echo 'Extracting src/linesw.c'
sed 's/^X//' > src/linesw.c << '+ END-OF-FILE src/linesw.c'
X#include	<sys/types.h>
X#include	<sys/sysmacros.h>
X#include	<sys/conf.h>
X#include	<sys/tty.h>
X
Xint (*real_linesw_read)(), (*real_linesw_write)();
Xint (*real_linesw_l_input)();
Xint so_linesw_read(), so_linesw_write();
Xint so_linesw_l_input();
X
X/* stuff to wake up on */
Xextern int select_sleep, select_sleep_addr;
X
X/* unsigned addr_win_tty = 384636; /* */
X
Xso_linesw_read(tp)
Xstruct tty *tp;
X{
X	extern int (*real_linesw_read) ();
X
X	/* next check us for wakeup maybe? */
X	if(select_sleep) {
X		select_sleep = 0;
X		wakeup((caddr_t) &select_sleep_addr);
X	}
X	(*real_linesw_read)(tp);
X}
Xso_linesw_write(tp)
Xstruct tty *tp;
X{
X	extern int (*real_linesw_write) ();
X
X	/* next check us for wakeup maybe? */
X	if(select_sleep) {
X		select_sleep = 0;
X		wakeup((caddr_t) &select_sleep_addr);
X	}
X	(*real_linesw_write)(tp);
X}
Xso_linesw_l_input(tp)
Xstruct tty *tp;
X{
X
X	/* next check us for wakeup maybe? */
X	if(select_sleep) {
X		select_sleep = 0;
X		wakeup((caddr_t) &select_sleep_addr);
X	}
X	/* first call real input routine */
X	(*real_linesw_l_input)(tp);
X}
Xso_linesw_setup()
X{
X	extern int (*real_linesw_write) ();
X	extern int (*real_linesw_read) ();
X	extern int (*real_linesw_l_input) ();
X
X	/* setup to route tty ouput to here */
X	real_linesw_read = linesw[0].l_read;
X	linesw[0].l_read = so_linesw_read;
X	real_linesw_write = linesw[0].l_write;
X	linesw[0].l_write = so_linesw_write;
X	real_linesw_l_input = linesw[0].l_input;
X	linesw[0].l_input = so_linesw_l_input;
X
X}
Xso_linesw_release()
X{
X	extern int (*real_linesw_write) ();
X	extern int (*real_linesw_read) ();
X
X	/* setup to route tty ouput to here */
X	linesw[0].l_read = real_linesw_read;
X	linesw[0].l_write = real_linesw_write;
X	linesw[0].l_input = real_linesw_l_input;
X
X}
+ END-OF-FILE src/linesw.c
chmod 'u=rw,g=r,o=r' 'src/linesw.c'
echo '	-rw-r--r--   1 bes      HSJ         1706 Aug 12 12:26 src/linesw.c        (as sent)'
echo '	\c'
/bin/ls -l src/linesw.c
echo 'Extracting src/mbuf.c'
sed 's/^X//' > src/mbuf.c << '+ END-OF-FILE src/mbuf.c'
X#ifndef LINT
Xstatic char * sccsdef = "@(#)mbuf.c	1.1	(Alex Crain) 6/20/89";
X#endif
X
X/*
X *  mbuf.c - high level socket routines
X *
X *  Written by Alex Crain.
X *
X *  This file is based in the Berkeley file uipc_mbuf.c,
X *  but is *not* guarenteed to be in any way compatable. It is
X *  close enough to the Berkeley code that the following applies...
X *
X *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
X *  All rights reserved.
X * 
X *  Redistribution and use in source and binary forms are permitted
X *  provided that this notice is preserved and that due credit is given
X *  to the University of California at Berkeley. The name of the University
X *  may not be used to endorse or promote products derived from this
X *  software without specific prior written permission. This software
X *  is provided "as is" without express or implied warranty.
X *
X */
X
X
X#include <sys/types.h>
X#include <sys/param.h>
X#include <sys/systm.h>
X#include <uipc/socketvar.h>
X#include <uipc/protosw.h>
X#include <uipc/domain.h>
X#include <uipc/mbuf.h>
X#include <uipc/fproto.h>
X
Xstatic char mbuf_data[sizeof (struct mbuf) * (NMBUF + 1)];
X
X/*
X *  Initialize the mbuf map; all free in a null terminated linked list.
X */
X
Xvoid
Xmbinit()
X{
X   register int i;
X
X   mfree = mbmem = &(dtom (mbuf_data))[1];
X   mbmask = ((unsigned int) mbmem & 0xFF800000);
X
X   for (i = 0; i < NMBUF; i++)
X    {
X       mbmem[i].m_type = MT_FREE;
X       mbmem[i].m_next = &mbmem[i+1];
X    }
X   mbmem[NMBUF-1].m_next = NULL;
X}
X
X/*
X *  get one mbuf structure
X */
X
Xstruct mbuf *
Xm_get (canwait, type)
X  int canwait, type;
X{
X   struct mbuf * m;
X
X   MGET (m, canwait, type);
X   return m;
X}
X
X/*
X *  get a clean mbuf (all zeros).
X */
X
Xstruct mbuf *
Xm_getclr (canwait, type)
X  int canwait, type;
X{
X   register struct mbuf * m;
X   
X   MGET (m, canwait, type);
X   if (m == 0)
X       return 0;
X   bzero (mtod (m, caddr_t), MLEN);
X   return m;
X}
X
X
X/*
X *  free one mbuf structure. returns the next mbuf in the chain.
X */
X
Xstruct mbuf *
Xm_free (m)
X  struct mbuf * m;
X{
X   struct mbuf * n;
X
X   MFREE (m, n);
X   return n;
X}
X
X/*
X * get some more mbuf.
X * There is no more, so we wait until some comes back.
X */ 
X
Xstruct mbuf *
Xm_more (canwait, type)
X  int canwait, type;
X{
X   struct mbuf * m;
X
X   if (canwait == M_WAIT)
X    {
X       m_want++;
X       (void) sleep ((caddr_t) &mfree, PZERO - 1);
X       MGET (m, canwait, type);
X       return m;
X    }
X   else
X       return NULL;
X}
X
X/*
X *  free an mbuf chain.
X */
X
Xvoid
Xm_freem (m)
X  struct mbuf * m;
X{
X   struct mbuf * n;
X   int s = splimp ();
X
X   if (m == NULL)
X       goto done;
X   do {
X      MFREE(m, n);
X   } while (m = n);
X done:
X   splx (s);
X}
X
X/*
X *  copy an mbuf chain, return 0 on failure.
X */
X
Xstruct mbuf *
Xm_copy (m, off, len)
X  struct mbuf * m;
X  int off, len;
X{
X   struct mbuf * n, ** np;
X   struct mbuf * top;
X
X   if (len = 0)
X       return NULL;
X
X   if (off < 0 || len < 0)
X       panic ("m_copy");
X
X   while (off > 0)
X    {
X       if (m == 0)
X	   panic ("m_copy");
X       if (off < m->m_len)
X	   break;
X       off -= m->m_len;
X       m = m->m_next;
X    }
X   np = ⊤
X   top = 0;
X
X   while (len > 0)
X    {
X       if (m == 0)
X	{
X	   if (len != M_COPYALL)
X	       panic ("m_copy");
X	   break;
X	}
X       MGET (n, M_DONTWAIT, m->m_type);
X       if ((*np = n) == 0)
X	   goto nospace;
X
X       n->m_len = MIN (len, m->m_len - off);
X       bcopy (mtod (m, caddr_t), mtod (n, caddr_t), (unsigned) n->m_len);
X       if (len != M_COPYALL)
X	   len -= n->m_len;
X       
X       off = 0;
X       m = m->m_next;
X       np = &n->m_next;
X    }
X   return top;
X
X nospace:
X   m_freem (top);
X   return NULL;
X}
X   
X       
X       
X       
+ END-OF-FILE src/mbuf.c
chmod 'u=rw,g=rw,o=rw' 'src/mbuf.c'
echo '	-rw-rw-rw-   1 bes      HSJ         3635 Aug 12 12:26 src/mbuf.c        (as sent)'
echo '	\c'
/bin/ls -l src/mbuf.c
echo 'Extracting src/proto.c'
sed 's/^X//' > src/proto.c << '+ END-OF-FILE src/proto.c'
X#ifndef LINT
Xstatic char * sccsdef = "@(#)proto.c	1.1	(Alex Crain) 6/20/89";
X#endif
X
X/*
X *  proto.c - protocol spec for the UNIX domain.
X *
X *  Written by Alex Crain.
X *
X *  This file is loosly based in the Berkeley file uipc_proto.c,
X *  but is *not* guarenteed to be in any way compatable. It is
X *  close enough to the Berkeley code that the following applies...
X *
X *  Copyright (c) 1982, 1986, 1988 Regents of the University of California.
X *  All rights reserved.
X * 
X *  Redistribution and use in source and binary forms are permitted
X *  provided that this notice is preserved and that due credit is given
X *  to the University of California at Berkeley. The name of the University
X *  may not be used to endorse or promote products derived from this
X *  software without specific prior written permission. This software
X *  is provided "as is" without express or implied warranty.
X *
X */
X
X#include <sys/types.h>
X#include <sys/param.h>
X#include <sys/systm.h>
X#include <uipc/mbuf.h>
X#include <uipc/socket.h>
X#include <uipc/socketvar.h>
X#include <uipc/protosw.h>
X#include <uipc/domain.h>
X#include <uipc/fproto.h>
X
X/*
X *  UNIX domain protocols
X */
X
Xint	uipc_usrreq ();
Xint	raw_init (), raw_usrreq (), raw_input (), raw_ctlinput ();
Xextern struct domain unixdomain;
X
Xstruct protosw unixsw[] = {
X   { SOCK_STREAM, &unixdomain, 0, PR_CONNREQUIRED | PR_WANTRCVD | PR_RIGHTS,
X      0,	0,	0,	0,
X      uipc_usrreq,
X      0,	0,	0,	0, },
X   { SOCK_DGRAM,  &unixdomain, 0, PR_ATOMIC | PR_ADDR | PR_RIGHTS,
X      0,	0,	0,	0,
X      uipc_usrreq,
X      0,	0,	0,	0, },
X#ifdef SOCK_RAW
X   { 0,		  0,	       0, 0,
X      raw_input, 0,	raw_ctlinput, 0,
X      raw_usrreq,
X      raw_init,	0,	0,	0, },
X#endif
X};
X
Xstruct domain unixdomain =
X{ AF_UNIX, "unix", 0, unp_externalize, (int (*)()) unp_dispose,
X   unixsw, &unixsw[sizeof (unixsw) / sizeof (unixsw[0])] };
X
+ END-OF-FILE src/proto.c
chmod 'u=rw,g=rw,o=rw' 'src/proto.c'
echo '	-rw-rw-rw-   1 bes      HSJ         1848 Aug 12 12:26 src/proto.c        (as sent)'
echo '	\c'
/bin/ls -l src/proto.c
echo 'Extracting src/prwopen.c'
sed 's/^X//' > src/prwopen.c << '+ END-OF-FILE src/prwopen.c'
X/*
X * NAME
X * 	prwopen - modified popen(3) to work with pty's instead of 
X * 		  pipes, and also provide both read and write 
X * 		  capabilities to the child process.
X *
X * SYNOPSIS
X *	#include <stdio.h>
X *	
X * 	int prwopen( cmd, streams )
X *	char *cmd;
X *	FILE streams[2];
X *
X * AUTHOR (actually, merger!)
X *	John Ioannidis, ioannidis at cs.columbia.edu
X * 
X * SEE ALSO
X *	popen(3), after which this call is modelled.
X *
X * UNIX SOURCES USED
X * 	popen(3), script(1)
X *
X */
X#include <stdio.h>
X#include <sys/ioctl.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <signal.h>
X#include <sgtty.h>
X
Xstatic	int	pip_pid[ 20 ];
X
Xint
Xprwopen( cmd, streams )
Xchar *cmd;
XFILE *streams[];
X{
X	int pty, pid, j;
X	struct stat stb;
X	char c;
X	static char *line = "/dev/ptyp0";
X
X        for( c = 'p'; c <= 's'; c++ )
X        {
X                line[strlen("/dev/pty")] = c;
X                line[strlen("/dev/ptyp")] = '0';
X                if( stat( line, &stb ) < 0 )
X                        break;
X                for( j = 0; j < 16; j++ )
X                {
X                        line[strlen("/dev/ptyp")] = "0123456789abcdef"[j];
X                        if( ( pty = open( line, 2 )) > 0 )
X			goto opened;
X                }
X        }
X        return( -1 );
X
Xopened:
X	switch( pid = fork() )
X	{
X	case -1:
X		return( -1 );
X	
X	case 0:
X		{
X			int t, tty;
X			struct sgttyb bf;
X			t=open( "/dev/tty", 2 );
X			if( t >= 0 )
X			{
X				ioctl( t, TIOCNOTTY, (char *)0 );
X				close( t );
X			}
X			line[strlen("/dev/")] = 't';
X			tty = open( line, 2 );
X			close( pty );
X			ioctl( tty, TIOCGETP, &bf );
X			bf.sg_flags &= ~ECHO;
X			ioctl( tty, TIOCSETP, &bf );
X			dup2( tty, 0 );
X			dup2( tty, 1 );
X			dup2( tty, 2 );
X			close( tty );
X
X			execl( "/bin/sh", "sh", "-c", cmd, 0 );
X			_exit(1);
X		}
X	}
X	
X	pip_pid[pty]=pid;
X
X	if( (streams[0] = fdopen( pty, "r" )) == NULL ||
X	    (streams[1] = fdopen( pty, "w" )) == NULL )
X	{
X		return( -1 );
X	}	
X	setbuf( streams[0], NULL );
X	setbuf( streams[1], NULL );
X	return( 0 );
X}
X
Xprwclose( streams )
XFILE *streams[];
X{
X        register f, r, (*hstat)(), (*istat)(), (*qstat)();
X        int status;
X
X        f = fileno(streams[1]);
X        fclose(streams[0]);
X        fclose(streams[1]);
X        istat = signal(SIGINT, SIG_IGN);
X        qstat = signal(SIGQUIT, SIG_IGN);
X        hstat = signal(SIGHUP, SIG_IGN);
X        while((r = wait(&status)) != pip_pid[f] && r != -1)
X                ;
X        if(r == -1)
X                status = -1;
X        signal(SIGINT, istat);
X        signal(SIGQUIT, qstat);
X        signal(SIGHUP, hstat);
X        return(status);
X}
X
+ END-OF-FILE src/prwopen.c
chmod 'u=rw,g=rw,o=' 'src/prwopen.c'
echo '	-rw-rw----   1 bes      HSJ         2565 Aug 12 12:26 src/prwopen.c        (as sent)'
echo '	\c'
/bin/ls -l src/prwopen.c
echo 'Extracting src/pty.c'
sed 's/^X//' > src/pty.c << '+ END-OF-FILE src/pty.c'
X/*
X * pty.c - Berkeley style pseudo tty driver for system V
X *
X * Copyright (c) 1987, Jens-Uwe Mager, FOCUS Computer GmbH
X * Not derived from licensed software.
X *
X * Permission is granted to freely use, copy, modify, and redistribute
X * this software, provided that no attempt is made to gain profit from it,
X * the author is not construed to be liable for any results of using the
X * software, alterations are clearly marked as such, and this notice is
X * not modified.
X */
X
X/*
X * Modified for use on the UnixPC by:
X * Eric H. Herrin II
X * University of Kentucky Mathematical Sciences Laboratories
X * eric at ms.uky.edu, eric at ms.uky.csnet, !cbosgd!ukma!eric
X *
X * See README.3b1 for details of port and installation.
X * Version 2.1
X */
X
X/*
X * the following are arbitrary 3 unused bits from t_state
X * in sys/tty.h
X */
X/* The UnixPC does not have any extra bits in t_state, thus
X * one must provide other means of storing the state.
X */
X#define MRWAIT	01	/* master waiting in read */
X#define t_rloc	t_cc[0]		/* wchannel */
X#define MWWAIT	02	/* master waiting in write */
X#define t_wloc	t_cc[1]		/* wchannel */
X#define MOPEN	04	/* master is open */
X
X#include <uipc/pty.h>
X#include <sys/param.h>
X#include <sys/types.h>
X#include <sys/sysmacros.h>
X#include <sys/systm.h>
X#include <sys/file.h>
X#include <sys/conf.h>
X#include <sys/proc.h>
X#include <sys/dir.h>
X#include <sys/tty.h>
X#include <sys/signal.h>
X#include <sys/user.h>
X#include <sys/errno.h>
X#include <sys/termio.h>
X#include <sys/ttold.h>
X
X/* The tty structures must be local to this driver.  One doesn't have
X * conf.c
X */
Xstruct tty pts_tty[PTYCNT];
Xint pts_cnt = PTYCNT;
Xint ptystate[PTYCNT];
X/* This is needed so that we know what the major device is. This
X * is need by socket driver. So we keep the Major device number
X * here for socket, this is used by the select function 
X */
Xint pty_major = 0; /* if zero then no pty's are opened */
X
Xptyopen(dev, flag)
X	register dev_t		dev;
X	register int		flag;
X{
X	register struct tty *tp;
X
X	dev = minor(dev);
X	if (Master(dev) == True) {
X#		ifdef DEBUG
X		eprintf("open(master): \n");
X#		endif
X		dev -= PTYCNT; 
X		tp = &pts_tty[dev];
X		if (dev >= pts_cnt) {
X			u.u_error = ENXIO;
X			return;
X		}
X		/*
X	 	* allow only one controlling process
X	 	*/
X		if (ptystate[dev] & MOPEN) {
X			u.u_error = EBUSY;
X			return;
X		}
X		if (tp->t_state & WOPEN)
X			wakeup((caddr_t)&tp->t_canq);
X		tp->t_state |= CARR_ON;
X		ptystate[dev] |= MOPEN;
X	} else {
X#		ifdef DEBUG
X		eprintf("open(slave): \n");
X#		endif
X		tp = &pts_tty[dev];
X		if (dev >= pts_cnt) {
X			u.u_error = ENXIO;
X			return;
X		}
X		if ((tp->t_state & (ISOPEN|WOPEN)) == 0) {
X			ttinit(tp);
X			tp->t_proc = ptsproc;
X		}
X		/*
X	  	 * if master is still open, don't wait for carrier
X	 	 */
X		if (ptystate[dev] & MOPEN)
X			tp->t_state |= CARR_ON;
X		if (!(flag & FNDELAY)) {
X			while ((tp->t_state & CARR_ON) == 0) {
X				tp->t_state |= WOPEN;
X				sleep((caddr_t)&tp->t_canq, TTIPRI);
X			}
X		}
X		(*linesw[tp->t_line].l_open)(tp);
X	}
X}
X
Xptyclose(dev, flag)
X	register dev_t		dev;
X	register int		flag;
X{
X        register struct tty     *tp;
X
X	dev = minor(dev);
X	if (Master(dev) == True) {
X#		ifdef DEBUG
X		eprintf("close(master): \n");
X#		endif
X		dev -= PTYCNT;
X		tp = &pts_tty[dev];
X		if (tp->t_state & ISOPEN) {
X			signal(tp->t_pgrp, SIGHUP);
X			ttyflush(tp, FREAD|FWRITE);
X		}
X		/*
X	 	 * virtual carrier gone
X	 	 */
X		tp->t_state &= ~(CARR_ON);
X		ptystate[dev] &= ~MOPEN;
X	} else {
X#		ifdef DEBUG
X		eprintf("close(slave): \n");
X#		endif
X		tp = &pts_tty[dev];
X		(*linesw[tp->t_line].l_close)(tp);
X		tp->t_state &= ~CARR_ON;
X	}
X}
X
Xptyread(dev)
X        register dev_t		dev;
X{
X	register struct tty     *tp;
X	register                n;
X
X	dev = minor(dev);
X	if (Master(dev) == True) {
X#		ifdef DEBUG
X		eprintf("read(master): \n");
X#		endif
X		dev -= PTYCNT;		
X                tp = &pts_tty[dev];
X
X		/* added fix for hanging master side when the slave hangs
X		 * up too early.  Fix by Michael Bloom (mb at ttidca.tti.com).
X		 */
X		if ((tp->t_state & (ISOPEN|TTIOW)) == 0) {
X			u.u_error = EIO;
X			return;
X		}
X		while (u.u_count > 0) {
X			ptsproc(tp, T_OUTPUT);
X			if ((tp->t_state & (TTSTOP|TIMEOUT))
X			    || tp->t_tbuf.c_ptr == NULL || tp->t_tbuf.c_count == 0) {
X				if (u.u_fmode & FNDELAY)
X					break;
X#				ifdef DEBUG
X				eprintf("read(master): master going to sleep\n");
X#				endif
X				ptystate[dev] |= MRWAIT;
X				sleep((caddr_t)&tp->t_rloc, TTIPRI);
X#				ifdef DEBUG
X				eprintf("read(master): master woke up\n");
X#				endif
X
X				continue;
X			}
X			n = min(u.u_count, tp->t_tbuf.c_count);
X			if (n) {
X#				ifdef DEBUG
X				eprintf("read(master): got some stuff\n");
X#				endif
X				if (copyout(tp->t_tbuf.c_ptr, u.u_base, n)) {
X					u.u_error = EFAULT;
X					break;
X				}
X				tp->t_tbuf.c_count -= n;
X				tp->t_tbuf.c_ptr += n;
X				u.u_base += n;
X				u.u_count -= n;
X			}
X		}
X	} else {
X#		ifdef DEBUG
X		eprintf("read(slave): \n");
X#		endif
X		tp = &pts_tty[dev];
X#		ifdef DEBUG
X		eprintf("read(slave): got some stuff\n");
X#		endif
X		(*linesw[tp->t_line].l_read)(tp);
X	}
X}
X	
Xptywrite(dev)
X	register dev_t		dev;
X{
X	register struct tty     *tp;
X	register                n;
X
X	dev = minor(dev);
X	if (Master(dev) == True) {
X#		ifdef DEBUG
X		eprintf("write(master): \n");
X#		endif
X		dev -= PTYCNT;
X		tp = &pts_tty[dev];
X		
X		if ((tp->t_state & ISOPEN) == 0) {
X			u.u_error = EIO;
X			return;
X		}
X		while (u.u_count > 0) {
X			if ((tp->t_state & TBLOCK) || tp->t_rbuf.c_ptr == NULL) {
X				if (u.u_fmode & FNDELAY)
X					break;
X				ptystate[dev] |= MWWAIT;
X#				ifdef DEBUG
X				eprintf("write(master): going to sleep\n");
X#				endif
X
X				sleep((caddr_t)&tp->t_wloc, TTOPRI);
X
X#				ifdef DEBUG
X				eprintf("write: waking up\n");
X#				endif
X
X				continue;
X			}
X			n = min(u.u_count, tp->t_rbuf.c_count);
X			if (n) {
X#				ifdef DEBUG
X				eprintf("write(master): sending some stuff\n");
X#				endif
X				if (copyin(u.u_base,tp->t_rbuf.c_ptr, n)) {
X					u.u_error = EFAULT;
X					break;
X				}
X				tp->t_rbuf.c_count -= n;
X				u.u_base += n;
X				u.u_count -= n;
X			}
X			(*linesw[tp->t_line].l_input)(tp);
X		}
X	} else {
X#		ifdef DEBUG
X		eprintf("write(slave): \n");
X#		endif
X		tp = &pts_tty[dev];
X#		ifdef DEBUG
X		eprintf("write(slave): sending some stuff\n");
X#		endif
X		(*linesw[tp->t_line].l_write)(tp);
X	}
X}
X
Xptyioctl(dev, cmd, arg, mode)
X	dev_t		dev;
X	int		cmd, arg, mode;
X{
X	register struct tty *tp;
X
X	dev = minor(dev);
X	if (Master(dev) == True) {
X#		ifdef DEBUG
X		eprintf("ioctl(master): \n");
X#		endif
X		dev -= PTYCNT;
X		tp = &pts_tty[dev];
X		/*
X	 	 * sorry, but we can't fiddle with the tty struct without
X	 	 * having done LDOPEN
X	 	 */
X		if (tp->t_state & ISOPEN) {
X			if (cmd == TCSBRK && arg ==  NULL) {
X				signal(tp->t_pgrp, SIGINT);
X				if ((tp->t_iflag & NOFLSH) == 0)
X					ttyflush(tp, FREAD|FWRITE);
X			} else {
X				/*
X			 	 * we must flush output to avoid hang in ttywait
X			 	 */
X				if (cmd == TCSETAW || cmd == TCSETAF || 
X				   cmd == TCSBRK || cmd == TIOCSETP)
X					ttyflush(tp, FWRITE);
X				ttiocom(tp, cmd, arg, mode);
X			}
X		}
X	} else {
X#		ifdef DEBUG
X		eprintf("ioctl(slave): \n");
X#		endif
X		tp = &pts_tty[dev];
X		ttiocom(tp, cmd, arg, mode);
X	}
X}
X
Xptsproc(tp, cmd)
Xregister struct tty *tp;
X{
X	register struct ccblock *tbuf;
X	extern ttrstrt();
X
X	switch (cmd) {
X	case T_TIME:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_TIME:\n");
X#		endif
X		tp->t_state &= ~TIMEOUT;
X		goto start;
X	case T_WFLUSH:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_WFLUSH:\n");
X#		endif
X		tp->t_tbuf.c_size  -= tp->t_tbuf.c_count;
X		tp->t_tbuf.c_count = 0;
X		/* fall through */
X	case T_RESUME:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_RESUME:\n");
X#		endif
X		tp->t_state &= ~TTSTOP;
X		/* fall through */
X	case T_OUTPUT:
Xstart:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_OUTPUT:\n");
X#		endif
X		if (tp->t_state & (TTSTOP|TIMEOUT))
X			break;
X#		ifdef DEBUG
X		eprintf("ptsproc: T_OUTPUT: past(TTSTOP|TIMEOUT)");
X#		endif
X		tbuf = &tp->t_tbuf;
X		if (tbuf->c_ptr == NULL || tbuf->c_count == 0) {
X#		ifdef DEBUG
X		eprintf("ptsproc: T_OUTPUT: tbuf empty, may break\n");
X#		endif
X			if (tbuf->c_ptr)
X				tbuf->c_ptr -= tbuf->c_size;
X			if (!(CPRES & (*linesw[tp->t_line].l_output)(tp)))
X				break;
X		}
X		if (tbuf->c_count && (ptystate[tp-pts_tty] & MRWAIT)) {
X#ifdef DEBUG
X			eprintf("ptsproc: T_OUTPUT: waking up master\n");
X#endif
X			ptystate[tp-pts_tty] &= ~MRWAIT;
X			wakeup((caddr_t)&tp->t_rloc);
X		}
X#		ifdef DEBUG
X		eprintf("ptsproc: T_OUTPUT: leaving end\n");
X#		endif
X		break;
X	case T_SUSPEND:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_SUSPEND:\n");
X#		endif
X		tp->t_state |= TTSTOP;
X		break;
X	case T_BLOCK:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_BLOCK:\n");
X#		endif
X		/*
X		 * the check for ICANON appears to be neccessary
X		 * to avoid a hang when overflowing input
X		 */
X		if ((tp->t_iflag & ICANON) == 0)
X			tp->t_state |= TBLOCK;
X		break;
X	case T_BREAK:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_BREAK:\n");
X#		endif
X		tp->t_state |= TIMEOUT;
X		timeout(ttrstrt, tp, HZ/4);
X		break;
X#ifdef T_LOG_FLUSH
X	case T_LOG_FLUSH:
X#endif
X	case T_RFLUSH:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_RFLUSH:\n");
X#		endif
X		if (!(tp->t_state & TBLOCK))
X			break;
X		/* fall through */
X	case T_UNBLOCK:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_UNBLOCK:\n");
X#		endif
X		tp->t_state &= ~(TTXOFF|TBLOCK);
X		/* fall through */
X	case T_INPUT:
X#		ifdef DEBUG
X		eprintf("ptsproc: T_INPUT:\n");
X#		endif
X		if (ptystate[tp-pts_tty] & MWWAIT) {
X			ptystate[tp-pts_tty] &= ~MWWAIT;
X#			ifdef DEBUG
X			eprintf("ptsproc: T_INPUT: waking up master\n");
X#			endif
X			wakeup((caddr_t)&tp->t_wloc);
X		}
X		break;
X	default:
X#		ifdef DEBUG
X		eprintf("ptsproc: default:\n");
X#		else
X		;
X#		endif
X	}
X}
X	
X/* This routine used to be a stub, however, an industrious soul found
X * the release routine caused a panic whenever the driver is released
X * and some ptys are still open.  The simple 'for' loop fixes this 
X * problem.
X *
X * Credit should be given to:
X * Mike "Ford" Ditto
X * kenobi!ford at crash.CTS.COM, ...!crash!kenobi!ford
X * for finding the bug and writing the for loop.
X *
X * [Eric H. Herrin II, 10-7-87]
X */
Xptyrelease()
X{
X	register int 	i;
X
X#	ifdef DEBUG
X	eprintf("ptyrelease:\n");
X#	endif
X	for (i=0; i<PTYCNT; i++)
X		if ((ptystate[i] & (ISOPEN|MOPEN)) || 
X                   (pts_tty[i].t_state & WOPEN)) {
X			u.u_error = EBUSY;
X			return;
X		}
X	/* next release socket driver */
X	i = uipcrelease();
X	return i;
X}
+ END-OF-FILE src/pty.c
chmod 'u=rw,g=r,o=r' 'src/pty.c'
echo '	-rw-r--r--   1 bes      HSJ        10252 Aug 12 12:26 src/pty.c        (as sent)'
echo '	\c'
/bin/ls -l src/pty.c
exit 0
-- 
Bradley Smith
Computer Systems Offer Integration Laboratory
AT&T Bell Labs, Holmdel, NJ 
201-949-0090 att!holin!bes or bes at holin.ATT.COM



More information about the Unix-pc.sources mailing list