diff options
author | marcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059> | 2008-12-21 14:20:19 +0800 |
---|---|---|
committer | marcus <marcus@df743ca5-7f9a-e211-a948-0013205c9059> | 2008-12-21 14:20:19 +0800 |
commit | 66fa9a18058345885c451991dbc711e83de88487 (patch) | |
tree | 63c13021dbc3a14a860884c7bb9bd3c26d756c8f | |
parent | 0438c9a615142a79aceac05a1f179eda9b639dac (diff) | |
download | marcuscom-ports-66fa9a18058345885c451991dbc711e83de88487.tar marcuscom-ports-66fa9a18058345885c451991dbc711e83de88487.tar.gz marcuscom-ports-66fa9a18058345885c451991dbc711e83de88487.tar.bz2 marcuscom-ports-66fa9a18058345885c451991dbc711e83de88487.tar.lz marcuscom-ports-66fa9a18058345885c451991dbc711e83de88487.tar.xz marcuscom-ports-66fa9a18058345885c451991dbc711e83de88487.tar.zst marcuscom-ports-66fa9a18058345885c451991dbc711e83de88487.zip |
Teach the mouse addon to use procstat on recent versions of -CURRENT.
This greatly alleviates the CPU burden caused by exec'ing fstat every
two seconds.
git-svn-id: svn://creme-brulee.marcuscom.com/ports/trunk@11831 df743ca5-7f9a-e211-a948-0013205c9059
-rw-r--r-- | sysutils/hal/Makefile | 8 | ||||
-rw-r--r-- | sysutils/hal/files/patch-hald_freebsd_addons_Makefile.in | 13 | ||||
-rw-r--r-- | sysutils/hal/files/patch-hald_freebsd_addons_addon-mouse.c | 184 |
3 files changed, 161 insertions, 44 deletions
diff --git a/sysutils/hal/Makefile b/sysutils/hal/Makefile index 81c560233..b20c401dc 100644 --- a/sysutils/hal/Makefile +++ b/sysutils/hal/Makefile @@ -3,12 +3,12 @@ # Whom: Joe Marcus Clarke <marcus@FreeBSD.org> # # $FreeBSD$ -# $MCom: ports/sysutils/hal/Makefile,v 1.52 2008/10/27 17:26:32 marcus Exp $ +# $MCom: ports/sysutils/hal/Makefile,v 1.53 2008/12/07 05:58:07 marcus Exp $ # PORTNAME= hal DISTVERSION= 0.5.11 -PORTREVISION= 9 +PORTREVISION= 10 CATEGORIES= sysutils MASTER_SITES= http://hal.freedesktop.org/releases/ @@ -71,10 +71,6 @@ OPTIONS= FIXED_MOUNTPOINTS "use fixed mountpoints" off .include <bsd.port.pre.mk> -.if ${OSVERSION} < 505000 -IGNORE= not supported on FreeBSD prior to 5.5-RELEASE -.endif - .if (${ARCH}=="i386" || ${ARCH}=="amd64" || ${ARCH}=="ia64") RUN_DEPENDS+= dmidecode:${PORTSDIR}/sysutils/dmidecode .endif diff --git a/sysutils/hal/files/patch-hald_freebsd_addons_Makefile.in b/sysutils/hal/files/patch-hald_freebsd_addons_Makefile.in index beb677fa9..f554c0650 100644 --- a/sysutils/hal/files/patch-hald_freebsd_addons_Makefile.in +++ b/sysutils/hal/files/patch-hald_freebsd_addons_Makefile.in @@ -1,5 +1,5 @@ ---- hald/freebsd/addons/Makefile.in.orig 2008-03-27 00:45:50.000000000 -0400 -+++ hald/freebsd/addons/Makefile.in 2008-03-27 00:48:15.000000000 -0400 +--- hald/freebsd/addons/Makefile.in.orig 2008-12-13 12:08:36.000000000 -0500 ++++ hald/freebsd/addons/Makefile.in 2008-12-20 21:16:41.000000000 -0500 @@ -33,7 +33,8 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @@ -39,19 +39,20 @@ ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -@@ -227,6 +239,11 @@ hald_addon_storage_SOURCES = addon-stora +@@ -229,6 +241,12 @@ hald_addon_storage_SOURCES = addon-stora hald_addon_storage_LDADD = \ $(top_builddir)/hald/freebsd/libprobe/libhald_freebsd_probe.la +hald_addon_mouse_sysmouse_SOURCES = addon-mouse.c +hald_addon_mouse_sysmouse_CFLAGS = $(AM_CPPFLAGS) @GLIB_CFLAGS@ +hald_addon_mouse_sysmouse_LDADD = @GLIB_LIBS@ \ ++ -lutil \ + $(top_builddir)/hald/freebsd/libprobe/libhald_freebsd_probe.la + all: all-am .SUFFIXES: -@@ -288,6 +305,9 @@ clean-libexecPROGRAMS: +@@ -290,6 +308,9 @@ clean-libexecPROGRAMS: echo " rm -f $$p $$f"; \ rm -f $$p $$f ; \ done @@ -61,7 +62,7 @@ hald-addon-storage$(EXEEXT): $(hald_addon_storage_OBJECTS) $(hald_addon_storage_DEPENDENCIES) @rm -f hald-addon-storage$(EXEEXT) $(LINK) $(hald_addon_storage_OBJECTS) $(hald_addon_storage_LDADD) $(LIBS) -@@ -299,6 +319,7 @@ distclean-compile: +@@ -301,6 +322,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/addon-storage.Po@am__quote@ @@ -69,7 +70,7 @@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@@ -321,6 +342,20 @@ distclean-compile: +@@ -323,6 +345,20 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< diff --git a/sysutils/hal/files/patch-hald_freebsd_addons_addon-mouse.c b/sysutils/hal/files/patch-hald_freebsd_addons_addon-mouse.c index 9d0d23300..70d8b9af6 100644 --- a/sysutils/hal/files/patch-hald_freebsd_addons_addon-mouse.c +++ b/sysutils/hal/files/patch-hald_freebsd_addons_addon-mouse.c @@ -1,8 +1,8 @@ ---- hald/freebsd/addons/addon-mouse.c.orig 2008-03-31 04:53:42.000000000 -0400 -+++ hald/freebsd/addons/addon-mouse.c 2008-03-31 05:07:19.000000000 -0400 -@@ -0,0 +1,216 @@ +--- hald/freebsd/addons/addon-mouse.c.orig 2008-12-21 01:15:41.000000000 -0500 ++++ hald/freebsd/addons/addon-mouse.c 2008-12-21 01:17:03.000000000 -0500 +@@ -0,0 +1,336 @@ +/*************************************************************************** -+ * CVSID: $Id: patch-hald_freebsd_addons_addon-mouse.c,v 1.1 2008-08-21 16:04:48 mezz Exp $ ++ * CVSID: $Id: patch-hald_freebsd_addons_addon-mouse.c,v 1.2 2008-12-21 06:20:19 marcus Exp $ + * + * addon-mouse.c : poll mice to disable moused(8) owned devices + * @@ -28,6 +28,13 @@ +# include <config.h> +#endif + ++#include <sys/param.h> ++#if __FreeBSD_version >= 800058 ++#include <sys/types.h> ++#include <sys/user.h> ++#include <sys/sysctl.h> ++#include <libutil.h> ++#endif +#include <string.h> +#include <stdlib.h> +#include <assert.h> @@ -38,7 +45,9 @@ + +#include "../libprobe/hfp.h" + ++#if __FreeBSD_version < 800058 +#define CMD "/usr/bin/fstat %s" ++#endif + +#define MOUSE_DRIVER "mouse" +#define MOUSED_DEVICE "/dev/sysmouse" @@ -47,11 +56,121 @@ + +static struct +{ -+ const struct timespec update_interval; -+ char *device_file; -+ struct timespec next_update; ++ const struct timespec update_interval; ++ char *device_file; ++ struct timespec next_update; +} addon = { { 2, 0 } }; + ++#if __FreeBSD_version >= 800058 ++static struct kinfo_proc * ++hfp_kinfo_getproc (int *cntp) ++{ ++ int mib[3]; ++ int error; ++ int cnt; ++ size_t len; ++ char *buf, *bp, *eb; ++ struct kinfo_proc *kip, *kp, *ki; ++ ++ *cntp = 0; ++ ++ len = 0; ++ mib[0] = CTL_KERN; ++ mib[1] = KERN_PROC; ++ mib[2] = KERN_PROC_PROC; ++ ++ error = sysctl(mib, 3, NULL, &len, NULL, 0); ++ if (error) ++ return NULL; ++ ++ len = len * 4 / 3; ++ buf = (char *) g_malloc(len); ++ if (buf == NULL) ++ return NULL; ++ ++ error = sysctl(mib, 3, buf, &len, NULL, 0); ++ if (error) ++ { ++ g_free(buf); ++ return NULL; ++ } ++ ++ cnt = 0; ++ bp = buf; ++ eb = buf + len; ++ while (bp < eb) ++ { ++ ki = (struct kinfo_proc *) (uintptr_t) bp; ++ bp += ki->ki_structsize; ++ cnt++; ++ } ++ ++ kip = calloc(cnt, sizeof (*kip)); ++ if (kip == NULL) ++ { ++ g_free(buf); ++ return NULL; ++ } ++ ++ bp = buf; ++ eb = buf + len; ++ kp = kip; ++ while (bp < eb) ++ { ++ ki = (struct kinfo_proc *) (uintptr_t) bp; ++ memcpy(kp, ki, ki->ki_structsize); ++ bp += ki->ki_structsize; ++ kp->ki_structsize = sizeof(*kp); ++ kp++; ++ } ++ ++ g_free(buf); ++ *cntp = cnt; ++ return kip; ++} ++ ++static gboolean ++device_opened_by_proc (const char *device, const char *proc) ++{ ++ struct kinfo_proc *kip, *pfreep; ++ int cnt, i; ++ ++ pfreep = hfp_kinfo_getproc(&cnt); ++ if (pfreep == NULL) ++ return FALSE; ++ ++ for (i = 0; i < cnt; i++) ++ { ++ kip = &pfreep[i]; ++ ++ if (! strcmp(kip->ki_comm, proc)) ++ { ++ struct kinfo_file *kif, *ffreep; ++ int fcnt, j; ++ ++ ffreep = kinfo_getfile(kip->ki_pid, &fcnt); ++ if (ffreep == NULL) ++ continue; ++ for (j = 0; j < fcnt; j++) ++ { ++ kif = &ffreep[j]; ++ ++ if (kif->kf_type == KF_TYPE_VNODE && ++ ! strcmp(kif->kf_path, device)) ++ { ++ g_free(ffreep); ++ g_free(pfreep); ++ return TRUE; ++ } ++ } ++ g_free(ffreep); ++ } ++ } ++ g_free(pfreep); ++ ++ return FALSE; ++} ++#else +static gboolean +device_opened_by_proc (const char *device, const char *proc) +{ @@ -91,16 +210,16 @@ + if (len < 2) + { + g_strfreev(fields); -+ continue; -+ } ++ continue; ++ } + for (j = 1; j < len && fields[j] && *fields[j] == '\0'; j++) + ; + if (j < len && fields[j] && ! strcmp(fields[j], proc)) + { + found = TRUE; + g_strfreev(fields); -+ break; -+ } ++ break; ++ } + g_strfreev(fields); + } + @@ -111,6 +230,7 @@ + + return found; +} ++#endif + +static const char * +get_mouse_device (const char *device) @@ -186,27 +306,27 @@ + { + /* process dbus traffic until update interval has elapsed */ + while (TRUE) -+ { -+ struct timespec now; -+ -+ hfp_clock_gettime(&now); -+ if (hfp_timespeccmp(&now, &addon.next_update, <)) -+ { -+ struct timespec timeout; -+ -+ timeout = addon.next_update; -+ hfp_timespecsub(&timeout, &now); -+ -+ if (timeout.tv_sec < 0) /* current time went backwards */ -+ timeout = addon.update_interval; -+ -+ dbus_connection_read_write_dispatch(connection, timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000); -+ if (! dbus_connection_get_is_connected(connection)) -+ goto end; -+ } -+ else -+ break; -+ } ++ { ++ struct timespec now; ++ ++ hfp_clock_gettime(&now); ++ if (hfp_timespeccmp(&now, &addon.next_update, <)) ++ { ++ struct timespec timeout; ++ ++ timeout = addon.next_update; ++ hfp_timespecsub(&timeout, &now); ++ ++ if (timeout.tv_sec < 0) /* current time went backwards */ ++ timeout = addon.update_interval; ++ ++ dbus_connection_read_write_dispatch(connection, timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000); ++ if (! dbus_connection_get_is_connected(connection)) ++ goto end; ++ } ++ else ++ break; ++ } + + poll_for_moused(); + |