add POSIX-style byte-level record locking
[unix-history] / usr / src / sys / kern / kern_sysctl.c
index cbc8fcf..57b4316 100644 (file)
@@ -2,44 +2,34 @@
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  *
  *
- *     @(#)kern_sysctl.c       7.6 (Berkeley) %G%
+ *     @(#)kern_sysctl.c       7.12 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "user.h"
 #include "proc.h"
  */
 
 #include "param.h"
 #include "user.h"
 #include "proc.h"
-#include "text.h"
 #include "kinfo.h"
 #include "kinfo.h"
-#include "vm.h"
 #include "ioctl.h"
 #include "tty.h"
 #include "buf.h"
 
 #include "ioctl.h"
 #include "tty.h"
 #include "buf.h"
 
-
 #define snderr(e) { error = (e); goto release;}
 #define snderr(e) { error = (e); goto release;}
-extern int kinfo_doproc(), kinfo_rtable();
+extern int kinfo_doproc(), kinfo_rtable(), kinfo_vnode();
 struct kinfo_lock kinfo_lock;
 
 struct kinfo_lock kinfo_lock;
 
-getkerninfo()
-{
-       register struct a {
+/* ARGSUSED */
+getkerninfo(p, uap, retval)
+       struct proc *p;
+       register struct args {
                int     op;
                char    *where;
                int     *size;
                int     arg;
                int     op;
                char    *where;
                int     *size;
                int     arg;
-       } *uap = (struct a *)u.u_ap;
+       } *uap;
+       int *retval;
+{
 
        int     bufsize,        /* max size of users buffer */
                needed, locked, (*server)(), error = 0;
 
        int     bufsize,        /* max size of users buffer */
                needed, locked, (*server)(), error = 0;
@@ -58,6 +48,10 @@ getkerninfo()
                server = kinfo_rtable;
                break;
 
                server = kinfo_rtable;
                break;
 
+       case KINFO_VNODE:
+               server = kinfo_vnode;
+               break;
+
        default:
                error = EINVAL;
                goto done;
        default:
                error = EINVAL;
                goto done;
@@ -76,15 +70,12 @@ getkerninfo()
 
        if (!useracc(uap->where, bufsize, B_WRITE))
                snderr(EFAULT);
 
        if (!useracc(uap->where, bufsize, B_WRITE))
                snderr(EFAULT);
-       /*
-        * lock down target pages - NEED DEADLOCK AVOIDANCE
-        */
-       if (bufsize > ((int)ptob(freemem) - (20 * 1024)))       /* XXX */
-               snderr(ENOMEM);
-       vslock(uap->where, bufsize);
+       if (server != kinfo_vnode)      /* XXX */
+               vslock(uap->where, bufsize);
        locked = bufsize;
        error = (*server)(uap->op, uap->where, &bufsize, uap->arg, &needed);
        locked = bufsize;
        error = (*server)(uap->op, uap->where, &bufsize, uap->arg, &needed);
-       vsunlock(uap->where, locked, B_WRITE);
+       if (server != kinfo_vnode)      /* XXX */
+               vsunlock(uap->where, locked, B_WRITE);
        if (error == 0)
                error = copyout((caddr_t)&bufsize,
                                (caddr_t)uap->size, sizeof (bufsize));
        if (error == 0)
                error = copyout((caddr_t)&bufsize,
                                (caddr_t)uap->size, sizeof (bufsize));
@@ -93,10 +84,9 @@ release:
        if (kinfo_lock.kl_want)
                wakeup(&kinfo_lock);
 done:
        if (kinfo_lock.kl_want)
                wakeup(&kinfo_lock);
 done:
-       if (error)
-               u.u_error = error;
-       else
-               u.u_r.r_val1 = needed;
+       if (!error)
+               *retval = needed;
+       return (error);
 }
 
 /* 
 }
 
 /* 
@@ -109,12 +99,11 @@ kinfo_doproc(op, where, acopysize, arg, aneeded)
        int *acopysize, *aneeded;
 {
        register struct proc *p;
        int *acopysize, *aneeded;
 {
        register struct proc *p;
-       register caddr_t dp = (caddr_t)where;
+       register struct kinfo_proc *dp = (struct kinfo_proc *)where;
        register needed = 0;
        int buflen;
        int doingzomb;
        struct eproc eproc;
        register needed = 0;
        int buflen;
        int doingzomb;
        struct eproc eproc;
-       struct tty *tp;
        int error = 0;
 
        if (where != NULL)
        int error = 0;
 
        if (where != NULL)
@@ -160,42 +149,34 @@ again:
                        break;
                }
                if (where != NULL && buflen >= sizeof (struct kinfo_proc)) {
                        break;
                }
                if (where != NULL && buflen >= sizeof (struct kinfo_proc)) {
-                       register struct text *txt;
+                       register struct tty *tp;
 
 
-                       if (error = copyout((caddr_t)p, dp
+                       if (error = copyout((caddr_t)p, &dp->kp_proc
                            sizeof (struct proc)))
                                return (error);
                            sizeof (struct proc)))
                                return (error);
-                       dp += sizeof (struct proc);
-                       /*
-                        *      XXX NEED ALLIGNMENT
-                        */
                        eproc.e_paddr = p;
                        eproc.e_sess = p->p_pgrp->pg_session;
                        eproc.e_pgid = p->p_pgrp->pg_id;
                        eproc.e_jobc = p->p_pgrp->pg_jobc;
                        eproc.e_paddr = p;
                        eproc.e_sess = p->p_pgrp->pg_session;
                        eproc.e_pgid = p->p_pgrp->pg_id;
                        eproc.e_jobc = p->p_pgrp->pg_jobc;
-                       tp = p->p_pgrp->pg_session->s_ttyp;
-                       if ((p->p_flag&SCTTY) && tp != NULL) {
+                       if ((p->p_flag&SCTTY) && 
+                            (tp = eproc.e_sess->s_ttyp)) {
                                eproc.e_tdev = tp->t_dev;
                                eproc.e_tpgid = tp->t_pgrp ? 
                                        tp->t_pgrp->pg_id : -1;
                                eproc.e_tsess = tp->t_session;
                        } else
                                eproc.e_tdev = NODEV;
                                eproc.e_tdev = tp->t_dev;
                                eproc.e_tpgid = tp->t_pgrp ? 
                                        tp->t_pgrp->pg_id : -1;
                                eproc.e_tsess = tp->t_session;
                        } else
                                eproc.e_tdev = NODEV;
+                       eproc.e_flag = eproc.e_sess->s_ttyvp ? EPROC_CTTY : 0;
+                       if (SESS_LEADER(p))
+                               eproc.e_flag |= EPROC_SLEADER;
                        if (p->p_wmesg)
                                strncpy(eproc.e_wmesg, p->p_wmesg, WMESGLEN);
                        if (p->p_wmesg)
                                strncpy(eproc.e_wmesg, p->p_wmesg, WMESGLEN);
-                       if (txt = p->p_textp) {
-                               eproc.e_xsize = txt->x_size;
-                               eproc.e_xrssize = txt->x_rssize;
-                               eproc.e_xccount = txt->x_ccount;
-                               eproc.e_xswrss = txt->x_swrss;
-                       } else {
-                               eproc.e_xsize = eproc.e_xrssize =
-                                 eproc.e_xccount =  eproc.e_xswrss = 0;
-                       }
-                       if (error = copyout((caddr_t)&eproc, dp, 
+                       eproc.e_xsize = eproc.e_xrssize = 0;
+                       eproc.e_xccount =  eproc.e_xswrss = 0;
+                       if (error = copyout((caddr_t)&eproc, &dp->kp_eproc, 
                            sizeof (eproc)))
                                return (error);
                            sizeof (eproc)))
                                return (error);
-                       dp += sizeof (eproc);
+                       dp++;
                        buflen -= sizeof (struct kinfo_proc);
                }
                needed += sizeof (struct kinfo_proc);
                        buflen -= sizeof (struct kinfo_proc);
                }
                needed += sizeof (struct kinfo_proc);
@@ -206,7 +187,7 @@ again:
                goto again;
        }
        if (where != NULL)
                goto again;
        }
        if (where != NULL)
-               *acopysize = dp - where;
+               *acopysize = (caddr_t)dp - where;
        else
                needed += KINFO_PROCSLOP;
        *aneeded = needed;
        else
                needed += KINFO_PROCSLOP;
        *aneeded = needed;