-/* $OpenBSD: kern_proc.c,v 1.81 2018/02/20 12:38:58 mpi Exp $ */
+/* $OpenBSD: kern_proc.c,v 1.82 2018/02/26 13:43:51 mpi Exp $ */
/* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */
/*
#include <sys/buf.h>
#include <sys/acct.h>
#include <sys/wait.h>
+#include <sys/rwlock.h>
#include <ufs/ufs/quota.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/pool.h>
#include <sys/vnode.h>
+struct rwlock uidinfolk;
#define UIHASH(uid) (&uihashtbl[(uid) & uihash])
LIST_HEAD(uihashhead, uidinfo) *uihashtbl;
u_long uihash; /* size of hash table - 1 */
LIST_INIT(&zombprocess);
LIST_INIT(&allproc);
+ rw_init(&uidinfolk, "uidinfo");
tidhashtbl = hashinit(maxthread / 4, M_PROC, M_NOWAIT, &tidhash);
pidhashtbl = hashinit(maxprocess / 4, M_PROC, M_NOWAIT, &pidhash);
PR_WAITOK, "sessionpl", NULL);
}
+/*
+ * This returns with `uidinfolk' held: caller must call uid_release()
+ * after making whatever change they needed.
+ */
struct uidinfo *
uid_find(uid_t uid)
{
struct uihashhead *uipp;
uipp = UIHASH(uid);
+ rw_enter_write(&uidinfolk);
LIST_FOREACH(uip, uipp, ui_hash)
if (uip->ui_uid == uid)
break;
if (uip)
return (uip);
+ rw_exit_write(&uidinfolk);
nuip = malloc(sizeof(*nuip), M_PROC, M_WAITOK|M_ZERO);
+ rw_enter_write(&uidinfolk);
LIST_FOREACH(uip, uipp, ui_hash)
if (uip->ui_uid == uid)
break;
return (nuip);
}
+void
+uid_release(struct uidinfo *uip)
+{
+ rw_exit_write(&uidinfolk);
+}
+
/*
* Change the count associated with number of threads
* a given user is using.
chgproccnt(uid_t uid, int diff)
{
struct uidinfo *uip;
+ long count;
uip = uid_find(uid);
- uip->ui_proccnt += diff;
- if (uip->ui_proccnt < 0)
+ count = (uip->ui_proccnt += diff);
+ uid_release(uip);
+ if (count < 0)
panic("chgproccnt: procs < 0");
- return (uip->ui_proccnt);
+ return count;
}
/*
-/* $OpenBSD: vfs_lockf.c,v 1.24 2016/11/07 00:26:33 guenther Exp $ */
+/* $OpenBSD: vfs_lockf.c,v 1.25 2018/02/26 13:43:51 mpi Exp $ */
/* $NetBSD: vfs_lockf.c,v 1.7 1996/02/04 02:18:21 christos Exp $ */
/*
uip = uid_find(uid);
if (uid && allowfail && uip->ui_lockcnt >
- (allowfail == 1 ? maxlocksperuid : (maxlocksperuid * 2)))
+ (allowfail == 1 ? maxlocksperuid : (maxlocksperuid * 2))) {
+ uid_release(uip);
return (NULL);
+ }
uip->ui_lockcnt++;
+ uid_release(uip);
lock = pool_get(&lockfpool, PR_WAITOK);
lock->lf_uid = uid;
return (lock);
uip = uid_find(lock->lf_uid);
uip->ui_lockcnt--;
+ uid_release(uip);
pool_put(&lockfpool, lock);
}
-/* $OpenBSD: proc.h,v 1.246 2018/02/20 12:38:58 mpi Exp $ */
+/* $OpenBSD: proc.h,v 1.247 2018/02/26 13:43:51 mpi Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
};
struct uidinfo *uid_find(uid_t);
+void uid_release(struct uidinfo *);
/*
* We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,