Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Apr 2003 18:36:15 -0800
From:      Kris Kennaway <kris@obsecurity.org>
To:        Glenn Johnson <gjohnson@srrc.ars.usda.gov>, Julian Elischer <julian@elischer.org>, current@freebsd.org
Subject:   Re: kp_proc and kp_eproc
Message-ID:  <20030405023615.GA27656@rot13.obsecurity.org>
In-Reply-To: <20030405000712.GA9839@node1.cluster.srrc.usda.gov>
References:  <20030404234917.GA98049@node1.cluster.srrc.usda.gov> <Pine.BSF.4.21.0304041552270.35903-100000@InterJet.elischer.org> <20030405000712.GA9839@node1.cluster.srrc.usda.gov>

next in thread | previous in thread | raw e-mail | index | archive | help

--2oS5YaxWCcQjTEyO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Apr 04, 2003 at 06:07:12PM -0600, Glenn Johnson wrote:
> On Fri, Apr 04, 2003 at 03:54:05PM -0800, Julian Elischer wrote:
>=20
> > yes..
> >
> > The entire process structure and it's surrounding enviroment has been=
=20
> > through a blender.                                                   =
=20
> >
> > What do you wnat to do?
>=20
> I would like to learn what I need to do to get the software to compile
> on FreeBSD-5.  I guess the question is, what information do I need to
> provide?  The software in question is OpenPBS (http://www.openpbs.org),
> so it nothing proprietary.  There were a whole bunch of dependency
> problems that I worked through manually and finally got to the point
> of the kp_proc failure.  Here is a snippet of code that produces the
> failure:

Here are untested patches I made for this a while ago.  There's also a
port PR somewhere.

--- src/resmom/freebsd/mom_mach.c.orig	Tue Dec  4 16:38:48 2001
+++ src/resmom/freebsd/mom_mach.c	Wed Jan 15 21:04:15 2003
@@ -368,11 +368,21 @@
 			continue;
=20
 		nps++;
+#if __FreeBSD_version < 500000
 		cputime +=3D tvk(pp->kp_proc.p_rtime);
-
-		if (pp->kp_proc.p_ru =3D=3D NULL) {
+#else
+		cputime +=3D tvk(pp->ki_runtime);
+#endif
+
+#if __FreeBSD_version < 500000
+		if (pp->kp_proc.p_ru =3D=3D NULL)
+#else
+		if (&pp->ki_rusage =3D=3D NULL)
+#endif
+		  {
 			struct	pstats	ps;
=20
+#if __FreeBSD_version < 500000
 			DBPRT(("%s: p_stats 0x%lx\n", id,
 				(u_long)pp->kp_proc.p_stats))
 			if (pp->kp_proc.p_stats =3D=3D NULL)
@@ -387,10 +397,27 @@
 				tv(ps.p_ru.ru_stime) +
 				tv(ps.p_cru.ru_utime) +
 				tv(ps.p_cru.ru_stime);
+#else
+			DBPRT(("%s: p_stats 0x%lx\n", id,
+				(u_long)pp->ki_user->u_stats))
+			if (&pp->ki_addr->u_stats =3D=3D NULL)
+				continue;
+
+			if (kvm_read(kd, (u_long)&pp->ki_addr->u_stats, &ps,
+					sizeof(ps)) !=3D sizeof(ps)) {
+				log_err(errno, id, "kvm_read(u_stats)");
+				continue;
+			}
+			cputime +=3D tv(ps.p_ru.ru_utime) +
+				tv(ps.p_ru.ru_stime) +
+				tv(ps.p_cru.ru_utime) +
+				tv(ps.p_cru.ru_stime);
+#endif
 		}
 		else {
 			struct	rusage	ru;
=20
+#if __FreeBSD_version < 500000
 			DBPRT(("%s: p_ru 0x%lx\n", id,
 				(u_long)pp->kp_proc.p_ru))
 			if (kvm_read(kd, (u_long)pp->kp_proc.p_ru, &ru,
@@ -402,6 +429,19 @@
 		}
 		DBPRT(("%s: ses %d pid %d cputime %d\n", id,
 				sess_tbl[i], pp->kp_proc.p_pid, cputime))
+#else
+			DBPRT(("%s: p_ru 0x%lx\n", id,
+				(u_long)pp->ki_rusage))
+			if (kvm_read(kd, (u_long)&pp->ki_rusage, &ru,
+					sizeof(ru)) !=3D sizeof(ru)) {
+				log_err(errno, id, "kvm_read(session)");
+				continue;
+			}
+			cputime +=3D tv(ru.ru_utime) + tv(ru.ru_stime);
+		}
+		DBPRT(("%s: ses %d pid %d cputime %d\n", id,
+				sess_tbl[i], pp->ki_pid, cputime))
+#endif
 	}
=20
 	if (nps =3D=3D 0)
@@ -429,12 +469,19 @@
=20
 		if (!injob(pjob, sess_tbl[i]))
 			continue;
-
+#if __FreeBSD_version < 500000
 		memsize +=3D ctob(pp->kp_eproc.e_vm.vm_tsize +
 			pp->kp_eproc.e_vm.vm_dsize +
 			pp->kp_eproc.e_vm.vm_ssize);
 		DBPRT(("%s: ses %d pid=3D%d totmem=3D%lu\n", id,
 		       sess_tbl[i], pp->kp_proc.p_pid, memsize))
+#else
+		memsize +=3D ctob(pp->ki_tsize +
+			pp->ki_dsize +
+			pp->ki_ssize);
+		DBPRT(("%s: ses %d pid=3D%d totmem=3D%lu\n", id,
+		       sess_tbl[i], pp->ki_pid, memsize))
+#endif
 	}
=20
 	return (memsize);
@@ -457,10 +504,17 @@
 		if (!injob(pjob, sess_tbl[i]))
 			continue;
=20
+#if __FreeBSD_version < 500000
 		memsize +=3D ctob(pp->kp_eproc.e_vm.vm_rssize);
 		DBPRT(("%s: pid=3D%d ses=3D%d mem=3D%d totmem=3D%d\n", id,
 			pp->kp_proc.p_pid, sess_tbl[i],
 			pp->kp_eproc.e_vm.vm_rssize, memsize))
+#else
+		memsize +=3D ctob(pp->ki_rssize);
+		DBPRT(("%s: pid=3D%d ses=3D%d mem=3D%d totmem=3D%d\n", id,
+			pp->ki_pid, sess_tbl[i],
+			pp->ki_rssize, memsize))
+#endif
 	}
=20
 	return (memsize);
@@ -481,10 +535,18 @@
 		if (!injob(pjob, sess_tbl[i]))
 			continue;
=20
+#if __FreeBSD_version < 500000
 		if (ctob(pp->kp_eproc.e_vm.vm_tsize +
 				pp->kp_eproc.e_vm.vm_dsize +
 				pp->kp_eproc.e_vm.vm_ssize) > limit)
 			return (TRUE);
+#else
+		if (ctob(pp->ki_tsize +
+				pp->ki_dsize +
+				pp->ki_ssize) > limit)
+			return (TRUE);
+#endif
+
 	}
=20
 	return (FALSE);
@@ -722,7 +784,12 @@
     struct	kinfo_proc	*a;
     struct	kinfo_proc	*b;
 {
+#if __FreeBSD_version < 500000
 	return((int)a->kp_eproc.e_paddr - (int)b->kp_eproc.e_paddr);
+#else
+	return((int)a->ki_paddr - (int)b->ki_paddr);
+#endif
+
 }
=20
 int
@@ -730,7 +797,12 @@
     struct	session		*key;
     struct	kinfo_proc	*member;
 {
+
+#if __FreeBSD_version < 500000
 	return((int)key->s_leader - (int)member->kp_eproc.e_paddr);
+#else
+	return((int)key->s_leader - (int)member->ki_paddr);
+#endif
 }
