Path: blob/master/tools/testing/selftests/filesystems/dnotify_test.c
26298 views
// SPDX-License-Identifier: GPL-2.01#define _GNU_SOURCE /* needed to get the defines */2#include <fcntl.h> /* in glibc 2.2 this has the needed3values defined */4#include <signal.h>5#include <stdio.h>6#include <unistd.h>78static volatile int event_fd;910static void handler(int sig, siginfo_t *si, void *data)11{12event_fd = si->si_fd;13}1415int main(void)16{17struct sigaction act;18int fd;1920act.sa_sigaction = handler;21sigemptyset(&act.sa_mask);22act.sa_flags = SA_SIGINFO;23sigaction(SIGRTMIN + 1, &act, NULL);2425fd = open(".", O_RDONLY);26fcntl(fd, F_SETSIG, SIGRTMIN + 1);27fcntl(fd, F_NOTIFY, DN_MODIFY|DN_CREATE|DN_MULTISHOT);28/* we will now be notified if any of the files29in "." is modified or new files are created */30while (1) {31pause();32printf("Got event on fd=%d\n", event_fd);33}34}353637