From e8691a5cc2cdda30b2aba2817667a6b41b2ac9bc Mon Sep 17 00:00:00 2001 From: Kris Kennaway Date: Tue, 25 Apr 2000 08:04:55 +0000 Subject: [PATCH] On FreeBSD 5.0, use the new kqueue() notification system to monitor for directory changes. This cuts CPU usage from 100% down to about 0.1% as well as improving the reliability of change monitoring. --- security/l0pht-watch/files/patch-aa | 4 +- security/l0pht-watch/files/patch-ab | 74 +++++++++++++++++++++++++++++ security/l0pht-watch/files/patch-ac | 30 ++++++++++++ security/l0pht-watch/files/patch-ad | 11 +++++ 4 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 security/l0pht-watch/files/patch-ab create mode 100644 security/l0pht-watch/files/patch-ac create mode 100644 security/l0pht-watch/files/patch-ad diff --git a/security/l0pht-watch/files/patch-aa b/security/l0pht-watch/files/patch-aa index 720aa31199c8..71bee0618872 100644 --- a/security/l0pht-watch/files/patch-aa +++ b/security/l0pht-watch/files/patch-aa @@ -1,5 +1,5 @@ --- Makefile.orig Thu Sep 23 10:18:18 1999 -+++ Makefile Sat Dec 4 00:53:05 1999 ++++ Makefile Tue Apr 25 00:30:11 2000 @@ -9,12 +9,13 @@ # debugging # DFLAGS = -DTEST -DDEBUG @@ -21,7 +21,7 @@ OpenBSD: make -e $(ALL) $(MFLAGS) \ - XFLAGS='-DBSD -DREGEX -DREGCOMP_3C' CC="gcc $(CFLAGS)" STATIC=-static -+ XFLAGS='-DBSD -DREGEX -DREGCOMP_3C' CC="$(CC) $(CFLAGS)" \ ++ XFLAGS='-DREGEX -DREGCOMP_3C' CC="$(CC) $(CFLAGS)" \ + STATIC=-static generic: diff --git a/security/l0pht-watch/files/patch-ab b/security/l0pht-watch/files/patch-ab new file mode 100644 index 000000000000..ce4332eec381 --- /dev/null +++ b/security/l0pht-watch/files/patch-ab @@ -0,0 +1,74 @@ +--- check_tmp.c.orig Fri Sep 24 13:33:35 1999 ++++ check_tmp.c Tue Apr 25 00:57:56 2000 +@@ -38,6 +38,13 @@ + #endif + #endif + ++#if __FreeBSD_version >= 500001 ++ struct kevent ev; ++ struct kevent *evp; ++ int fd; ++ struct timespec ts = { 0, 0 }; ++ int kq = -1; ++#endif + + struct listStruct *list = NULL; + +@@ -178,6 +185,22 @@ + exit(1); + } + ++#if __FreeBSD_version >= 500001 ++ /* Set up the KQ on the target directory */ ++ fd = dirfd(dirp); ++ ++ kq = kqueue(); ++ if (kq < 0) ++ err(1, "kqueue"); ++ ++ ev.ident = fd; ++ ev.filter = EVFILT_VNODE; ++ ev.flags = EV_ADD | EV_ENABLE | EV_CLEAR; ++ ev.fflags = NOTE_WRITE; ++ evp = &ev; ++ kevent(kq, 1, &evp, 0, NULL, &ts); ++#endif ++ + /* steup the first element of the list */ + while ((dp = readdir(dirp)) != NULL){ + if (!list) /* first time */ +@@ -266,6 +289,10 @@ + rewinddir(dirp); + + while (1){ ++ ++#if __FreeBSD_version >= 500001 ++ if (ev.fflags & NOTE_WRITE) { ++#endif + while ((dp = readdir(dirp)) != NULL){ + if (!(checknode(list, watchdir, dp->d_name))){ + if (replacewatchflag){ +@@ -352,11 +379,22 @@ + /* closedir(dirp); */ + } + } +-#ifdef 0 ++#if 0 + walklist(list); + #endif + list = prunelist(list); + rewinddir(dirp); ++ ++#if __FreeBSD_version >= 500001 ++ /* Reset event so we don't trigger on the rewinddir */ ++ kevent(kq, 1, &evp, 0, NULL, &ts); ++ ++ /* Block until the directory changes */ ++ if (kevent(kq, 0, NULL, 1, &ev, NULL) < 0) ++ err(1, "kevent"); ++ ++ } ++#endif + } + /* closedir(dirp); */ + diff --git a/security/l0pht-watch/files/patch-ac b/security/l0pht-watch/files/patch-ac new file mode 100644 index 000000000000..cc663e00f43b --- /dev/null +++ b/security/l0pht-watch/files/patch-ac @@ -0,0 +1,30 @@ +--- check_tmp.h.orig Thu Dec 24 07:40:13 1998 ++++ check_tmp.h Tue Apr 25 00:29:52 2000 +@@ -1,16 +1,22 @@ + #ifndef __CHECK_TMP_H + #define __CHECK_TMP_H + +-#include +-#include + #include ++#include + #include ++#include + #include +-#include +-#include + #include +-#include ++#include ++#include ++#include ++#include + #include ++#if __FreeBSD_version >= 500001 ++#include ++#include ++#include ++#endif + + #if defined (REGEXPR_3G) + #include diff --git a/security/l0pht-watch/files/patch-ad b/security/l0pht-watch/files/patch-ad new file mode 100644 index 000000000000..dde9441b1e9d --- /dev/null +++ b/security/l0pht-watch/files/patch-ad @@ -0,0 +1,11 @@ +--- list_utils.c.orig Tue Apr 25 00:58:27 2000 ++++ list_utils.c Tue Apr 25 00:58:33 2000 +@@ -168,7 +168,7 @@ + + + +-#ifdef 0 ++#if 0 + printf("%-11s %-2d %-8s %-8s %-6ld %-10s %-10s\n", filemodes, + (int)list->statbuf.st_nlink, username, groupname, + list->statbuf.st_size, timehold, list->filename);