openbsd-ports/devel/libgtop2/patches/patch-sysdeps_bsd_procwd_c
ajacoutot 40fdf8a7c1 Implements procwd and procopenfiles using a wrapper around lsof(8)
(from FreeBSD sysdeps directory).
Merge proctime.c patch from pkgsrc.
Several other cleanings.
2010-04-18 12:32:09 +00:00

94 lines
2.4 KiB
Plaintext

$OpenBSD: patch-sysdeps_bsd_procwd_c,v 1.1 2010/04/18 12:32:09 ajacoutot Exp $
--- sysdeps/bsd/procwd.c.orig Sun Apr 18 13:27:40 2010
+++ sysdeps/bsd/procwd.c Sun Apr 18 13:36:37 2010
@@ -26,7 +26,6 @@
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/param.h>
-#include <sys/user.h>
#include <string.h>
static const unsigned long _glibtop_sysdeps_proc_wd =
@@ -40,7 +39,6 @@ _glibtop_init_proc_wd_s(glibtop *server)
server->sysdeps.proc_wd = _glibtop_sysdeps_proc_wd;
}
-#if (__FreeBSD_version >= 800000 && __FreeBSD_version < 800019) || _FreeBSD_version < 700104
static GPtrArray *
parse_output(const char *output, glibtop_proc_wd *buf)
{
@@ -92,21 +90,12 @@ parse_output(const char *output, glibtop_proc_wd *buf)
return dirs;
}
-#endif
char**
glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd *buf, pid_t pid)
{
char path[MAXPATHLEN];
-#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
- struct kinfo_file *freep, *kif;
- GPtrArray *dirs;
- size_t len;
- int i;
- int name[4];
-#else
char *output;
-#endif
memset (buf, 0, sizeof (glibtop_proc_wd));
@@ -114,43 +103,6 @@ glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd
if (safe_readlink(path, buf->exe, sizeof(buf->exe)))
buf->flags |= (1 << GLIBTOP_PROC_WD_EXE);
-#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
- name[0] = CTL_KERN;
- name[1] = KERN_PROC;
- name[2] = KERN_PROC_FILEDESC;
- name[3] = pid;
-
- if (sysctl(name, 4, NULL, &len, NULL, 0) < 0)
- return NULL;
- freep = kif = g_malloc(len);
- if (sysctl(name, 4, kif, &len, NULL, 0) < 0) {
- g_free(freep);
- return NULL;
- }
-
- dirs = g_ptr_array_sized_new(1);
-
- for (i = 0; i < len / sizeof(*kif); i++, kif++) {
- switch (kif->kf_fd) {
- case KF_FD_TYPE_ROOT:
- g_strlcpy(buf->root, kif->kf_path,
- sizeof(buf->root));
- buf->flags |= (1 << GLIBTOP_PROC_WD_ROOT);
- break;
- case KF_FD_TYPE_CWD:
- g_ptr_array_add(dirs, g_strdup (kif->kf_path));
- break;
- }
- }
- g_free(freep);
-
- buf->number = dirs->len;
- buf->flags |= (1 << GLIBTOP_PROC_WD_NUMBER);
-
- g_ptr_array_add(dirs, NULL);
-
- return (char **)g_ptr_array_free(dirs, FALSE);
-#else
output = execute_lsof(pid);
if (output != NULL) {
GPtrArray *dirs;
@@ -165,7 +117,6 @@ glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd
return (char **)g_ptr_array_free(dirs, FALSE);
}
-#endif
return NULL;
}