=20
 /*
@@ -775,13 +847,20 @@
 	qsort(proc_tbl, nproc, sizeof(struct kinfo_proc), qs_cmp);
=20
 	for (i=3D0, kp=3Dproc_tbl; i<nproc; i++, kp++) {
+#if __FreeBSD_version < 500000
 		if (kvm_read(kd, (u_long)kp->kp_eproc.e_sess, &ss, sizeof(ss))
-				!=3D sizeof(ss)) {
+				!=3D sizeof(ss))
+#else
+		if (kvm_read(kd, (u_long)kp->ki_paddr->p_pgrp->pg_session, &ss, sizeof(s=
s))
+				!=3D sizeof(ss))
+#endif
+		  {
 			sprintf(log_buffer,
 				"kvm_read: %s", kvm_geterr(kd));
 			log_err(errno, id, log_buffer);
 			return (PBSE_SYSTEM);
 		}
+#if __FreeBSD_version < 500000
 		if (ss.s_leader =3D=3D kp->kp_eproc.e_paddr ||
 				ss.s_leader =3D=3D NULL) {
 			sid =3D kp->kp_proc.p_pid;
@@ -791,6 +870,17 @@
 				sizeof(struct kinfo_proc), bs_cmp);
 			sid =3D leader ? leader->kp_proc.p_pid : 0;
 		}
+#else
+		if (ss.s_leader =3D=3D kp->ki_paddr ||
+				ss.s_leader =3D=3D NULL) {
+			sid =3D kp->ki_pid;
+		}
+		else {
+			leader =3D bsearch(&ss, proc_tbl, nproc,
+				sizeof(struct kinfo_proc), bs_cmp);
+			sid =3D leader ? leader->ki_pid : 0;
+		}
+#endif
 		sess_tbl[i] =3D sid;
 	}
=20
@@ -995,9 +1085,16 @@
 		if (sesid !=3D sess_tbl[i])
 			continue;
=20
+#if __FreeBSD_version < 500000
 		DBPRT(("%s: send signal %d to pid %d\n", id,
 				sig, pp->kp_proc.p_pid))
 		(void)kill(pp->kp_proc.p_pid, sig);
+#else
+		DBPRT(("%s: send signal %d to pid %d\n", id,
+				sig, pp->ki_pid))
+		(void)kill(pp->ki_pid, sig);
+
+#endif
 		++ct;
 	}
 	return ct;
@@ -1102,8 +1199,13 @@
 		if (jobid !=3D sess_tbl[i])
 			continue;
=20
+#if __FreeBSD_version < 500000
 		cputime +=3D tvk(pp->kp_proc.p_rtime);
+#else
+
+#endif
=20
+#if __FreeBSD_version < 500000
 		if (pp->kp_proc.p_ru =3D=3D NULL) {
 			struct	pstats	ps;
=20
@@ -1132,6 +1234,36 @@
 		}
 		DBPRT(("%s: ses %d pid %d cputime %d\n", id,
 				jobid, pp->kp_proc.p_pid, cputime))
+#else
+		if (&pp->ki_rusage =3D=3D NULL) {
+			struct	pstats	ps;
+
+			if (&pp->ki_addr->u_stats =3D=3D NULL)
+				continue;
+
+			if (kvm_read(kd, (u_long)&pp->ki_addr->u_stats, &ps,
+					sizeof(ps)) !=3D sizeof(ps)) {
+				log_err(errno, id, "kvm_read(u_stats)");
+				continue;
+			}
+			cputime +=3D tv(ps.p_ru.ru_utime) +
+				tv(ps.p_ru.ru_stime) +
+				tv(ps.p_cru.ru_utime) +
+				tv(ps.p_cru.ru_stime);
+		}
+		else {
+			struct	rusage	ru;
+
+			if (kvm_read(kd, (u_long)pp->ki_paddr->p_ru, &ru,
+					sizeof(ru)) !=3D sizeof(ru)) {
+				log_err(errno, id, "kvm_read(session)");
+				continue;
+			}
+			cputime +=3D tv(ru.ru_utime) + tv(ru.ru_stime);
+		}
+		DBPRT(("%s: ses %d pid %d cputime %d\n", id,
+				jobid, pp->ki_pid, cputime))
+#endif
=20
 	}
=20
@@ -1150,6 +1282,7 @@
 	for (i=3D0; i<nproc; i++) {
 		struct kinfo_proc	*pp =3D &proc_tbl[i];
=20
+#if __FreeBSD_version < 500000
 		if (pid !=3D pp->kp_proc.p_pid)
 			continue;
=20
@@ -1180,9 +1313,41 @@
 				break;
 			}
 			cputime +=3D tv(ru.ru_utime) + tv(ru.ru_stime);
-		}
 		DBPRT(("%s: pid %d cputime %d\n", id, pid, cputime))
+#else
+		if (pid !=3D pp->ki_pid)
+			continue;
+
+		cputime =3D tvk(pp->ki_runtime);
+
+		if (&pp->ki_rusage =3D=3D NULL) {
+			struct	pstats	ps;
+
+			if (&pp->ki_addr->u_stats =3D=3D NULL)
+				break;
=20
+			if (kvm_read(kd, (u_long)&pp->ki_addr->u_stats, &ps,
+					sizeof(ps)) !=3D sizeof(ps)) {
+				log_err(errno, id, "kvm_read(u_stats)");
+				break;
+			}
+			cputime +=3D tv(ps.p_ru.ru_utime) +
+				tv(ps.p_ru.ru_stime) +
+				tv(ps.p_cru.ru_utime) +
+				tv(ps.p_cru.ru_stime);
+		}
+		else {
+			struct	rusage	ru;
+
+			if (kvm_read(kd, (u_long)&pp->ki_rusage, &ru,
+					sizeof(ru)) !=3D sizeof(ru)) {
+				log_err(errno, id, "kvm_read(session)");
+				break;
+			}
+			cputime +=3D tv(ru.ru_utime) + tv(ru.ru_stime);
+		}
+#endif
+		DBPRT(("%s: pid %d cputime %d\n", id, pid, cputime))
 		sprintf(ret_string, "%.2f", (double)cputime * cputfactor);
 		return ret_string;
 	}
@@ -1245,9 +1410,16 @@
 			continue;
=20
 		found =3D 1;
+
+#if __FreeBSD_version < 500000
 		addmem =3D pp->kp_eproc.e_vm.vm_tsize +
 				pp->kp_eproc.e_vm.vm_dsize +
 				pp->kp_eproc.e_vm.vm_ssize;
+#else
+		addmem =3D pp->ki_tsize +
+				pp->ki_dsize +
+				pp->ki_ssize;
+#endif
 		memsize +=3D addmem;
 	}
 	if (found) {
@@ -1273,12 +1445,24 @@
 	for (i=3D0; i<nproc; i++) {
 		struct kinfo_proc	*pp =3D &proc_tbl[i];
=20
+#if __FreeBSD_version < 500000
 		if (pid !=3D pp->kp_proc.p_pid)
 			continue;
+#else
+		if (pid !=3D pp->ki_pid)
+			continue;
+#endif
=20
+
+#if __FreeBSD_version < 500000
 		memsize =3D pp->kp_eproc.e_vm.vm_tsize +
 				pp->kp_eproc.e_vm.vm_dsize +
 				pp->kp_eproc.e_vm.vm_ssize;
+#else
+		memsize =3D pp->ki_tsize +
+				pp->ki_dsize +
+				pp->ki_ssize;
+#endif
 		sprintf(ret_string, "%ukb", ctob(memsize) >> 10); /* KB */
 		return ret_string;
 	}
