0001
0002 #define _GNU_SOURCE
0003 #include <fcntl.h> /* in glibc 2.2 this has the needed
0004 values defined */
0005 #include <signal.h>
0006 #include <stdio.h>
0007 #include <unistd.h>
0008
0009 static volatile int event_fd;
0010
0011 static void handler(int sig, siginfo_t *si, void *data)
0012 {
0013 event_fd = si->si_fd;
0014 }
0015
0016 int main(void)
0017 {
0018 struct sigaction act;
0019 int fd;
0020
0021 act.sa_sigaction = handler;
0022 sigemptyset(&act.sa_mask);
0023 act.sa_flags = SA_SIGINFO;
0024 sigaction(SIGRTMIN + 1, &act, NULL);
0025
0026 fd = open(".", O_RDONLY);
0027 fcntl(fd, F_SETSIG, SIGRTMIN + 1);
0028 fcntl(fd, F_NOTIFY, DN_MODIFY|DN_CREATE|DN_MULTISHOT);
0029
0030
0031 while (1) {
0032 pause();
0033 printf("Got event on fd=%d\n", event_fd);
0034 }
0035 }