summaryrefslogtreecommitdiffstats
path: root/osdep-openbsd.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-12-26 23:48:37 +0000
committerTiago Cunha <tcunha@gmx.com>2009-12-26 23:48:37 +0000
commit3cc7f2e191115b815b7486a40919611032d1187c (patch)
tree3e18f64bb08473654fc971d84c1202850ff4fdb4 /osdep-openbsd.c
parentf81b3ddf94c9f593bc37cd79528fcca42697ce1b (diff)
Sync OpenBSD patchset 592:
Use sysctl() KERN_PROC2 instead of KERN_PROC, as the latter's ABI is sensitive to changes in struct proc. fixes for warnings and ok nicm@
Diffstat (limited to 'osdep-openbsd.c')
-rw-r--r--osdep-openbsd.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/osdep-openbsd.c b/osdep-openbsd.c
index 13f0a1c8..1d2e6e45 100644
--- a/osdep-openbsd.c
+++ b/osdep-openbsd.c
@@ -1,4 +1,4 @@
-/* $Id: osdep-openbsd.c,v 1.19 2009-08-09 17:57:39 tcunha Exp $ */
+/* $Id: osdep-openbsd.c,v 1.20 2009-12-26 23:48:37 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,14 +34,12 @@
#define is_stopped(p) \
((p)->p_stat == SSTOP || (p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
-struct proc *cmp_procs(struct proc *, struct proc *);
+struct kinfo_proc2 *cmp_procs(struct kinfo_proc2 *, struct kinfo_proc2 *);
char *osdep_get_name(int, char *);
-struct proc *
-cmp_procs(struct proc *p1, struct proc *p2)
+struct kinfo_proc2 *
+cmp_procs(struct kinfo_proc2 *p1, struct kinfo_proc2 *p2)
{
- void *ptr1, *ptr2;
-
if (is_runnable(p1) && !is_runnable(p2))
return (p1);
if (!is_runnable(p1) && is_runnable(p2))
@@ -67,13 +65,6 @@ cmp_procs(struct proc *p1, struct proc *p2)
if (!(p1->p_flag & P_SINTR) && (p2->p_flag & P_SINTR))
return (p2);
- ptr1 = LIST_FIRST(&p1->p_children);
- ptr2 = LIST_FIRST(&p2->p_children);
- if (ptr1 == NULL && ptr2 != NULL)
- return (p1);
- if (ptr1 != NULL && ptr2 == NULL)
- return (p2);
-
if (strcmp(p1->p_comm, p2->p_comm) < 0)
return (p1);
if (strcmp(p1->p_comm, p2->p_comm) > 0)
@@ -87,11 +78,11 @@ cmp_procs(struct proc *p1, struct proc *p2)
char *
osdep_get_name(int fd, char *tty)
{
- int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 };
+ int mib[6] = { CTL_KERN, KERN_PROC2, KERN_PROC_PGRP, 0,
+ sizeof(struct kinfo_proc2), 0 };
struct stat sb;
size_t len;
- struct kinfo_proc *buf, *newbuf;
- struct proc *bestp;
+ struct kinfo_proc2 *buf, *newbuf, *bestp;
u_int i;
char *name;
@@ -111,6 +102,7 @@ retry:
goto error;
buf = newbuf;
+ mib[5] = (int)(len / sizeof(struct kinfo_proc2));
if (sysctl(mib, nitems(mib), buf, &len, NULL, 0) == -1) {
if (errno == ENOMEM)
goto retry;
@@ -118,13 +110,13 @@ retry:
}
bestp = NULL;
- for (i = 0; i < len / sizeof (struct kinfo_proc); i++) {
- if (buf[i].kp_eproc.e_tdev != sb.st_rdev)
+ for (i = 0; i < len / sizeof (struct kinfo_proc2); i++) {
+ if ((dev_t)buf[i].p_tdev != sb.st_rdev)
continue;
if (bestp == NULL)
- bestp = &buf[i].kp_proc;
+ bestp = &buf[i];
else
- bestp = cmp_procs(&buf[i].kp_proc, bestp);
+ bestp = cmp_procs(&buf[i], bestp);
}
name = NULL;