@@ -1342,7 +1526,11 @@
 			continue;
=20
 		found =3D 1;
+#if __FreeBSD_version < 500000
 		resisize +=3D pp->kp_eproc.e_vm.vm_rssize;
+#else
+		resisize +=3D pp->ki_rssize;
+#endif
 	}
 	if (found) {
 		sprintf(ret_string, "%ukb", ctob(resisize) >> 10); /* KB */
@@ -1369,10 +1557,19 @@
 	for (i=3D0; i<nproc; i++) {
 		struct kinfo_proc	*pp =3D &proc_tbl[i];
=20
+#if __FreeBSD_version < 500000
 		if (pid !=3D pp->kp_proc.p_pid)
 			continue;
+#else
+		if (pid !=3D pp->ki_pid)
+			continue;
+#endif
=20
+#if __FreeBSD_version < 500000
 		resisize =3D pp->kp_eproc.e_vm.vm_rssize;
+#else
+		resisize =3D pp->ki_rssize;
+#endif
 		sprintf(ret_string, "%ukb", ctob(resisize) >> 10); /* KB */
 		return ret_string;
 	}
@@ -1446,12 +1643,22 @@
 	for (i=3D0; i<nproc; i++) {
 		struct kinfo_proc	*pp =3D &proc_tbl[i];
=20
+#if __FreeBSD_version < 500000
 		if (pp->kp_eproc.e_pcred.p_ruid =3D=3D 0)
 			continue;
+#else
+		if (pp->ki_ruid =3D=3D 0)
+			continue;
+#endif
=20
 		jobid =3D sess_tbl[i];
+#if __FreeBSD_version < 500000
 		DBPRT(("%s: pid %d sid %u\n",
 		       id, (int)pp->kp_proc.p_pid, jobid))
+#else
+		DBPRT(("%s: pid %d sid %u\n",
+		       id, (int)pp->ki_pid, jobid))
+#endif
 		for (j=3D0; j<njids; j++) {
 			if (jids[j] =3D=3D jobid)
 				break;
@@ -1531,13 +1738,22 @@
 	for (i=3D0; i<nproc; i++) {
 		struct kinfo_proc	*pp =3D &proc_tbl[i];
=20
+#if __FreeBSD_version < 500000
 		DBPRT(("%s[%d]: pid %d sid %u\n",
 		       id, num_pids, pp->kp_proc.p_pid, sess_tbl[i]))
+#else
+		DBPRT(("%s[%d]: pid %d sid %u\n",
+		       id, num_pids, pp->ki_pid, sess_tbl[i]))
+#endif
 		if (jobid !=3D sess_tbl[i])
 			continue;
=20
 		checkret(&fmt, 100);
+#if __FreeBSD_version < 500000
 		sprintf(fmt, " %d", pp->kp_proc.p_pid);
+#else
+		sprintf(fmt, " %d", pp->ki_pid);
+#endif
 		fmt +=3D strlen(fmt);
 		num_pids++;
 	}
@@ -1575,11 +1791,20 @@
 	for (i=3D0; i<nproc; i++) {
 		struct kinfo_proc	*pp =3D &proc_tbl[i];
=20
+#if __FreeBSD_version < 500000
 		if ((uid =3D pp->kp_eproc.e_pcred.p_ruid) =3D=3D 0)
 			continue;
=20
 		DBPRT(("%s: pid %d uid %u\n",
 		       id, (int)pp->kp_proc.p_pid, uid))
+#else
+		if ((uid =3D pp->ki_ruid) =3D=3D 0)
+			continue;
+
+		DBPRT(("%s: pid %d uid %u\n",
+		       id, (int)pp->ki_pid, uid))
+#endif
+
 		for (j=3D0; j<nuids; j++) {
 			if (uids[j] =3D=3D uid)
 				break;
@@ -1842,10 +2067,16 @@
 				continue;
 		}
 		else {
+#if __FreeBSD_version < 500000
 			if (value !=3D pp->kp_proc.p_pid)
 				continue;
+#else
+			if (value !=3D pp->ki_pid)
+				continue;
+#endif
 		}
=20
+#if __FreeBSD_version < 500000
 		if (pp->kp_proc.p_stats =3D=3D NULL) {
 			rm_errno =3D RM_ERR_SYSTEM;
 			return NULL;
@@ -1857,6 +2088,19 @@
 			rm_errno =3D RM_ERR_SYSTEM;
 			return NULL;
 		}
+#else
+		if (&pp->ki_addr->u_stats =3D=3D NULL) {
+			rm_errno =3D RM_ERR_SYSTEM;
+			return NULL;
+		}
+
+		if (kvm_read(kd, (u_long)&pp->ki_addr->u_stats, &ps,
+				sizeof(ps)) !=3D sizeof(ps)) {
+			log_err(errno, id, "kvm_read(u_stats)");
+			rm_errno =3D RM_ERR_SYSTEM;
+			return NULL;
+		}
+#endif
 		found =3D 1;
 		start =3D MIN(start, ps.p_start.tv_sec);
 	}


--2oS5YaxWCcQjTEyO
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (FreeBSD)

iD8DBQE+jkEeWry0BWjoQKURAoeWAJ4vifXFFkEWUy0jC2E65QngbiZqoQCfX3o2
xv/+jOes37HXHJ6jjW6eKLA=
=wDku
-----END PGP SIGNATURE-----

--2oS5YaxWCcQjTEyO--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030405023615.GA27656>