tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Examples of kfilter_register(9)?
On Mon, 31 Aug 2009, Marc Tooley wrote:
monkey around with it in userspace, but I'm still interested in seeing
an example, or hearing a description of what it was designed to do and
what purpose it was designed to serve.
Unless I'm totally off-track here, there is a userland interface: The code
below watches a given directory, and if any file is written or linked to
it runs a given command. Maybe that helps... based on code by someone
elase (I forgot who... sorry! :).
- Hubert
#include <stdio.h>
#include <sys/event.h>
#include <sys/time.h>
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>
void usage(void)
{
printf("Usage: %s dir-to-monitor logfile\n",
getprogname());
exit (0);
}
int main(int argc, char *argv[])
{
char cmd[256];
int qd, fd;
struct kevent filter, result;
int n;
if (argc != 3)
usage();
sprintf(cmd, "( date ; ls -l '%s' ) >%s", argv[1], argv[2]);
qd = kqueue();
assert(qd > 0);
fd = open(argv[1], O_RDONLY);
assert(fd > 0);
EV_SET( &filter, fd, EVFILT_VNODE, EV_ADD,
NOTE_WRITE|NOTE_EXTEND|NOTE_LINK, 0, NULL);
printf("Waiting for %s to get touched...\n", argv[1]);
/* n = */ kevent(qd, &filter, 1, &result, 1, NULL);
/* assert(n > 0); *//* speed up! */
/* should check 'result' here... */
system(cmd);
printf("Ran: %s\n", cmd);
return 0;
}
Home |
Main Index |
Thread Index |
Old Index