Created
April 30, 2012 02:39
-
-
Save lichray/2555062 to your computer and use it in GitHub Desktop.
A kqueue(2) example, listens to VFS mount/umount events.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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