Skip to content

Instantly share code, notes, and snippets.

@lichray
Created April 30, 2012 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lichray/2555062 to your computer and use it in GitHub Desktop.
Save lichray/2555062 to your computer and use it in GitHub Desktop.
A kqueue(2) example, listens to VFS mount/umount events.
#include <sys/types.h>
#include <sys/event.h>
#include <sys/mount.h>
#include <stdio.h>
int main() {
int kq = kqueue();
struct kevent ki[1];
EV_SET(ki, 0, EVFILT_FS, EV_ADD, 0, 0, 0);
kevent(kq, ki, 1, NULL, 0, NULL);
puts("started");
for (;;) {
switch (kevent(kq, NULL, 0, ki, 1, NULL)) {
case -1:
perror("kevent");
case 0:
break;
default:
if (ki->fflags & VQ_MOUNT)
puts("mount");
else if (ki->fflags & VQ_UNMOUNT)
puts("umount");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment