diff options
author | marcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059> | 2008-02-10 01:51:21 +0800 |
---|---|---|
committer | marcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059> | 2008-02-10 01:51:21 +0800 |
commit | 1fa879582dddd3f59d20f6460fbec321050a4a0e (patch) | |
tree | 674767eb0de0b82e0d70e4fccb48672b3b8a6205 /devel/libgtop | |
parent | 0af2ca94e3d715ea819ea3170c017f7c31af2dd7 (diff) | |
download | marcuscom-ports-1fa879582dddd3f59d20f6460fbec321050a4a0e.tar marcuscom-ports-1fa879582dddd3f59d20f6460fbec321050a4a0e.tar.gz marcuscom-ports-1fa879582dddd3f59d20f6460fbec321050a4a0e.tar.bz2 marcuscom-ports-1fa879582dddd3f59d20f6460fbec321050a4a0e.tar.lz marcuscom-ports-1fa879582dddd3f59d20f6460fbec321050a4a0e.tar.xz marcuscom-ports-1fa879582dddd3f59d20f6460fbec321050a4a0e.tar.zst marcuscom-ports-1fa879582dddd3f59d20f6460fbec321050a4a0e.zip |
Port to use the new kern.proc.filedesc sysctl in -CURRENT now that it has
cwd and root directory support.
git-svn-id: svn://creme-brulee.marcuscom.com/ports/trunk@10376 df743ca5-7f9a-e211-a948-0013205c9059
Diffstat (limited to 'devel/libgtop')
-rw-r--r-- | devel/libgtop/Makefile | 8 | ||||
-rw-r--r-- | devel/libgtop/files/patch-sysdeps_freebsd_procopenfiles.c | 186 | ||||
-rw-r--r-- | devel/libgtop/files/patch-sysdeps_freebsd_procwd.c | 94 |
3 files changed, 286 insertions, 2 deletions
diff --git a/devel/libgtop/Makefile b/devel/libgtop/Makefile index 01709e484..14b43803f 100644 --- a/devel/libgtop/Makefile +++ b/devel/libgtop/Makefile @@ -3,11 +3,12 @@ # Whom: Joe Marcus Clarke <marcus@FreeBSD.org> # # $FreeBSD$ -# $MCom: ports/devel/libgtop/Makefile,v 1.26 2007/11/03 04:08:15 marcus Exp $ +# $MCom: ports/devel/libgtop/Makefile,v 1.27 2008/01/15 02:37:36 mezz Exp $ # PORTNAME= libgtop PORTVERSION= 2.21.5 +PORTREVISION= 1 CATEGORIES= devel gnome MASTER_SITES= ${MASTER_SITE_GNOME} MASTER_SITE_SUBDIR= sources/${PORTNAME}/${PORTVERSION:C/^([0-9]+\.[0-9]+).*/\1/} @@ -17,7 +18,6 @@ MAINTAINER= gnome@FreeBSD.org COMMENT= GNOME 2 top library LIB_DEPENDS= popt.0:${PORTSDIR}/devel/popt -RUN_DEPENDS= lsof:${PORTSDIR}/sysutils/lsof USE_BZIP2= yes USE_PERL5_BUILD=yes @@ -35,6 +35,10 @@ INFO= libgtop2 .include <bsd.port.pre.mk> +.if ${OSVERSION} < 800019 +RUN_DEPENDS+= lsof:${PORTSDIR}/sysutils/lsof +.endif + .if ${OSVERSION} >= 600000 PKGMESSAGE= ${FILESDIR}/pkg-message .endif diff --git a/devel/libgtop/files/patch-sysdeps_freebsd_procopenfiles.c b/devel/libgtop/files/patch-sysdeps_freebsd_procopenfiles.c new file mode 100644 index 000000000..5565b8a0c --- /dev/null +++ b/devel/libgtop/files/patch-sysdeps_freebsd_procopenfiles.c @@ -0,0 +1,186 @@ +--- sysdeps/freebsd/procopenfiles.c.orig 2008-02-09 02:05:40.000000000 -0500 ++++ sysdeps/freebsd/procopenfiles.c 2008-02-09 12:41:44.000000000 -0500 +@@ -28,6 +28,13 @@ + #include <glibtop/error.h> + #include <glibtop/procopenfiles.h> + #include <sys/types.h> ++#include <sys/socket.h> ++#include <sys/param.h> ++#include <sys/sysctl.h> ++#include <sys/un.h> ++#include <sys/user.h> ++#include <netinet/in.h> ++#include <arpa/inet.h> + #include <string.h> + #include <stdlib.h> + +@@ -46,6 +53,63 @@ _glibtop_init_proc_open_files_s (glibtop + server->sysdeps.proc_open_files = _glibtop_sysdeps_proc_open_files; + } + ++#if __FreeBSD_version > 800018 ++static char * ++addr_to_string(struct sockaddr_storage *ss) ++{ ++ char *buffer; ++ char buffer2[INET6_ADDRSTRLEN]; ++ struct sockaddr_in6 *sin6; ++ struct sockaddr_in *sin; ++ struct sockaddr_un *sun; ++ ++ switch (ss->ss_family) { ++ case AF_LOCAL: ++ sun = (struct sockaddr_un *)ss; ++ if (strlen(sun->sun_path) == 0) ++ buffer = g_strdup("-"); ++ else ++ buffer = g_strdup(sun->sun_path); ++ break; ++ case AF_INET: ++ sin = (struct sockaddr_in *)ss; ++ buffer = g_strdup(inet_ntoa(sin->sin_addr)); ++ break; ++ case AF_INET6: ++ sin6 = (struct sockaddr_in6 *)ss; ++ if (inet_ntop(AF_INET6, &sin6->sin6_addr, buffer2, ++ sizeof(buffer2)) != NULL) ++ buffer = g_strdup(buffer2); ++ else ++ buffer = g_strdup("-"); ++ break; ++ } ++ ++ return buffer; ++} ++ ++static int ++addr_to_port(struct sockaddr_storage *ss) ++{ ++ int port; ++ struct sockaddr_in6 *sin6; ++ struct sockaddr_in *sin; ++ ++ switch (ss->ss_family) { ++ case AF_INET: ++ sin = (struct sockaddr_in *)ss; ++ port = ntohs(sin->sin_port); ++ break; ++ case AF_INET6: ++ sin6 = (struct sockaddr_in6 *)ss; ++ port = ntohs(sin6->sin6_port); ++ break; ++ } ++ ++ return port; ++} ++#else ++ + static GArray * + parse_output(const char *output) { + GArray *entries; +@@ -159,21 +223,105 @@ parse_output(const char *output) { + + return entries; + } ++#endif + + glibtop_open_files_entry * + glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid) + { ++#if __FreeBSD_version > 800018 ++ struct kinfo_file *freep, *kif; ++ int name[4]; ++ size_t len; ++ int i; ++#else + char *output; ++#endif + GArray *entries; + + memset(buf, 0, sizeof (glibtop_proc_open_files)); + ++#if __FreeBSD_version > 800018 ++ 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; ++ } ++ ++ entries = g_array_new(FALSE, FALSE, sizeof(glibtop_open_files_entry)); ++ ++ for (i = 0; i < len / sizeof(*kif); i++, kif++) { ++ glibtop_open_files_entry entry = {0}; ++ ++ if (kif->kf_fd < 0) ++ continue; ++ ++ if (kif->kf_type == KF_VTYPE_VSOCK) { ++ if (kif->kf_sock_domain == AF_LOCAL) { ++ struct sockaddr_un *sun; ++ ++ entry.type = GLIBTOP_FILE_TYPE_LOCALSOCKET; ++ sun = (struct sockaddr_un *)&kif->kf_sa_local; ++ ++ if (sun->sun_path[0]) { ++ char *addrstr; ++ ++ addrstr = addr_to_string(&kif->kf_sa_local); ++ g_strlcpy(entry.info.localsock.name, ++ addrstr, ++ sizeof(entry.info.localsock.name)); ++ g_free(addrstr); ++ } else { ++ char *addrstr; ++ ++ addrstr = addr_to_string(&kif->kf_sa_peer); ++ g_strlcpy(entry.info.localsock.name, ++ addrstr, ++ sizeof(entry.info.localsock.name)); ++ g_free(addrstr); ++ } ++ } else if (kif->kf_sock_domain == AF_INET || ++ kif->kf_sock_domain == AF_INET6) { ++ char *addrstr; ++ ++ entry.type = GLIBTOP_FILE_TYPE_INETSOCKET; ++ addrstr = addr_to_string(&kif->kf_sa_peer); ++ g_strlcpy(entry.info.sock.dest_host, ++ addrstr, ++ sizeof(entry.info.sock.dest_host)); ++ g_free(addrstr); ++ entry.info.sock.dest_port = addr_to_port(&kif->kf_sa_peer); ++ } ++ } else if (kif->kf_type == KF_TYPE_PIPE) { ++ entry.type = GLIBTOP_FILE_TYPE_PIPE; ++ } else if (kif->kf_type == KF_TYPE_VNODE) { ++ entry.type = GLIBTOP_FILE_TYPE_FILE; ++ g_strlcpy(entry.info.file.name, kif->kf_path, ++ sizeof(entry.info.file.name)); ++ } else ++ continue; ++ ++ entry.fd = kif->kf_fd; ++ ++ g_array_append_val(entries, entry); ++ } ++ g_free(freep); ++#else ++ + output = execute_lsof(pid); + if (output == NULL) return NULL; + + entries = parse_output(output); + + g_free(output); ++#endif + + buf->flags = _glibtop_sysdeps_proc_open_files; + buf->number = entries->len; diff --git a/devel/libgtop/files/patch-sysdeps_freebsd_procwd.c b/devel/libgtop/files/patch-sysdeps_freebsd_procwd.c new file mode 100644 index 000000000..08a58359e --- /dev/null +++ b/devel/libgtop/files/patch-sysdeps_freebsd_procwd.c @@ -0,0 +1,94 @@ +--- sysdeps/freebsd/procwd.c.orig 2008-02-09 12:46:32.000000000 -0500 ++++ sysdeps/freebsd/procwd.c 2008-02-09 12:48:24.000000000 -0500 +@@ -24,7 +24,9 @@ + #include <glibtop_private.h> + + #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 = +@@ -38,6 +40,7 @@ _glibtop_init_proc_wd_s(glibtop *server) + server->sysdeps.proc_wd = _glibtop_sysdeps_proc_wd; + } + ++#if __FreeBSD_version < 800019 + static GPtrArray * + parse_output(const char *output, glibtop_proc_wd *buf) + { +@@ -89,12 +92,21 @@ parse_output(const char *output, glibtop + + 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 ++ 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)); + +@@ -102,6 +114,43 @@ glibtop_get_proc_wd_s(glibtop *server, g + if (safe_readlink(path, buf->exe, sizeof(buf->exe))) + buf->flags |= (1 << GLIBTOP_PROC_WD_EXE); + ++#if __FreeBSD_version > 800018 ++ 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; +@@ -116,6 +165,7 @@ glibtop_get_proc_wd_s(glibtop *server, g + + return (char **)g_ptr_array_free(dirs, FALSE); + } ++#endif + + return NULL; + } |