-/* $OpenBSD: kern_descrip.c,v 1.83 2010/03/24 23:18:17 tedu Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.84 2010/07/19 23:00:15 guenther Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
* Descriptor management.
*/
struct filelist filehead; /* head of list of open files */
-struct rwlock fileheadlk;
int nfiles; /* actual number of open files */
static __inline void fd_used(struct filedesc *, int);
pool_init(&fdesc_pool, sizeof(struct filedesc0), 0, 0, 0, "fdescpl",
&pool_allocator_nointr);
LIST_INIT(&filehead);
- rw_init(&fileheadlk, "filehead");
}
static __inline int
nfiles++;
fp = pool_get(&file_pool, PR_WAITOK|PR_ZERO);
fp->f_iflags = FIF_LARVAL;
- rw_enter_write(&fileheadlk);
if ((fq = p->p_fd->fd_ofiles[0]) != NULL) {
LIST_INSERT_AFTER(fq, fp, f_list);
} else {
LIST_INSERT_HEAD(&filehead, fp, f_list);
}
- rw_exit_write(&fileheadlk);
p->p_fd->fd_ofiles[i] = fp;
fp->f_count = 1;
fp->f_cred = p->p_ucred;
error = 0;
/* Free fp */
- rw_enter_write(&fileheadlk);
LIST_REMOVE(fp, f_list);
- rw_exit_write(&fileheadlk);
crfree(fp->f_cred);
#ifdef DIAGNOSTIC
if (fp->f_count != 0 || fp->f_usecount != 1)
-/* $OpenBSD: kern_exit.c,v 1.94 2010/06/29 20:25:57 guenther Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.95 2010/07/19 23:00:15 guenther Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
* deadproc list later (using the p_hash member), and
* wake up the reaper when we do.
*/
- rw_enter_write(&allproclk);
/*
* NOTE: WE ARE NO LONGER ALLOWED TO SLEEP!
*/
LIST_REMOVE(p, p_hash);
LIST_REMOVE(p, p_list);
LIST_INSERT_HEAD(&zombproc, p, p_list);
- rw_exit_write(&allproclk);
/*
* Give orphaned children to init(8).
* Unlink it from its process group and free it.
*/
leavepgrp(p);
- rw_enter_write(&allproclk);
LIST_REMOVE(p, p_list); /* off zombproc */
- rw_exit_write(&allproclk);
LIST_REMOVE(p, p_sibling);
/*
-/* $OpenBSD: kern_fork.c,v 1.119 2010/07/02 01:25:05 art Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.120 2010/07/19 23:00:15 guenther Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
#endif
/* Find an unused pid satisfying 1 <= lastpid <= PID_MAX */
- rw_enter_write(&allproclk);
do {
lastpid = 1 + (randompid ? arc4random() : lastpid) % PID_MAX;
} while (pidtaken(lastpid));
LIST_INSERT_HEAD(&allproc, p2, p_list);
LIST_INSERT_HEAD(PIDHASH(p2->p_pid), p2, p_hash);
- rw_exit_write(&allproclk);
LIST_INSERT_HEAD(&p1->p_children, p2, p_sibling);
LIST_INSERT_AFTER(p1, p2, p_pglist);
if (p2->p_flag & P_TRACED) {
-/* $OpenBSD: kern_proc.c,v 1.43 2010/07/10 21:29:37 guenther Exp $ */
+/* $OpenBSD: kern_proc.c,v 1.44 2010/07/19 23:00:15 guenther Exp $ */
/* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */
/*
#include <sys/acct.h>
#include <sys/wait.h>
#include <sys/file.h>
-#include <sys/rwlock.h>
#include <ufs/ufs/quota.h>
#include <sys/uio.h>
#include <sys/malloc.h>
struct pgrphashhead *pgrphashtbl;
u_long pgrphash;
struct proclist allproc;
-struct rwlock allproclk;
struct proclist zombproc;
struct pool proc_pool;
procinit(void)
{
LIST_INIT(&allproc);
- rw_init(&allproclk, "allproc");
LIST_INIT(&zombproc);
-/* $OpenBSD: kern_sysctl.c,v 1.189 2010/07/10 21:29:37 guenther Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.190 2010/07/19 23:00:15 guenther Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
switch (name[0]) {
case CTL_KERN:
fn = kern_sysctl;
- switch (name[1]) { /* XXX */
- case KERN_VNODE:
- case KERN_FILE:
- case KERN_FILE2:
+ if (name[1] == KERN_VNODE) /* XXX */
dolock = 0;
- break;
- }
break;
case CTL_HW:
fn = hw_sysctl;
/*
* followed by an array of file structures
*/
- rw_enter_read(&fileheadlk);
LIST_FOREACH(fp, &filehead, f_list) {
if (buflen < sizeof(struct file)) {
*sizep = where - start;
- error = ENOMEM;
- goto out;
+ return (ENOMEM);
}
/* Only let the superuser or the owner see some information */
}
error = copyout(&cfile, where, sizeof (struct file));
if (error)
- goto out;
+ return (error);
buflen -= sizeof(struct file);
where += sizeof(struct file);
}
*sizep = where - start;
-out:
- rw_exit_read(&fileheadlk);
- return (error);
+ return (0);
}
#ifndef SMALL_KERNEL
error = EINVAL;
break;
}
- rw_enter_read(&fileheadlk);
LIST_FOREACH(fp, &filehead, f_list) {
if (fp->f_count == 0)
continue;
FILLIT(fp, NULL, 0, NULL, NULL);
}
- rw_exit_read(&fileheadlk);
break;
case KERN_FILE_BYPID:
/* A arg of -1 indicates all processes */
error = EINVAL;
break;
}
- rw_enter_read(&allproclk);
LIST_FOREACH(pp, &allproc, p_list) {
/* skip system, exiting, embryonic and undead processes */
if ((pp->p_flag & P_SYSTEM) || (pp->p_flag & P_WEXIT)
continue;
}
fdp = pp->p_fd;
- fdplock(fdp);
if (pp->p_textvp)
FILLIT(NULL, NULL, KERN_FILE_TEXT, pp->p_textvp, pp);
if (fdp->fd_cdir)
continue;
FILLIT(fp, fdp, i, NULL, pp);
}
- fdpunlock(fdp);
}
- rw_exit_read(&allproclk);
break;
case KERN_FILE_BYUID:
- rw_enter_read(&allproclk);
LIST_FOREACH(pp, &allproc, p_list) {
/* skip system, exiting, embryonic and undead processes */
if ((pp->p_flag & P_SYSTEM) || (pp->p_flag & P_WEXIT)
continue;
}
fdp = pp->p_fd;
- fdplock(fdp);
if (fdp->fd_cdir)
FILLIT(NULL, NULL, KERN_FILE_CDIR, fdp->fd_cdir, pp);
if (fdp->fd_rdir)
continue;
FILLIT(fp, fdp, i, NULL, pp);
}
- fdpunlock(fdp);
}
- rw_exit_read(&allproclk);
break;
default:
error = EINVAL;
elem_count = name[4];
kproc2 = malloc(sizeof(struct kinfo_proc2), M_TEMP, M_WAITOK);
}
- rw_enter_read(&allproclk);
p = LIST_FIRST(&allproc);
doingzomb = 0;
again:
*sizep = needed;
}
err:
- rw_exit_read(&allproclk);
if (eproc)
free(eproc, M_TEMP);
if (kproc2)
-/* $OpenBSD: file.h,v 1.26 2010/03/24 23:18:17 tedu Exp $ */
+/* $OpenBSD: file.h,v 1.27 2010/07/19 23:00:15 guenther Exp $ */
/* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */
/*
LIST_HEAD(filelist, file);
extern struct filelist filehead; /* head of list of open files */
-extern struct rwlock fileheadlk;
extern int maxfiles; /* kernel limit on number of open files */
extern int nfiles; /* actual number of open files */
extern struct fileops vnops; /* vnode operations for files */
-/* $OpenBSD: proc.h,v 1.130 2010/07/03 04:44:51 guenther Exp $ */
+/* $OpenBSD: proc.h,v 1.131 2010/07/19 23:00:15 guenther Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
LIST_HEAD(proclist, proc);
extern struct proclist allproc; /* List of all processes. */
-extern struct rwlock allproclk; /* also used for zombie list */
extern struct proclist zombproc; /* List of zombie processes. */
extern struct proc *initproc; /* Process slots for init, pager. */