Index: kern_lwp.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_lwp.c,v retrieving revision 1.174 diff -u -p -u -r1.174 kern_lwp.c --- kern_lwp.c 16 Dec 2012 22:21:03 -0000 1.174 +++ kern_lwp.c 11 Feb 2013 20:54:23 -0000 @@ -781,6 +781,12 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_ */ if (p2->p_nlwps != 0 && p2 != &proc0) { uid_t uid = kauth_cred_getuid(l1->l_cred); + if (strncmp(p2->p_comm, "hald", 4) == 0) { + struct uidinfo *uip = uid_find(uid); + printf("%s,%d: %s[%d]: [uid=%d] (%lu/%d)\n", __FILE__, + __LINE__, p2->p_comm, (int)p2->p_pid, (int)uid, + uip->ui_lwpcnt, 1); + } int count = chglwpcnt(uid, 1); if (__predict_false(count > p2->p_rlimit[RLIMIT_NTHR].rlim_cur)) { @@ -789,6 +795,13 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_ KAUTH_ARG(KAUTH_REQ_PROCESS_RLIMIT_BYPASS), &p2->p_rlimit[RLIMIT_NTHR], KAUTH_ARG(RLIMIT_NTHR)) != 0) { + if (strncmp(p2->p_comm, "hald", 4) == 0) { + struct uidinfo *uip = uid_find(uid); + printf("%s,%d: %s[%d]: [uid=%d]" + " (%lu/%d)\n", __FILE__, __LINE__, + p2->p_comm, (int)p2->p_pid, + (int)uid, uip->ui_lwpcnt, -1); + } (void)chglwpcnt(uid, -1); return EAGAIN; } @@ -1174,8 +1187,16 @@ lwp_free(struct lwp *l, bool recycle, bo KASSERT(l != curlwp); KASSERT(last || mutex_owned(p->p_lock)); - if (p != &proc0 && p->p_nlwps != 1) + if (p != &proc0 && p->p_nlwps != 1) { + uid_t uid = kauth_cred_getuid(l->l_cred); + if (strncmp(p->p_comm, "hald", 4) == 0) { + struct uidinfo *uip = uid_find(uid); + printf("%s,%d: %s[%d]: [uid=%d] (%lu/%d)\n", __FILE__, + __LINE__, p->p_comm, (int)p->p_pid, (int)uid, + uip->ui_lwpcnt, -1); + } (void)chglwpcnt(kauth_cred_getuid(l->l_cred), -1); + } /* * If this was not the last LWP in the process, then adjust * counters and unlock. Index: kern_prot.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_prot.c,v retrieving revision 1.116 diff -u -p -u -r1.116 kern_prot.c --- kern_prot.c 9 Jun 2012 02:55:32 -0000 1.116 +++ kern_prot.c 11 Feb 2013 20:54:23 -0000 @@ -299,6 +299,7 @@ do_setresuid(struct lwp *l, uid_t r, uid { struct proc *p = l->l_proc; kauth_cred_t cred, ncred; + uid_t uid; ncred = kauth_cred_alloc(); @@ -342,14 +343,25 @@ do_setresuid(struct lwp *l, uid_t r, uid kauth_cred_clone(cred, ncred); - if (r != -1 && r != kauth_cred_getuid(ncred)) { + uid = kauth_cred_getuid(ncred); + if (r != -1 && r != uid) { /* Update count of processes for this user */ - (void)chgproccnt(kauth_cred_getuid(ncred), -1); + (void)chgproccnt(uid, -1); (void)chgproccnt(r, 1); /* The first lwp of a process is not counted */ int nlwps = p->p_nlwps - 1; - (void)chglwpcnt(kauth_cred_getuid(ncred), -nlwps); + if (strncmp(p->p_comm, "hald", 4) == 0) { + struct uidinfo *uip = uid_find(uid); + printf("%s,%d: %s[%d]: [uid=%d] (%lu/%d)\n", __FILE__, + __LINE__, p->p_comm, (int)p->p_pid, (int)uid, + uip->ui_lwpcnt, -nlwps); + uip = uid_find(r); + printf("%s,%d: %s[%d]: [uid=%d] (%lu/%d)\n", __FILE__, + __LINE__, p->p_comm, (int)p->p_pid, (int)r, + uip->ui_lwpcnt, nlwps); + } + (void)chglwpcnt(uid, -nlwps); (void)chglwpcnt(r, nlwps); kauth_cred_setuid(ncred, r); @@ -362,6 +374,19 @@ do_setresuid(struct lwp *l, uid_t r, uid /* Broadcast our credentials to the process and other LWPs. */ proc_crmod_leave(ncred, cred, true); + if (strncmp(p->p_comm, "hald", 4) == 0) { + uid = kauth_cred_getuid(p->p_cred); + struct uidinfo *uip = uid_find(uid); + printf("%s,%d: %s[%d]: [uid=%d] (%lu/%d)\n", __FILE__, + __LINE__, p->p_comm, (int)p->p_pid, (int)uid, + uip->ui_lwpcnt, 0); + uid = kauth_cred_getuid(l->l_cred); + uip = uid_find(uid); + printf("%s,%d: %s[%d]: [uid=%d] (%lu/%d)\n", __FILE__, + __LINE__, p->p_comm, (int)p->p_pid, (int)uid, + uip->ui_lwpcnt, 0); + } + return 0; } Index: kern_uidinfo.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_uidinfo.c,v retrieving revision 1.7 diff -u -p -u -r1.7 kern_uidinfo.c --- kern_uidinfo.c 9 Jun 2012 02:55:32 -0000 1.7 +++ kern_uidinfo.c 11 Feb 2013 20:54:23 -0000 @@ -214,7 +214,7 @@ chglwpcnt(uid_t uid, int diff) uip = uid_find(uid); lwpcnt = atomic_add_long_nv(&uip->ui_lwpcnt, diff); - KASSERT(lwpcnt >= 0); +// KASSERT(lwpcnt >= 0); return lwpcnt; }