summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_sysctl.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2012-05-01 03:43:23 +0000
committerguenther <guenther@openbsd.org>2012-05-01 03:43:23 +0000
commit50902bb7879663d57b7f98c50d39fd2c75bd21d3 (patch)
tree38a589affa179c76181b0a81b58cf028f945fef1 /sys/kern/kern_sysctl.c
parentCorrect the error path in execve when there's a race to single thread (diff)
downloadwireguard-openbsd-50902bb7879663d57b7f98c50d39fd2c75bd21d3.tar.xz
wireguard-openbsd-50902bb7879663d57b7f98c50d39fd2c75bd21d3.zip
Eliminate the f_usecount ref count in struct file; instead of sleeping
at the top of closef() until all in-progress calls finish, just do the advisory locking bits required of close() by POSIX and let whichever thread has the last reference do the call to the file's fo_close() method and the final cleanup. lots of discussion with deraadt@ and others; worked out with and ok krw@
Diffstat (limited to 'sys/kern/kern_sysctl.c')
-rw-r--r--sys/kern/kern_sysctl.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index c7b1e5331e3..907035779df 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.221 2012/04/17 23:17:53 pirofti Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.222 2012/05/01 03:43:23 guenther Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -1088,7 +1088,7 @@ fill_file2(struct kinfo_file2 *kf, struct file *fp, struct filedesc *fdp,
kf->f_gid = fp->f_cred->cr_gid;
kf->f_ops = PTRTOINT64(fp->f_ops);
kf->f_data = PTRTOINT64(fp->f_data);
- kf->f_usecount = fp->f_usecount;
+ kf->f_usecount = 0;
if (suser(p, 0) == 0 || p->p_ucred->cr_uid == fp->f_cred->cr_uid) {
kf->f_offset = fp->f_offset;
@@ -1288,8 +1288,11 @@ sysctl_file2(int *name, u_int namelen, char *where, size_t *sizep,
break;
}
LIST_FOREACH(pp, &allproc, p_list) {
- /* skip system, exiting, embryonic and undead processes */
- if ((pp->p_flag & P_SYSTEM) || (pp->p_flag & P_WEXIT)
+ /*
+ * skip system, exiting, embryonic and undead
+ * processes, as well as threads
+ */
+ if ((pp->p_flag & (P_SYSTEM | P_WEXIT | P_THREAD))
|| (pp->p_p->ps_flags & PS_EXITING)
|| pp->p_stat == SIDL || pp->p_stat == SZOMB)
continue;
@@ -1317,8 +1320,11 @@ sysctl_file2(int *name, u_int namelen, char *where, size_t *sizep,
break;
case KERN_FILE_BYUID:
LIST_FOREACH(pp, &allproc, p_list) {
- /* skip system, exiting, embryonic and undead processes */
- if ((pp->p_flag & P_SYSTEM) || (pp->p_flag & P_WEXIT)
+ /*
+ * skip system, exiting, embryonic and undead
+ * processes, as well as threads
+ */
+ if ((pp->p_flag & (P_SYSTEM | P_WEXIT | P_THREAD))
|| (pp->p_p->ps_flags & PS_EXITING)
|| pp->p_stat == SIDL || pp->p_stat == SZOMB)
continue;