must include proc before tty.h and socketvar.h
[unix-history] / usr / src / sys / kern / tty_tty.c
index f528a0e..9b26f68 100644 (file)
@@ -1,9 +1,10 @@
-/*
- * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1982, 1986, 1991 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
  *
  *
- *     @(#)tty_tty.c   7.11 (Berkeley) %G%
+ *     @(#)tty_tty.c   7.17 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
 #include "param.h"
 #include "systm.h"
 #include "conf.h"
 #include "param.h"
 #include "systm.h"
 #include "conf.h"
-#include "user.h"
 #include "ioctl.h"
 #include "ioctl.h"
-#include "tty.h"
 #include "proc.h"
 #include "proc.h"
+#include "tty.h"
 #include "vnode.h"
 #include "file.h"
 #include "vnode.h"
 #include "file.h"
-#include "uio.h"
 
 #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL)
 
 /*ARGSUSED*/
 
 #define cttyvp(p) ((p)->p_flag&SCTTY ? (p)->p_session->s_ttyvp : NULL)
 
 /*ARGSUSED*/
-cttyopen(dev, flag)
+cttyopen(dev, flag, mode, p)
        dev_t dev;
        dev_t dev;
-       int flag;
+       int flag, mode;
+       struct proc *p;
 {
 {
-       struct proc *p = curproc;
        struct vnode *ttyvp = cttyvp(p);
        int error;
 
        struct vnode *ttyvp = cttyvp(p);
        int error;
 
@@ -35,23 +34,24 @@ cttyopen(dev, flag)
                return (ENXIO);
        VOP_LOCK(ttyvp);
        error = VOP_ACCESS(ttyvp,
                return (ENXIO);
        VOP_LOCK(ttyvp);
        error = VOP_ACCESS(ttyvp,
-          (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred);
+         (flag&FREAD ? VREAD : 0) | (flag&FWRITE ? VWRITE : 0), p->p_ucred, p);
+       if (!error)
+               error = VOP_OPEN(ttyvp, flag, NOCRED, p);
        VOP_UNLOCK(ttyvp);
        VOP_UNLOCK(ttyvp);
-       if (error)
-               return (error);
-       return (VOP_OPEN(ttyvp, flag, NOCRED));
+       return (error);
 }
 
 /*ARGSUSED*/
 cttyread(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
 }
 
 /*ARGSUSED*/
 cttyread(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
+       int flag;
 {
 {
-       register struct vnode *ttyvp = cttyvp(curproc);
+       register struct vnode *ttyvp = cttyvp(uio->uio_procp);
        int error;
 
        if (ttyvp == NULL)
        int error;
 
        if (ttyvp == NULL)
-               return (ENXIO);
+               return (EIO);
        VOP_LOCK(ttyvp);
        error = VOP_READ(ttyvp, uio, flag, NOCRED);
        VOP_UNLOCK(ttyvp);
        VOP_LOCK(ttyvp);
        error = VOP_READ(ttyvp, uio, flag, NOCRED);
        VOP_UNLOCK(ttyvp);
@@ -62,12 +62,13 @@ cttyread(dev, uio, flag)
 cttywrite(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
 cttywrite(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
+       int flag;
 {
 {
-       register struct vnode *ttyvp = cttyvp(curproc);
+       register struct vnode *ttyvp = cttyvp(uio->uio_procp);
        int error;
 
        if (ttyvp == NULL)
        int error;
 
        if (ttyvp == NULL)
-               return (ENXIO);
+               return (EIO);
        VOP_LOCK(ttyvp);
        error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
        VOP_UNLOCK(ttyvp);
        VOP_LOCK(ttyvp);
        error = VOP_WRITE(ttyvp, uio, flag, NOCRED);
        VOP_UNLOCK(ttyvp);
@@ -75,34 +76,36 @@ cttywrite(dev, uio, flag)
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
-cttyioctl(dev, cmd, addr, flag)
+cttyioctl(dev, cmd, addr, flag, p)
        dev_t dev;
        int cmd;
        caddr_t addr;
        int flag;
        dev_t dev;
        int cmd;
        caddr_t addr;
        int flag;
+       struct proc *p;
 {
 {
-       struct vnode *ttyvp = cttyvp(curproc);
+       struct vnode *ttyvp = cttyvp(p);
 
        if (ttyvp == NULL)
 
        if (ttyvp == NULL)
-               return (ENXIO);
+               return (EIO);
        if (cmd == TIOCNOTTY) {
        if (cmd == TIOCNOTTY) {
-               if (!SESS_LEADER(curproc)) {
-                       curproc->p_flag &= ~SCTTY;
+               if (!SESS_LEADER(p)) {
+                       p->p_flag &= ~SCTTY;
                        return (0);
                } else
                        return (EINVAL);
        }
                        return (0);
                } else
                        return (EINVAL);
        }
-       return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED));
+       return (VOP_IOCTL(ttyvp, cmd, addr, flag, NOCRED, p));
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
-cttyselect(dev, flag)
+cttyselect(dev, flag, p)
        dev_t dev;
        int flag;
        dev_t dev;
        int flag;
+       struct proc *p;
 {
 {
-       struct vnode *ttyvp = cttyvp(curproc);
+       struct vnode *ttyvp = cttyvp(p);
 
        if (ttyvp == NULL)
                return (1);     /* try operation to get EOF/failure */
 
        if (ttyvp == NULL)
                return (1);     /* try operation to get EOF/failure */
-       return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED));
+       return (VOP_SELECT(ttyvp, flag, FREAD|FWRITE, NOCRED, p));
 }
 }