Implements procwd and procopenfiles using a wrapper around lsof(8)
(from FreeBSD sysdeps directory). Merge proctime.c patch from pkgsrc. Several other cleanings.
This commit is contained in:
parent
6671a84614
commit
40fdf8a7c1
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.44 2010/04/18 09:49:22 ajacoutot Exp $
|
||||
# $OpenBSD: Makefile,v 1.45 2010/04/18 12:32:09 ajacoutot Exp $
|
||||
|
||||
COMMENT= portable library for obtaining system information
|
||||
|
||||
@ -40,5 +40,9 @@ CPPFLAGS+= -DDEBUG \
|
||||
|
||||
post-extract:
|
||||
cp ${FILESDIR}/procaffinity.c ${WRKSRC}/sysdeps/bsd/
|
||||
cp ${WRKSRC}/sysdeps/{freebsd,bsd}/glibtop_private.h
|
||||
cp ${WRKSRC}/sysdeps/{freebsd,bsd}/procwd.c
|
||||
cp ${WRKSRC}/sysdeps/{freebsd,bsd}/glibtop_private.c
|
||||
cp ${WRKSRC}/sysdeps/{freebsd,bsd}/procopenfiles.c
|
||||
|
||||
.include <bsd.port.mk>
|
||||
|
@ -1,61 +0,0 @@
|
||||
$OpenBSD: patch-src_daemon_io_c,v 1.4 2010/04/08 15:57:46 ajacoutot Exp $
|
||||
|
||||
From FreeBSD.
|
||||
|
||||
--- src/daemon/io.c.orig Sun Apr 19 19:51:00 2009
|
||||
+++ src/daemon/io.c Fri Apr 2 10:51:08 2010
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
+#include <errno.h>
|
||||
#include "daemon.h"
|
||||
#include <glibtop/error.h>
|
||||
|
||||
@@ -35,9 +36,13 @@ do_output (int s, glibtop_response *resp, off_t offset
|
||||
resp->offset = offset;
|
||||
resp->data_size = data_size;
|
||||
|
||||
+retry1:
|
||||
if (s == 0) {
|
||||
- if (write (1, (const void *) resp, sizeof (glibtop_response)) < 0)
|
||||
+ if (write (1, (const void *) resp, sizeof (glibtop_response)) < 0) {
|
||||
+ if (errno == EINTR)
|
||||
+ goto retry1;
|
||||
glibtop_warn_io ("write");
|
||||
+ }
|
||||
} else {
|
||||
if (send (s, (const void *) resp, sizeof (glibtop_response), 0) < 0)
|
||||
glibtop_warn_io ("send");
|
||||
@@ -48,9 +53,13 @@ do_output (int s, glibtop_response *resp, off_t offset
|
||||
fprintf (stderr, "Writing %d bytes of data.\n", resp->data_size);
|
||||
#endif
|
||||
|
||||
+retry2:
|
||||
if (s == 0) {
|
||||
- if (write (1, data, resp->data_size) < 0)
|
||||
+ if (write (1, data, resp->data_size) < 0) {
|
||||
+ if (errno == EINTR)
|
||||
+ goto retry2;
|
||||
glibtop_warn_io ("write");
|
||||
+ }
|
||||
} else {
|
||||
if (send (s, data, resp->data_size, 0) , 0)
|
||||
glibtop_warn_io ("send");
|
||||
@@ -66,6 +75,7 @@ do_read (int s, void *ptr, size_t total_size)
|
||||
size_t already_read = 0, remaining = total_size;
|
||||
|
||||
while (already_read < total_size) {
|
||||
+retry:
|
||||
if (s)
|
||||
nread = recv (s, ptr, remaining, 0);
|
||||
else
|
||||
@@ -77,6 +87,8 @@ do_read (int s, void *ptr, size_t total_size)
|
||||
}
|
||||
|
||||
if (nread <= 0) {
|
||||
+ if (errno == EINTR)
|
||||
+ goto retry;
|
||||
glibtop_warn_io ("recv");
|
||||
return 0;
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
$OpenBSD: patch-sysdeps_bsd_Makefile_in,v 1.3 2010/04/11 12:38:56 ajacoutot Exp $
|
||||
$OpenBSD: patch-sysdeps_bsd_Makefile_in,v 1.4 2010/04/18 12:32:09 ajacoutot Exp $
|
||||
--- sysdeps/bsd/Makefile.in.orig Tue Mar 30 17:10:14 2010
|
||||
+++ sysdeps/bsd/Makefile.in Sat Apr 10 18:05:08 2010
|
||||
+++ sysdeps/bsd/Makefile.in Sun Apr 18 13:54:34 2010
|
||||
@@ -49,7 +49,8 @@ CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
LTLIBRARIES = $(noinst_LTLIBRARIES)
|
||||
libgtop_sysdeps_2_0_la_LIBADD =
|
||||
-am_libgtop_sysdeps_2_0_la_OBJECTS = nosuid.lo siglist.lo sysinfo.lo
|
||||
+am_libgtop_sysdeps_2_0_la_OBJECTS = nosuid.lo siglist.lo sysinfo.lo \
|
||||
+ procaffinity.lo
|
||||
+ procwd.lo procaffinity.lo glibtop_private.lo
|
||||
libgtop_sysdeps_2_0_la_OBJECTS = $(am_libgtop_sysdeps_2_0_la_OBJECTS)
|
||||
libgtop_sysdeps_2_0_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
@ -16,11 +16,28 @@ $OpenBSD: patch-sysdeps_bsd_Makefile_in,v 1.3 2010/04/11 12:38:56 ajacoutot Exp
|
||||
top_srcdir = @top_srcdir@
|
||||
noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
|
||||
-libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c sysinfo.c
|
||||
+libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c sysinfo.c procaffinity.c
|
||||
+libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c sysinfo.c procwd.c procaffinity.c glibtop_private.c
|
||||
libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
libgtop_sysdeps_suid_2_0_la_LIBADD = $(KVM_LIBS)
|
||||
libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
|
||||
@@ -368,6 +369,7 @@ distclean-compile:
|
||||
@@ -300,7 +301,7 @@ libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c c
|
||||
|
||||
libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h \
|
||||
- glibtop_suid.h
|
||||
+ glibtop_suid.h glibtop_private.h
|
||||
|
||||
libgtopincludedir = $(includedir)/libgtop-2.0
|
||||
all: all-am
|
||||
@@ -360,6 +361,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/close.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpu.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fsusage.Plo@am__quote@
|
||||
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glibtop_private.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loadavg.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msg_limits.Plo@am__quote@
|
||||
@@ -368,6 +370,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nosuid.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ppp.Plo@am__quote@
|
||||
@ -28,3 +45,11 @@ $OpenBSD: patch-sysdeps_bsd_Makefile_in,v 1.3 2010/04/11 12:38:56 ajacoutot Exp
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procargs.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prockernel.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proclist.Plo@am__quote@
|
||||
@@ -379,6 +382,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procstate.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proctime.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procuid.Plo@am__quote@
|
||||
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procwd.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sem_limits.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shm_limits.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/siglist.Plo@am__quote@
|
||||
|
14
devel/libgtop2/patches/patch-sysdeps_bsd_glibtop_private_c
Normal file
14
devel/libgtop2/patches/patch-sysdeps_bsd_glibtop_private_c
Normal file
@ -0,0 +1,14 @@
|
||||
$OpenBSD: patch-sysdeps_bsd_glibtop_private_c,v 1.1 2010/04/18 12:32:09 ajacoutot Exp $
|
||||
--- sysdeps/bsd/glibtop_private.c.orig Sun Apr 18 14:23:23 2010
|
||||
+++ sysdeps/bsd/glibtop_private.c Sun Apr 18 14:23:49 2010
|
||||
@@ -26,8 +26,8 @@ execute_lsof(pid_t pid) {
|
||||
|
||||
if (g_spawn_command_line_sync (command, &output, NULL, &exit_status, NULL)) {
|
||||
if (exit_status != 0) {
|
||||
- g_warning("Could not execute \"%s\" (%i)", command,
|
||||
- exit_status);
|
||||
+ g_warning("Could not execute \"%s\" (%i)\nMake sure lsof(8) is installed sgid kmem.",
|
||||
+ command, exit_status);
|
||||
output = NULL;
|
||||
}
|
||||
}
|
20
devel/libgtop2/patches/patch-sysdeps_bsd_glibtop_private_h
Normal file
20
devel/libgtop2/patches/patch-sysdeps_bsd_glibtop_private_h
Normal file
@ -0,0 +1,20 @@
|
||||
$OpenBSD: patch-sysdeps_bsd_glibtop_private_h,v 1.1 2010/04/18 12:32:09 ajacoutot Exp $
|
||||
--- sysdeps/bsd/glibtop_private.h.orig Sun Apr 18 13:27:38 2010
|
||||
+++ sysdeps/bsd/glibtop_private.h Sun Apr 18 13:28:09 2010
|
||||
@@ -17,8 +17,8 @@
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
-#ifndef __FREEBSD__GLIBTOP_PRIVATE_H__
|
||||
-#define __FREEBSD__GLIBTOP_PRIVATE_H__
|
||||
+#ifndef __OPENBSD__GLIBTOP_PRIVATE_H__
|
||||
+#define __OPENBSD__GLIBTOP_PRIVATE_H__
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
@@ -37,4 +37,4 @@ gboolean safe_readlink(const char *path, char *buf, in
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
-#endif /* __FREEBSD__GLIBTOP_PRIVATE_H__ */
|
||||
+#endif /* __OPENBSD__GLIBTOP_PRIVATE_H__ */
|
@ -1,14 +1,11 @@
|
||||
$OpenBSD: patch-sysdeps_bsd_glibtop_server_h,v 1.3 2009/11/02 20:19:06 jasper Exp $
|
||||
--- sysdeps/bsd/glibtop_server.h.orig Sun Apr 19 01:29:49 2009
|
||||
+++ sysdeps/bsd/glibtop_server.h Wed Oct 28 23:54:49 2009
|
||||
@@ -42,9 +42,11 @@ G_BEGIN_DECLS
|
||||
#define GLIBTOP_SUID_PROC_SEGMENT (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT)
|
||||
#define GLIBTOP_SUID_PROC_ARGS (1 << GLIBTOP_SYSDEPS_PROC_ARGS)
|
||||
#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
|
||||
+#define GLIBTOP_SUID_PROC_WD 0
|
||||
$OpenBSD: patch-sysdeps_bsd_glibtop_server_h,v 1.4 2010/04/18 12:32:09 ajacoutot Exp $
|
||||
--- sysdeps/bsd/glibtop_server.h.orig Sun Apr 19 19:51:00 2009
|
||||
+++ sysdeps/bsd/glibtop_server.h Sun Apr 18 12:07:35 2010
|
||||
@@ -45,6 +45,8 @@ G_BEGIN_DECLS
|
||||
#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
|
||||
#define GLIBTOP_SUID_NETLIST 0
|
||||
#define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP)
|
||||
+#define GLIBTOP_SUID_PROC_WD 0
|
||||
+#define GLIBTOP_SUID_PROC_AFFINITY 0
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -1,6 +1,6 @@
|
||||
$OpenBSD: patch-sysdeps_bsd_procmem_c,v 1.2 2010/04/08 15:57:46 ajacoutot Exp $
|
||||
$OpenBSD: patch-sysdeps_bsd_procmem_c,v 1.3 2010/04/18 12:32:09 ajacoutot Exp $
|
||||
--- sysdeps/bsd/procmem.c.orig Sun Apr 19 19:51:00 2009
|
||||
+++ sysdeps/bsd/procmem.c Fri Apr 2 14:30:09 2010
|
||||
+++ sysdeps/bsd/procmem.c Sun Apr 18 12:10:09 2010
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
@ -42,7 +42,7 @@ $OpenBSD: patch-sysdeps_bsd_procmem_c,v 1.2 2010/04/08 15:57:46 ajacoutot Exp $
|
||||
#else
|
||||
0;
|
||||
#endif
|
||||
@@ -116,10 +116,13 @@ void
|
||||
@@ -116,6 +116,9 @@ void
|
||||
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
@ -52,11 +52,6 @@ $OpenBSD: patch-sysdeps_bsd_procmem_c,v 1.2 2010/04/08 15:57:46 ajacoutot Exp $
|
||||
struct kinfo_proc *pinfo;
|
||||
struct vm_map_entry entry, *first;
|
||||
struct vmspace *vms, vmspace;
|
||||
-#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||
struct vnode vnode;
|
||||
#else
|
||||
struct vm_object object;
|
||||
@@ -127,6 +130,8 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
|
||||
#if (!defined(__FreeBSD__) || (__FreeBSD_version < 500013)) && !defined(__FreeBSD_kernel__)
|
||||
struct plimit plimit;
|
||||
@ -107,43 +102,7 @@ $OpenBSD: patch-sysdeps_bsd_procmem_c,v 1.2 2010/04/08 15:57:46 ajacoutot Exp $
|
||||
if (kvm_read (server->machine.kd,
|
||||
(unsigned long) pinfo [0].PROC_VMSPACE,
|
||||
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
|
||||
@@ -221,7 +244,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
|
||||
continue;
|
||||
#endif
|
||||
#else
|
||||
-#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||
if (UVM_ET_ISSUBMAP (&entry))
|
||||
continue;
|
||||
#else
|
||||
@@ -230,7 +253,8 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
|
||||
#endif
|
||||
#endif
|
||||
|
||||
-#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || \
|
||||
+ defined(__OpenBSD__)
|
||||
if (!entry.object.uvm_obj)
|
||||
continue;
|
||||
|
||||
@@ -257,14 +281,14 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
|
||||
#endif
|
||||
/* If the object is of type vnode, add its size */
|
||||
|
||||
-#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||
#if defined(UVM_VNODE_VALID)
|
||||
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
||||
continue;
|
||||
#endif
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
-#if defined(__NetBSD__) && (__NetBSD_Version__ >= 105250000)
|
||||
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 105250000))
|
||||
/* Reference count must be at least two. */
|
||||
if (vnode.v_usecount <= 1)
|
||||
continue;
|
||||
@@ -287,6 +311,8 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
|
||||
@@ -287,6 +310,8 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_
|
||||
buf->share += object.un_pager.vnp.vnp_size;
|
||||
#endif
|
||||
}
|
||||
|
@ -1,34 +1,184 @@
|
||||
$OpenBSD: patch-sysdeps_bsd_procopenfiles_c,v 1.1 2008/02/09 16:52:25 ajacoutot Exp $
|
||||
--- sysdeps/bsd/procopenfiles.c.orig Sun Dec 30 19:40:10 2007
|
||||
+++ sysdeps/bsd/procopenfiles.c Sun Dec 30 19:42:14 2007
|
||||
@@ -47,5 +47,30 @@ _glibtop_init_proc_open_files_s (glibtop *server)
|
||||
$OpenBSD: patch-sysdeps_bsd_procopenfiles_c,v 1.2 2010/04/18 12:32:09 ajacoutot Exp $
|
||||
--- sysdeps/bsd/procopenfiles.c.orig Sun Apr 18 13:27:52 2010
|
||||
+++ sysdeps/bsd/procopenfiles.c Sun Apr 18 13:36:28 2010
|
||||
@@ -32,7 +32,6 @@
|
||||
#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>
|
||||
@@ -53,63 +52,6 @@ _glibtop_init_proc_open_files_s (glibtop *server)
|
||||
server->sysdeps.proc_open_files = _glibtop_sysdeps_proc_open_files;
|
||||
}
|
||||
|
||||
-#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
|
||||
-static char *
|
||||
-addr_to_string(struct sockaddr_storage *ss)
|
||||
-{
|
||||
- char *buffer = NULL;
|
||||
- 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 = 0;
|
||||
- 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;
|
||||
@@ -256,108 +198,21 @@ 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)
|
||||
{
|
||||
+ memset(buf, 0, sizeof (glibtop_proc_open_files));
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+#include <glibtop/procwd.h>
|
||||
+
|
||||
+static const unsigned long _glibtop_sysdeps_proc_wd =
|
||||
+(1 << GLIBTOP_PROC_WD_EXE) |
|
||||
+(1 << GLIBTOP_PROC_WD_ROOT) |
|
||||
+(1 << GLIBTOP_PROC_WD_NUMBER);
|
||||
+
|
||||
+/* Init function. */
|
||||
+
|
||||
+void
|
||||
+_glibtop_init_proc_wd_s (glibtop *server)
|
||||
+{
|
||||
+ server->sysdeps.proc_wd = _glibtop_sysdeps_proc_wd;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/* XXX Unimplemented on BSD */
|
||||
+char **
|
||||
+glibtop_get_proc_wd_s (glibtop *server, glibtop_proc_wd *buf, pid_t pid)
|
||||
+{
|
||||
+ memset (buf, 0, sizeof (glibtop_proc_wd));
|
||||
return NULL;
|
||||
}
|
||||
-#if __FreeBSD_version > 800018 || (__FreeBSD_version < 800000 && __FreeBSD_version >= 700104)
|
||||
- struct kinfo_file *freep, *kif;
|
||||
- int name[4];
|
||||
- size_t len;
|
||||
- size_t i;
|
||||
-#else
|
||||
char *output;
|
||||
-#endif
|
||||
GArray *entries;
|
||||
|
||||
memset(buf, 0, sizeof (glibtop_proc_open_files));
|
||||
|
||||
-#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;
|
||||
- }
|
||||
-
|
||||
- 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_TYPE_SOCKET) {
|
||||
- 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;
|
||||
-
|
||||
- if (kif->kf_sock_domain == AF_INET)
|
||||
- entry.type = GLIBTOP_FILE_TYPE_INETSOCKET;
|
||||
- else
|
||||
- entry.type = GLIBTOP_FILE_TYPE_INET6SOCKET;
|
||||
- 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;
|
||||
|
123
devel/libgtop2/patches/patch-sysdeps_bsd_proctime_c
Normal file
123
devel/libgtop2/patches/patch-sysdeps_bsd_proctime_c
Normal file
@ -0,0 +1,123 @@
|
||||
$OpenBSD: patch-sysdeps_bsd_proctime_c,v 1.1 2010/04/18 12:32:09 ajacoutot Exp $
|
||||
--- sysdeps/bsd/proctime.c.orig Sun Apr 19 19:51:00 2009
|
||||
+++ sysdeps/bsd/proctime.c Sun Apr 18 12:20:27 2010
|
||||
@@ -40,11 +40,25 @@ static const unsigned long _glibtop_sysdeps_proc_time_
|
||||
|
||||
#define tv2sec(tv) (((guint64) tv.tv_sec * 1000000) + (guint64) tv.tv_usec)
|
||||
|
||||
+#if defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
+static unsigned int clockrate;
|
||||
+static const int mib [] = { CTL_KERN, KERN_CLOCKRATE };
|
||||
+#endif
|
||||
+
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_time_p (glibtop *server)
|
||||
{
|
||||
+#if defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
+ struct clockinfo ci;
|
||||
+ size_t length;
|
||||
+ length = sizeof (ci);
|
||||
+ if (sysctl (mib, 2, &ci, &length, NULL, 0) == 0)
|
||||
+ clockrate = ci.hz;
|
||||
+ if (!clockrate)
|
||||
+ clockrate = 1; /* XXX avoid div by 0 later */
|
||||
+#endif
|
||||
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
|
||||
_glibtop_sysdeps_proc_time_user;
|
||||
}
|
||||
@@ -56,7 +70,7 @@ _glibtop_init_proc_time_p (glibtop *server)
|
||||
* system, and interrupt time usage.
|
||||
*/
|
||||
|
||||
-#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__))
|
||||
+#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__))
|
||||
|
||||
static void
|
||||
calcru(p, up, sp, ip)
|
||||
@@ -114,13 +128,13 @@ void
|
||||
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
- struct kinfo_proc *pinfo;
|
||||
-#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
|
||||
- register struct rusage *rup;
|
||||
+#if defined (__NetBSD__) || defined(__OpenBSD__)
|
||||
+ struct kinfo_proc2 *pinfo;
|
||||
#else
|
||||
+ struct kinfo_proc *pinfo;
|
||||
struct user *u_addr = (struct user *)USRSTACK;
|
||||
-#endif
|
||||
struct pstats pstats;
|
||||
+#endif
|
||||
int count;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
|
||||
@@ -136,7 +150,12 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc
|
||||
#endif
|
||||
|
||||
/* Get the process information */
|
||||
+#if defined (__NetBSD__) || defined(__OpenBSD__)
|
||||
+ pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
|
||||
+ sizeof (*pinfo), &count);
|
||||
+#else
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
+#endif
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return;
|
||||
@@ -146,38 +165,30 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc
|
||||
buf->rtime = pinfo [0].ki_runtime;
|
||||
#elif (defined __FreeBSD__) && (__FreeBSD_version <= 500013)
|
||||
buf->rtime = pinfo [0].kp_proc.p_runtime;
|
||||
+#elif defined (__NetBSD__) || defined(__OpenBSD__)
|
||||
+ buf->rtime = pinfo[0].p_rtime_sec * clockrate
|
||||
+ + pinfo[0].p_rtime_usec * clockrate / 1000000;
|
||||
+ buf->frequency = clockrate;
|
||||
#else
|
||||
buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
|
||||
+ buf->frequency = 1000000;
|
||||
#endif
|
||||
|
||||
- buf->frequency = 1000000;
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
|
||||
-#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
|
||||
- glibtop_suid_enter (server);
|
||||
+#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || defined(__OpenBSD__)
|
||||
|
||||
- if (kvm_read (server->machine.kd,
|
||||
- (unsigned long) pinfo [0].kp_proc.p_stats,
|
||||
- &pstats, sizeof (pstats)) != sizeof (pstats)) {
|
||||
- glibtop_warn_io_r (server, "kvm_read (pstats)");
|
||||
- return;
|
||||
- }
|
||||
+ buf->utime = pinfo[0].p_uutime_sec * 1000000
|
||||
+ + pinfo[0].p_uutime_usec;
|
||||
+ buf->stime = pinfo[0].p_ustime_sec * 1000000
|
||||
+ + pinfo[0].p_ustime_usec;
|
||||
+ buf->cutime = pinfo[0].p_uctime_sec * 1000000
|
||||
+ + pinfo[0].p_uctime_usec; /* XXX is u+s */
|
||||
+ buf->cstime = 0; /* XXX */
|
||||
+ buf->start_time = pinfo[0].p_ustart_sec;
|
||||
|
||||
- glibtop_suid_leave (server);
|
||||
-
|
||||
- rup = &pstats.p_ru;
|
||||
- calcru(&(pinfo [0]).kp_proc,
|
||||
- &rup->ru_utime, &rup->ru_stime, NULL);
|
||||
-
|
||||
- buf->utime = tv2sec (pstats.p_ru.ru_utime);
|
||||
- buf->stime = tv2sec (pstats.p_ru.ru_stime);
|
||||
-
|
||||
- buf->cutime = tv2sec (pstats.p_cru.ru_utime);
|
||||
- buf->cstime = tv2sec (pstats.p_cru.ru_stime);
|
||||
-
|
||||
- buf->start_time = (guint64) pstats.p_start.tv_sec;
|
||||
-
|
||||
buf->flags |= _glibtop_sysdeps_proc_time_user;
|
||||
+
|
||||
#else
|
||||
#if (defined(__FreeBSD__) && (__FreeBSD_version >= 500013)) || defined(__FreeBSD_kernel__)
|
||||
#if (__FreeBSD_version >= 500016) || defined(__FreeBSD_kernel__)
|
93
devel/libgtop2/patches/patch-sysdeps_bsd_procwd_c
Normal file
93
devel/libgtop2/patches/patch-sysdeps_bsd_procwd_c
Normal file
@ -0,0 +1,93 @@
|
||||
$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;
|
||||
}
|
2
devel/libgtop2/pkg/MESSAGE
Normal file
2
devel/libgtop2/pkg/MESSAGE
Normal file
@ -0,0 +1,2 @@
|
||||
LibGTop uses lsof(8) to get open files information. If you want to be
|
||||
able to use this feature, the lsof binary needs to be sgid kmem.
|
Loading…
x
Reference in New Issue
Block a user