2014-04-25 05:55:05 +00:00
|
|
|
.\" Copyright (C) 2013, Heinrich Schuchardt <xypron.glpk@gmx.de>
|
2014-05-08 08:24:22 +00:00
|
|
|
.\" and Copyright (C) 2014, Michael Kerrisk <mtk.manpages@gmail.com>
|
2014-04-25 05:55:05 +00:00
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(VERBATIM)
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of
|
|
|
|
.\" this manual under the conditions for verbatim copying, provided that
|
|
|
|
.\" the entire resulting derived work is distributed under the terms of
|
|
|
|
.\" a permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume.
|
|
|
|
.\" no responsibility for errors or omissions, or for damages resulting.
|
|
|
|
.\" from the use of the information contained herein. The author(s) may.
|
|
|
|
.\" not have taken the same level of care in the production of this.
|
|
|
|
.\" manual, which is licensed free of charge, as they might when working.
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\" %%%LICENSE_END
|
iconv.1, locale.1, memusage.1, memusagestat.1, pldd.1, sprof.1, _syscall.2, add_key.2, adjtimex.2, bind.2, bpf.2, chown.2, clone.2, close.2, copy_file_range.2, eventfd.2, fanotify_init.2, fanotify_mark.2, fork.2, fsync.2, futex.2, getdents.2, getrlimit.2, getxattr.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, ioctl_fat.2, ioctl_getfsmap.2, ioctl_ns.2, ioctl_tty.2, ioctl_userfaultfd.2, kcmp.2, keyctl.2, listen.2, listxattr.2, mbind.2, membarrier.2, memfd_create.2, mkdir.2, move_pages.2, mremap.2, msync.2, nfsservctl.2, open.2, perf_event_open.2, pidfd_send_signal.2, pipe.2, pivot_root.2, pkey_alloc.2, process_vm_readv.2, ptrace.2, readlink.2, readv.2, recv.2, recvmmsg.2, rename.2, request_key.2, s390_runtime_instr.2, sched_setaffinity.2, seccomp.2, send.2, sendmmsg.2, sigaltstack.2, signalfd.2, socket.2, socketpair.2, splice.2, spu_create.2, spu_run.2, statfs.2, syscall.2, sysctl.2, sysfs.2, tee.2, timer_getoverrun.2, timer_settime.2, umount.2, userfaultfd.2, utimensat.2, wait4.2, INFINITY.3, __ppc_get_timebase.3, __setfpucw.3, abort.3, aio_cancel.3, aio_error.3, aio_read.3, aio_return.3, atexit.3, backtrace.3, basename.3, bsearch.3, bswap.3, cacos.3, cacosh.3, catan.3, catanh.3, cexp2.3, clock_getcpuclockid.3, clog2.3, cmsg.3, confstr.3, div.3, dl_iterate_phdr.3, dlerror.3, dlinfo.3, dlopen.3, dlsym.3, duplocale.3, encrypt.3, end.3, endian.3, envz_add.3, err.3, expm1.3, fdim.3, flockfile.3, fmtmsg.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo_a.3, getauxval.3, getdate.3, getdtablesize.3, getgrent_r.3, getgrouplist.3, gethostbyname.3, getline.3, getnameinfo.3, getopt.3, getprotoent_r.3, getpwent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, getutent.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_ntop.3, inet_pton.3, insque.3, killpg.3, makecontext.3, mallinfo.3, malloc.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbsnrtowcs.3, mbstowcs.3, mcheck.3, mempcpy.3, mq_getattr.3, mq_notify.3, mtrace.3, newlocale.3, nextafter.3, ntp_gettime.3, offsetof.3, open_memstream.3, pow.3, printf.3, pthread_attr_init.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setstack.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_detach.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_join.3, pthread_mutex_consistent.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_spin_init.3, pthread_testcancel.3, pthread_tryjoin_np.3, ptsname.3, qsort.3, rand.3, random.3, remainder.3, rpmatch.3, rtime.3, rtnetlink.3, scalb.3, scalbln.3, scandir.3, sem_getvalue.3, sem_wait.3, setaliasent.3, setlogmask.3, sigwait.3, sincos.3, sockatmark.3, stdarg.3, stpcpy.3, strcat.3, strfmon.3, strptime.3, strtod.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, tsearch.3, uselocale.3, wcstok.3, wcstombs.3, wordexp.3, y0.3, loop.4, vcs.4, veth.4, charmap.5, core.5, filesystems.5, gai.conf.5, hosts.5, hosts.equiv.5, locale.5, nss.5, repertoiremap.5, securetty.5, shells.5, ttytype.5, ascii.7, complex.7, cpuset.7, credentials.7, fanotify.7, hier.7, inotify.7, ip.7, mount_namespaces.7, mq_overview.7, netlink.7, network_namespaces.7, pid_namespaces.7, pkeys.7, rtld-audit.7, rtnetlink.7, sem_overview.7, signal-safety.7, sock_diag.7, spufs.7, standards.7, symlink.7, tcp.7, time_namespaces.7, unix.7, user_namespaces.7, xattr.7, ldconfig.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-06-09 12:43:54 +00:00
|
|
|
.TH FANOTIFY 7 2020-06-09 "Linux" "Linux Programmer's Manual"
|
2014-04-25 05:55:05 +00:00
|
|
|
.SH NAME
|
|
|
|
fanotify \- monitoring filesystem events
|
|
|
|
.SH DESCRIPTION
|
2014-05-05 09:45:37 +00:00
|
|
|
The fanotify API provides notification and interception of
|
|
|
|
filesystem events.
|
2014-04-25 05:55:05 +00:00
|
|
|
Use cases include virus scanning and hierarchical storage management.
|
|
|
|
Currently, only a limited set of events is supported.
|
2014-04-25 06:05:16 +00:00
|
|
|
In particular, there is no support for create, delete, and move events.
|
2014-04-25 06:06:07 +00:00
|
|
|
(See
|
|
|
|
.BR inotify (7)
|
|
|
|
for details of an API that does notify those events.)
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-04-25 05:55:05 +00:00
|
|
|
Additional capabilities compared to the
|
|
|
|
.BR inotify (7)
|
2014-05-07 08:07:26 +00:00
|
|
|
API include the ability to monitor all of the objects
|
|
|
|
in a mounted filesystem,
|
|
|
|
the ability to make access permission decisions, and the
|
2014-04-25 05:55:05 +00:00
|
|
|
possibility to read or modify files before access by other applications.
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-04-25 05:55:05 +00:00
|
|
|
The following system calls are used with this API:
|
|
|
|
.BR fanotify_init (2),
|
|
|
|
.BR fanotify_mark (2),
|
|
|
|
.BR read (2),
|
|
|
|
.BR write (2),
|
|
|
|
and
|
|
|
|
.BR close (2).
|
2014-04-25 09:07:48 +00:00
|
|
|
.SS fanotify_init(), fanotify_mark(), and notification groups
|
2014-04-25 08:19:41 +00:00
|
|
|
The
|
2014-04-25 05:55:05 +00:00
|
|
|
.BR fanotify_init (2)
|
2014-04-25 08:19:41 +00:00
|
|
|
system call creates and initializes an fanotify notification group
|
|
|
|
and returns a file descriptor referring to it.
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
2014-04-25 06:05:16 +00:00
|
|
|
An fanotify notification group is a kernel-internal object that holds
|
2019-02-26 16:19:08 +00:00
|
|
|
a list of files, directories, filesystems, and mount points for which
|
2018-11-17 16:32:09 +00:00
|
|
|
events shall be created.
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
2014-04-25 06:05:16 +00:00
|
|
|
For each entry in an fanotify notification group, two bit masks exist: the
|
|
|
|
.I mark
|
|
|
|
mask and the
|
|
|
|
.I ignore
|
|
|
|
mask.
|
|
|
|
The mark mask defines file activities for which an event shall be created.
|
|
|
|
The ignore mask defines activities for which no event shall be generated.
|
2019-02-26 16:19:08 +00:00
|
|
|
Having these two types of masks permits a filesystem, mount point, or
|
2018-11-17 16:32:09 +00:00
|
|
|
directory to be marked for receiving events, while at the same time
|
|
|
|
ignoring events for specific objects under a mount point or directory.
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
2014-05-08 09:04:30 +00:00
|
|
|
The
|
2014-04-25 09:07:48 +00:00
|
|
|
.BR fanotify_mark (2)
|
2018-11-17 16:32:09 +00:00
|
|
|
system call adds a file, directory, filesystem or mount point to a
|
|
|
|
notification group and specifies which events
|
2014-04-25 09:07:48 +00:00
|
|
|
shall be reported (or ignored), or removes or modifies such an entry.
|
|
|
|
.PP
|
2014-04-25 05:55:05 +00:00
|
|
|
A possible usage of the ignore mask is for a file cache.
|
|
|
|
Events of interest for a file cache are modification of a file and closing
|
|
|
|
of the same.
|
|
|
|
Hence, the cached directory or mount point is to be marked to receive these
|
|
|
|
events.
|
2014-05-05 09:45:37 +00:00
|
|
|
After receiving the first event informing that a file has been modified,
|
|
|
|
the corresponding cache entry will be invalidated.
|
|
|
|
No further modification events for this file are of interest until the file
|
|
|
|
is closed.
|
2014-04-25 05:55:05 +00:00
|
|
|
Hence, the modify event can be added to the ignore mask.
|
2014-05-06 04:55:26 +00:00
|
|
|
Upon receiving the close event, the modify event can be removed from the
|
2014-04-25 05:55:05 +00:00
|
|
|
ignore mask and the file cache entry can be updated.
|
|
|
|
.PP
|
2014-05-05 09:45:37 +00:00
|
|
|
The entries in the fanotify notification groups refer to files and
|
|
|
|
directories via their inode number and to mounts via their mount ID.
|
2015-08-06 20:49:43 +00:00
|
|
|
If files or directories are renamed or moved within the same mount,
|
2014-05-05 09:45:37 +00:00
|
|
|
the respective entries survive.
|
2018-11-17 16:32:09 +00:00
|
|
|
If files or directories are deleted or moved to another mount or if
|
|
|
|
filesystems or mounts are unmounted, the corresponding entries are deleted.
|
2014-04-25 09:28:17 +00:00
|
|
|
.SS The event queue
|
2014-05-05 09:38:07 +00:00
|
|
|
As events occur on the filesystem objects monitored by a notification group,
|
2014-04-25 09:18:02 +00:00
|
|
|
the fanotify system generates events that are collected in a queue.
|
|
|
|
These events can then be read (using
|
|
|
|
.BR read (2)
|
|
|
|
or similar)
|
|
|
|
from the fanotify file descriptor
|
|
|
|
returned by
|
|
|
|
.BR fanotify_init (2).
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-04-25 09:18:02 +00:00
|
|
|
Two types of events are generated:
|
2014-05-07 08:07:26 +00:00
|
|
|
.I notification
|
|
|
|
events and
|
|
|
|
.I permission
|
|
|
|
events.
|
2020-08-25 11:40:54 +00:00
|
|
|
Notification events are merely informative and require no action to be taken
|
2020-08-28 12:26:12 +00:00
|
|
|
by the receiving application with one exception: if a valid file descriptor
|
2020-08-25 11:40:54 +00:00
|
|
|
is provided within a generic event, the file descriptor must be closed.
|
2014-05-05 09:45:37 +00:00
|
|
|
Permission events are requests to the receiving application to decide
|
|
|
|
whether permission for a file access shall be granted.
|
2014-04-25 05:55:05 +00:00
|
|
|
For these events, the recipient must write a response which decides whether
|
|
|
|
access is granted or not.
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-05-07 03:49:39 +00:00
|
|
|
An event is removed from the event queue of the fanotify group
|
|
|
|
when it has been read.
|
2014-05-06 18:41:06 +00:00
|
|
|
Permission events that have been read are kept in an internal list of the
|
2014-05-07 03:49:39 +00:00
|
|
|
fanotify group until either a permission decision has been taken by
|
|
|
|
writing to the fanotify file descriptor or the fanotify file descriptor
|
|
|
|
is closed.
|
2014-04-25 09:28:17 +00:00
|
|
|
.SS Reading fanotify events
|
2014-04-25 05:55:05 +00:00
|
|
|
Calling
|
|
|
|
.BR read (2)
|
|
|
|
for the file descriptor returned by
|
|
|
|
.BR fanotify_init (2)
|
|
|
|
blocks (if the flag
|
|
|
|
.B FAN_NONBLOCK
|
|
|
|
is not specified in the call to
|
|
|
|
.BR fanotify_init (2))
|
|
|
|
until either a file event occurs or the call is interrupted by a signal
|
|
|
|
(see
|
|
|
|
.BR signal (7)).
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2020-08-25 11:40:55 +00:00
|
|
|
The use of one of the flags
|
|
|
|
.BR FAN_REPORT_FID ,
|
|
|
|
.BR FAN_REPORT_DIR_FID
|
|
|
|
in
|
2019-06-06 09:48:02 +00:00
|
|
|
.BR fanotify_init (2)
|
2019-06-12 21:13:43 +00:00
|
|
|
influences what data structures are returned to the event listener for each
|
2020-08-28 12:18:05 +00:00
|
|
|
event.
|
|
|
|
Events reported to a group initialized with one of these flags will
|
2020-08-25 11:40:54 +00:00
|
|
|
use file handles to identify filesystem objects instead of file descriptors.
|
|
|
|
.TP
|
2014-04-25 05:55:05 +00:00
|
|
|
After a successful
|
2014-04-25 06:05:16 +00:00
|
|
|
.BR read (2),
|
2014-04-25 05:55:05 +00:00
|
|
|
the read buffer contains one or more of the following structures:
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-04-25 05:55:05 +00:00
|
|
|
.in +4n
|
execve.2, ioctl_console.2, ioctl_iflags.2, ioctl_ns.2, ioctl_userfaultfd.2, kcmp.2, kexec_load.2, keyctl.2, link.2, listxattr.2, membarrier.2, memfd_create.2, mmap.2, modify_ldt.2, mprotect.2, msgctl.2, nanosleep.2, open_by_handle_at.2, perf_event_open.2, poll.2, posix_fadvise.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, readdir.2, readv.2, recv.2, recvmmsg.2, request_key.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setscheduler.2, seccomp.2, select.2, select_tut.2, semctl.2, semop.2, send.2, sendmmsg.2, set_thread_area.2, setns.2, shmctl.2, shmget.2, sigaction.2, sigaltstack.2, signal.2, sigwaitinfo.2, stat.2, statfs.2, statx.2, sync_file_range.2, syscall.2, sysctl.2, sysinfo.2, tee.2, timer_create.2, timer_settime.2, timerfd_create.2, unshare.2, userfaultfd.2, ustat.2, utime.2, utimensat.2, vmsplice.2, wait.2, adjtime.3, aio_init.3, backtrace.3, basename.3, bswap.3, btree.3, clock_getcpuclockid.3, cmsg.3, confstr.3, dbopen.3, dl_iterate_phdr.3, dladdr.3, dlinfo.3, dlopen.3, duplocale.3, encrypt.3, end.3, endian.3, err.3, errno.3, ether_aton.3, fgetgrent.3, fgetpwent.3, fmemopen.3, frexp.3, ftime.3, fts.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, getifaddrs.3, getipnodebyname.3, getmntent.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, glob.3, gnu_get_libc_version.3, hash.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, isalpha.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, memchr.3, mq_getattr.3, mq_open.3, mq_receive.3, mq_send.3, mtrace.3, newlocale.3, ntp_gettime.3, posix_openpt.3, printf.3, pthread_attr_init.3, pthread_attr_setschedparam.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_tryjoin_np.3, readdir.3, realpath.3, recno.3, regex.3, rpc.3, scanf.3, sched_getcpu.3, sem_wait.3, setaliasent.3, sigqueue.3, statvfs.3, strcat.3, strcpy.3, strftime.3, strtok.3, strtol.3, strverscmp.3, toupper.3, ttyslot.3, xdr.3, fuse.4, loop.4, rtc.4, st.4, acct.5, core.5, elf.5, slabinfo.5, aio.7, arp.7, capabilities.7, cgroup_namespaces.7, cgroups.7, ddp.7, fanotify.7, feature_test_macros.7, inode.7, inotify.7, ip.7, keyrings.7, locale.7, mount_namespaces.7, namespaces.7, netdevice.7, netlink.7, packet.7, pkeys.7, pthreads.7, sched.7, session-keyring.7, sock_diag.7, socket.7, spufs.7, udplite.7, unix.7, user_namespaces.7, vdso.7, x25.7, ld.so.8: Use consistent markup for code snippets
Change .nf/.fi to .EX/.EE
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 19:52:46 +00:00
|
|
|
.EX
|
2014-04-25 05:55:05 +00:00
|
|
|
struct fanotify_event_metadata {
|
|
|
|
__u32 event_len;
|
|
|
|
__u8 vers;
|
|
|
|
__u8 reserved;
|
|
|
|
__u16 metadata_len;
|
|
|
|
__aligned_u64 mask;
|
|
|
|
__s32 fd;
|
|
|
|
__s32 pid;
|
|
|
|
};
|
execve.2, ioctl_console.2, ioctl_iflags.2, ioctl_ns.2, ioctl_userfaultfd.2, kcmp.2, kexec_load.2, keyctl.2, link.2, listxattr.2, membarrier.2, memfd_create.2, mmap.2, modify_ldt.2, mprotect.2, msgctl.2, nanosleep.2, open_by_handle_at.2, perf_event_open.2, poll.2, posix_fadvise.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, readdir.2, readv.2, recv.2, recvmmsg.2, request_key.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setscheduler.2, seccomp.2, select.2, select_tut.2, semctl.2, semop.2, send.2, sendmmsg.2, set_thread_area.2, setns.2, shmctl.2, shmget.2, sigaction.2, sigaltstack.2, signal.2, sigwaitinfo.2, stat.2, statfs.2, statx.2, sync_file_range.2, syscall.2, sysctl.2, sysinfo.2, tee.2, timer_create.2, timer_settime.2, timerfd_create.2, unshare.2, userfaultfd.2, ustat.2, utime.2, utimensat.2, vmsplice.2, wait.2, adjtime.3, aio_init.3, backtrace.3, basename.3, bswap.3, btree.3, clock_getcpuclockid.3, cmsg.3, confstr.3, dbopen.3, dl_iterate_phdr.3, dladdr.3, dlinfo.3, dlopen.3, duplocale.3, encrypt.3, end.3, endian.3, err.3, errno.3, ether_aton.3, fgetgrent.3, fgetpwent.3, fmemopen.3, frexp.3, ftime.3, fts.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, getifaddrs.3, getipnodebyname.3, getmntent.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, glob.3, gnu_get_libc_version.3, hash.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, isalpha.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, memchr.3, mq_getattr.3, mq_open.3, mq_receive.3, mq_send.3, mtrace.3, newlocale.3, ntp_gettime.3, posix_openpt.3, printf.3, pthread_attr_init.3, pthread_attr_setschedparam.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_tryjoin_np.3, readdir.3, realpath.3, recno.3, regex.3, rpc.3, scanf.3, sched_getcpu.3, sem_wait.3, setaliasent.3, sigqueue.3, statvfs.3, strcat.3, strcpy.3, strftime.3, strtok.3, strtol.3, strverscmp.3, toupper.3, ttyslot.3, xdr.3, fuse.4, loop.4, rtc.4, st.4, acct.5, core.5, elf.5, slabinfo.5, aio.7, arp.7, capabilities.7, cgroup_namespaces.7, cgroups.7, ddp.7, fanotify.7, feature_test_macros.7, inode.7, inotify.7, ip.7, keyrings.7, locale.7, mount_namespaces.7, namespaces.7, netdevice.7, netlink.7, packet.7, pkeys.7, pthreads.7, sched.7, session-keyring.7, sock_diag.7, socket.7, spufs.7, udplite.7, unix.7, user_namespaces.7, vdso.7, x25.7, ld.so.8: Use consistent markup for code snippets
Change .nf/.fi to .EX/.EE
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 19:52:46 +00:00
|
|
|
.EE
|
2014-04-25 05:55:05 +00:00
|
|
|
.in
|
2014-04-25 09:29:17 +00:00
|
|
|
.PP
|
2020-08-25 11:40:54 +00:00
|
|
|
In case of an fanotify group that identifies filesystem objects by file
|
|
|
|
handles, you should also expect to receive one or more additional information
|
|
|
|
records of the structure detailed below following the generic
|
2019-06-06 09:48:02 +00:00
|
|
|
.I fanotify_event_metadata
|
|
|
|
structure within the read buffer:
|
|
|
|
.PP
|
|
|
|
.in +4n
|
|
|
|
.EX
|
2020-08-25 11:40:54 +00:00
|
|
|
struct fanotify_event_info_header {
|
2020-08-28 12:26:12 +00:00
|
|
|
__u8 info_type;
|
|
|
|
__u8 pad;
|
|
|
|
__u16 len;
|
2020-08-25 11:40:54 +00:00
|
|
|
};
|
|
|
|
|
2019-06-06 09:48:02 +00:00
|
|
|
struct fanotify_event_info_fid {
|
|
|
|
struct fanotify_event_info_header hdr;
|
|
|
|
__kernel_fsid_t fsid;
|
|
|
|
unsigned char file_handle[0];
|
|
|
|
};
|
|
|
|
.EE
|
|
|
|
.in
|
|
|
|
.PP
|
2014-05-07 07:29:06 +00:00
|
|
|
For performance reasons, it is recommended to use a large
|
|
|
|
buffer size (for example, 4096 bytes),
|
|
|
|
so that multiple events can be retrieved by a single
|
|
|
|
.BR read (2).
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-05-07 07:29:06 +00:00
|
|
|
The return value of
|
|
|
|
.BR read (2)
|
|
|
|
is the number of bytes placed in the buffer,
|
2014-05-14 18:10:16 +00:00
|
|
|
or \-1 in case of an error (but see BUGS).
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-05-07 08:07:26 +00:00
|
|
|
The fields of the
|
|
|
|
.I fanotify_event_metadata
|
|
|
|
structure are as follows:
|
2014-04-25 08:16:17 +00:00
|
|
|
.TP
|
2014-04-25 05:55:05 +00:00
|
|
|
.I event_len
|
2014-05-05 09:45:37 +00:00
|
|
|
This is the length of the data for the current event and the offset
|
|
|
|
to the next event in the buffer.
|
2020-08-25 11:40:54 +00:00
|
|
|
Unless the group identifies filesystem objects by file handles, the value of
|
2014-04-25 05:55:05 +00:00
|
|
|
.I event_len
|
|
|
|
is always
|
|
|
|
.BR FAN_EVENT_METADATA_LEN .
|
2020-08-25 11:40:54 +00:00
|
|
|
For a group that identifies filesystem objects by file handles,
|
2019-06-06 09:48:02 +00:00
|
|
|
.I event_len
|
2020-08-25 11:40:54 +00:00
|
|
|
also includes the variable length file identifier records.
|
2014-04-25 05:55:05 +00:00
|
|
|
.TP
|
|
|
|
.I vers
|
2014-04-25 07:20:45 +00:00
|
|
|
This field holds a version number for the structure.
|
2014-04-25 05:55:05 +00:00
|
|
|
It must be compared to
|
|
|
|
.B FANOTIFY_METADATA_VERSION
|
2018-04-27 12:43:23 +00:00
|
|
|
to verify that the structures returned at run time match
|
2014-04-25 07:20:45 +00:00
|
|
|
the structures defined at compile time.
|
2014-04-25 05:55:05 +00:00
|
|
|
In case of a mismatch, the application should abandon trying to use the
|
|
|
|
fanotify file descriptor.
|
|
|
|
.TP
|
|
|
|
.I reserved
|
|
|
|
This field is not used.
|
|
|
|
.TP
|
|
|
|
.I metadata_len
|
|
|
|
This is the length of the structure.
|
2014-05-05 09:45:37 +00:00
|
|
|
The field was introduced to facilitate the implementation of
|
|
|
|
optional headers per event type.
|
2014-04-25 05:55:05 +00:00
|
|
|
No such optional headers exist in the current implementation.
|
|
|
|
.TP
|
|
|
|
.I mask
|
2014-05-07 08:07:26 +00:00
|
|
|
This is a bit mask describing the event (see below).
|
2014-04-25 05:55:05 +00:00
|
|
|
.TP
|
|
|
|
.I fd
|
|
|
|
This is an open file descriptor for the object being accessed, or
|
|
|
|
.B FAN_NOFD
|
|
|
|
if a queue overflow occurred.
|
2020-08-25 11:40:54 +00:00
|
|
|
With an fanotify group that identifies filesystem objects by file handles,
|
2019-06-06 09:48:02 +00:00
|
|
|
applications should expect this value to be set to
|
|
|
|
.B FAN_NOFD
|
|
|
|
for each event that is received.
|
2014-05-05 09:45:37 +00:00
|
|
|
The file descriptor can be used to access the contents
|
|
|
|
of the monitored file or directory.
|
2014-05-07 08:07:26 +00:00
|
|
|
The reading application is responsible for closing this file descriptor.
|
|
|
|
.IP
|
2014-05-07 07:53:35 +00:00
|
|
|
When calling
|
2014-05-07 19:59:08 +00:00
|
|
|
.BR fanotify_init (2),
|
2014-05-07 07:53:35 +00:00
|
|
|
the caller may specify (via the
|
|
|
|
.I event_f_flags
|
|
|
|
argument) various file status flags that are to be set
|
|
|
|
on the open file description that corresponds to this file descriptor.
|
|
|
|
In addition, the (kernel-internal)
|
2014-04-25 05:55:05 +00:00
|
|
|
.B FMODE_NONOTIFY
|
2014-05-07 07:53:35 +00:00
|
|
|
file status flag is set on the open file description.
|
2014-04-25 05:55:05 +00:00
|
|
|
This flag suppresses fanotify event generation.
|
|
|
|
Hence, when the receiver of the fanotify event accesses the notified file or
|
|
|
|
directory using this file descriptor, no additional events will be created.
|
|
|
|
.TP
|
|
|
|
.I pid
|
2018-11-17 16:32:10 +00:00
|
|
|
If flag
|
|
|
|
.B FAN_REPORT_TID
|
|
|
|
was set in
|
|
|
|
.BR fanotify_init (2),
|
|
|
|
this is the TID of the thread that caused the event.
|
|
|
|
Otherwise, this the PID of the process that caused the event.
|
|
|
|
.PP
|
2014-05-05 09:45:37 +00:00
|
|
|
A program listening to fanotify events can compare this PID
|
|
|
|
to the PID returned by
|
2014-04-25 05:55:05 +00:00
|
|
|
.BR getpid (2),
|
2014-05-05 09:45:37 +00:00
|
|
|
to determine whether the event is caused by the listener itself,
|
2014-05-07 08:07:26 +00:00
|
|
|
or is due to a file access by another process.
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
|
|
|
The bit mask in
|
|
|
|
.I mask
|
2014-05-07 08:07:26 +00:00
|
|
|
indicates which events have occurred for a single filesystem object.
|
2014-04-25 09:21:27 +00:00
|
|
|
Multiple bits may be set in this mask,
|
2014-05-05 09:38:07 +00:00
|
|
|
if more than one event occurred for the monitored filesystem object.
|
2014-04-25 09:24:04 +00:00
|
|
|
In particular,
|
|
|
|
consecutive events for the same filesystem object and originating from the
|
|
|
|
same process may be merged into a single event, with the exception that two
|
|
|
|
permission events are never merged into one queue entry.
|
|
|
|
.PP
|
2014-04-25 09:21:27 +00:00
|
|
|
The bits that may appear in
|
|
|
|
.I mask
|
|
|
|
are as follows:
|
2014-04-25 05:55:05 +00:00
|
|
|
.TP
|
|
|
|
.B FAN_ACCESS
|
|
|
|
A file or a directory (but see BUGS) was accessed (read).
|
|
|
|
.TP
|
|
|
|
.B FAN_OPEN
|
|
|
|
A file or a directory was opened.
|
|
|
|
.TP
|
2019-01-12 01:56:15 +00:00
|
|
|
.B FAN_OPEN_EXEC
|
|
|
|
A file was opened with the intent to be executed.
|
2019-02-26 15:35:57 +00:00
|
|
|
See NOTES in
|
2019-01-12 01:56:15 +00:00
|
|
|
.BR fanotify_mark (2)
|
|
|
|
for additional details.
|
|
|
|
.TP
|
2019-06-06 09:48:02 +00:00
|
|
|
.B FAN_ATTRIB
|
|
|
|
A file or directory metadata was changed.
|
|
|
|
.TP
|
|
|
|
.B FAN_CREATE
|
|
|
|
A child file or directory was created in a watched parent.
|
|
|
|
.TP
|
|
|
|
.B FAN_DELETE
|
|
|
|
A child file or directory was deleted in a watched parent.
|
|
|
|
.TP
|
|
|
|
.B FAN_DELETE_SELF
|
|
|
|
A watched file or directory was deleted.
|
|
|
|
.TP
|
|
|
|
.B FAN_MOVED_FROM
|
|
|
|
A file or directory has been moved from a watched parent directory.
|
|
|
|
.TP
|
|
|
|
.B FAN_MOVED_TO
|
|
|
|
A file or directory has been moved to a watched parent directory.
|
|
|
|
.TP
|
|
|
|
.B FAN_MOVE_SELF
|
|
|
|
A watched file or directory was moved.
|
|
|
|
.TP
|
2014-04-25 05:55:05 +00:00
|
|
|
.B FAN_MODIFY
|
|
|
|
A file was modified.
|
|
|
|
.TP
|
|
|
|
.B FAN_CLOSE_WRITE
|
|
|
|
A file that was opened for writing
|
|
|
|
.RB ( O_WRONLY
|
|
|
|
or
|
|
|
|
.BR O_RDWR )
|
|
|
|
was closed.
|
|
|
|
.TP
|
|
|
|
.B FAN_CLOSE_NOWRITE
|
2014-04-25 08:17:03 +00:00
|
|
|
A file or directory that was opened read-only
|
2014-04-25 05:55:05 +00:00
|
|
|
.RB ( O_RDONLY )
|
2014-04-25 08:17:03 +00:00
|
|
|
was closed.
|
2014-04-25 05:55:05 +00:00
|
|
|
.TP
|
|
|
|
.B FAN_Q_OVERFLOW
|
|
|
|
The event queue exceeded the limit of 16384 entries.
|
2014-05-07 08:07:26 +00:00
|
|
|
This limit can be overridden by specifying the
|
|
|
|
.BR FAN_UNLIMITED_QUEUE
|
|
|
|
flag when calling
|
|
|
|
.BR fanotify_init (2).
|
2014-04-25 05:55:05 +00:00
|
|
|
.TP
|
|
|
|
.B FAN_ACCESS_PERM
|
|
|
|
An application wants to read a file or directory, for example using
|
|
|
|
.BR read (2)
|
|
|
|
or
|
|
|
|
.BR readdir (2).
|
2014-05-07 08:07:26 +00:00
|
|
|
The reader must write a response (as described below)
|
|
|
|
that determines whether the permission to
|
2014-04-25 05:55:05 +00:00
|
|
|
access the filesystem object shall be granted.
|
|
|
|
.TP
|
|
|
|
.B FAN_OPEN_PERM
|
|
|
|
An application wants to open a file or directory.
|
|
|
|
The reader must write a response that determines whether the permission to
|
|
|
|
open the filesystem object shall be granted.
|
2019-01-12 01:56:15 +00:00
|
|
|
.TP
|
|
|
|
.B FAN_OPEN_EXEC_PERM
|
|
|
|
An application wants to open a file for execution.
|
|
|
|
The reader must write a response that determines whether the permission to
|
|
|
|
open the filesystem object for execution shall be granted.
|
2019-02-26 15:35:57 +00:00
|
|
|
See NOTES in
|
2019-01-12 01:56:15 +00:00
|
|
|
.BR fanotify_mark (2)
|
|
|
|
for additional details.
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
|
|
|
To check for any close event, the following bit mask may be used:
|
|
|
|
.TP
|
|
|
|
.B FAN_CLOSE
|
2014-04-25 09:32:32 +00:00
|
|
|
A file was closed.
|
2014-05-07 08:07:26 +00:00
|
|
|
This is a synonym for:
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.IP
|
2014-04-25 09:32:32 +00:00
|
|
|
FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
2019-06-06 09:48:02 +00:00
|
|
|
To check for any move event, the following bit mask may be used:
|
|
|
|
.TP
|
|
|
|
.B FAN_MOVE
|
|
|
|
A file or directory was moved.
|
|
|
|
This is a synonym for:
|
|
|
|
.IP
|
|
|
|
FAN_MOVED_FROM | FAN_MOVED_TO
|
|
|
|
.PP
|
2020-05-29 09:25:30 +00:00
|
|
|
The following bits may appear in
|
|
|
|
.I mask
|
|
|
|
only in conjunction with other event type bits:
|
|
|
|
.TP
|
|
|
|
.B FAN_ONDIR
|
|
|
|
The events described in the
|
|
|
|
.I mask
|
|
|
|
have occurred on a directory object.
|
|
|
|
Reporting events on directories requires setting this flag in the mark mask.
|
|
|
|
See
|
|
|
|
.BR fanotify_mark (2)
|
|
|
|
for additional details.
|
|
|
|
The
|
|
|
|
.BR FAN_ONDIR
|
2020-08-25 11:40:54 +00:00
|
|
|
flag is reported in an event mask only if the fanotify group identifies
|
|
|
|
filesystem objects by file handles.
|
2020-05-29 09:25:30 +00:00
|
|
|
.PP
|
2019-06-06 09:48:02 +00:00
|
|
|
The fields of the
|
|
|
|
.I fanotify_event_info_fid
|
|
|
|
structure are as follows:
|
|
|
|
.TP
|
|
|
|
.I hdr
|
|
|
|
This is a structure of type
|
|
|
|
.IR fanotify_event_info_header .
|
2020-08-25 11:40:54 +00:00
|
|
|
It is a generic header that contains information used to describe an
|
|
|
|
additional information record attached to the event.
|
2019-06-06 09:48:02 +00:00
|
|
|
For example, when an fanotify file descriptor is created using
|
2019-06-08 07:07:48 +00:00
|
|
|
.BR FAN_REPORT_FID ,
|
2020-08-25 11:40:54 +00:00
|
|
|
a single information record is expected to be attached to the event with
|
2019-06-06 09:48:02 +00:00
|
|
|
.I info_type
|
2020-08-25 11:40:54 +00:00
|
|
|
field value of
|
2020-05-29 09:25:28 +00:00
|
|
|
.BR FAN_EVENT_INFO_TYPE_FID .
|
2020-08-25 11:40:55 +00:00
|
|
|
When an fanotify file descriptor is created using the combination of
|
|
|
|
.BR FAN_REPORT_FID
|
|
|
|
and
|
|
|
|
.BR FAN_REPORT_DIR_FID ,
|
2020-08-28 12:26:12 +00:00
|
|
|
there may be two information records attached to the event:
|
|
|
|
one with
|
2020-08-25 11:40:55 +00:00
|
|
|
.I info_type
|
|
|
|
field value of
|
|
|
|
.BR FAN_EVENT_INFO_TYPE_DFID ,
|
|
|
|
identifying a parent directory object, and one with
|
|
|
|
.I info_type
|
|
|
|
field value of
|
|
|
|
.BR FAN_EVENT_INFO_TYPE_FID ,
|
|
|
|
identifying a non-directory object.
|
2020-08-25 11:40:54 +00:00
|
|
|
The
|
2019-06-06 09:48:02 +00:00
|
|
|
.I fanotify_event_info_header
|
2020-08-25 11:40:54 +00:00
|
|
|
contains a
|
2019-06-06 09:48:02 +00:00
|
|
|
.I len
|
|
|
|
field.
|
2020-08-25 11:40:54 +00:00
|
|
|
The value of
|
2019-06-06 09:48:02 +00:00
|
|
|
.I len
|
2020-08-25 11:40:54 +00:00
|
|
|
is the size of the additional information record including the
|
|
|
|
.IR fanotify_event_info_header
|
2020-08-28 12:18:05 +00:00
|
|
|
itself.
|
|
|
|
The total size of all additional information records is not expected
|
2020-08-25 11:40:54 +00:00
|
|
|
to be bigger than
|
|
|
|
(
|
|
|
|
.IR event_len
|
|
|
|
\-
|
|
|
|
.IR metadata_len
|
|
|
|
).
|
2019-06-06 09:48:02 +00:00
|
|
|
.TP
|
|
|
|
.I fsid
|
|
|
|
This is a unique identifier of the filesystem containing the object
|
|
|
|
associated with the event.
|
|
|
|
It is a structure of type
|
|
|
|
.I __kernel_fsid_t
|
|
|
|
and contains the same value as
|
|
|
|
.I f_fsid
|
|
|
|
when calling
|
|
|
|
.BR statfs (2).
|
|
|
|
.TP
|
|
|
|
.I file_handle
|
2020-08-25 11:40:54 +00:00
|
|
|
This is a variable length structure of type struct file_handle.
|
2019-06-06 09:48:02 +00:00
|
|
|
It is an opaque handle that corresponds to a specified object on a
|
|
|
|
filesystem as returned by
|
2019-06-08 07:07:48 +00:00
|
|
|
.BR name_to_handle_at (2).
|
2019-06-06 09:48:02 +00:00
|
|
|
It can be used to uniquely identify a file on a filesystem and can be
|
|
|
|
passed as an argument to
|
2019-06-08 07:07:48 +00:00
|
|
|
.BR open_by_handle_at (2).
|
2020-08-25 11:40:54 +00:00
|
|
|
Note that for the directory entry modification events
|
2019-06-06 09:48:02 +00:00
|
|
|
.BR FAN_CREATE ,
|
|
|
|
.BR FAN_DELETE ,
|
2019-06-08 07:07:48 +00:00
|
|
|
and
|
|
|
|
.BR FAN_MOVE ,
|
2019-06-06 09:48:02 +00:00
|
|
|
the
|
|
|
|
.IR file_handle
|
2020-08-25 11:40:54 +00:00
|
|
|
identifies the modified directory and not the created/deleted/moved child
|
2019-06-06 09:48:02 +00:00
|
|
|
object.
|
2020-08-25 11:40:56 +00:00
|
|
|
If the value of
|
|
|
|
.I info_type
|
|
|
|
field is
|
|
|
|
.BR FAN_EVENT_INFO_TYPE_DFID_NAME ,
|
|
|
|
the file handle is followed by a null terminated string that identifies the
|
|
|
|
created/deleted/moved directory entry name.
|
2020-08-25 11:40:54 +00:00
|
|
|
For other events such as
|
|
|
|
.BR FAN_OPEN ,
|
2019-06-06 09:48:02 +00:00
|
|
|
.BR FAN_ATTRIB ,
|
2019-06-08 07:07:48 +00:00
|
|
|
.BR FAN_DELETE_SELF ,
|
2019-06-06 09:48:02 +00:00
|
|
|
and
|
2020-08-25 11:40:54 +00:00
|
|
|
.BR FAN_MOVE_SELF ,
|
|
|
|
if the value of
|
|
|
|
.I info_type
|
|
|
|
field is
|
|
|
|
.BR FAN_EVENT_INFO_TYPE_FID ,
|
|
|
|
the
|
2019-06-06 09:48:02 +00:00
|
|
|
.IR file_handle
|
2020-08-25 11:40:54 +00:00
|
|
|
identifies the object correlated to the event.
|
2020-08-25 11:40:55 +00:00
|
|
|
If the value of
|
|
|
|
.I info_type
|
|
|
|
field is
|
|
|
|
.BR FAN_EVENT_INFO_TYPE_DFID ,
|
|
|
|
the
|
|
|
|
.IR file_handle
|
|
|
|
identifies the directory object correlated to the event or the parent directory
|
2020-08-25 11:40:56 +00:00
|
|
|
of a non-directory object correlated to the event.
|
|
|
|
If the value of
|
|
|
|
.I info_type
|
|
|
|
field is
|
|
|
|
.BR FAN_EVENT_INFO_TYPE_DFID_NAME ,
|
|
|
|
the
|
|
|
|
.IR file_handle
|
|
|
|
identifies the same directory object that would be reported with
|
|
|
|
.BR FAN_EVENT_INFO_TYPE_DFID
|
|
|
|
and the file handle is followed by a null terminated string that identifies the
|
|
|
|
name of a directory entry in that directory, or '.' to identify the directory
|
|
|
|
object itself.
|
2019-06-06 09:48:02 +00:00
|
|
|
.PP
|
2014-05-05 09:45:37 +00:00
|
|
|
The following macros are provided to iterate over a buffer containing
|
2014-05-07 08:07:26 +00:00
|
|
|
fanotify event metadata returned by a
|
2014-04-25 05:55:05 +00:00
|
|
|
.BR read (2)
|
2014-05-07 08:07:26 +00:00
|
|
|
from an fanotify file descriptor:
|
2014-04-25 05:55:05 +00:00
|
|
|
.TP
|
|
|
|
.B FAN_EVENT_OK(meta, len)
|
|
|
|
This macro checks the remaining length
|
|
|
|
.I len
|
|
|
|
of the buffer
|
|
|
|
.I meta
|
|
|
|
against the length of the metadata structure and the
|
|
|
|
.I event_len
|
|
|
|
field of the first metadata structure in the buffer.
|
|
|
|
.TP
|
|
|
|
.B FAN_EVENT_NEXT(meta, len)
|
2014-05-19 05:16:20 +00:00
|
|
|
This macro uses the length indicated in the
|
2014-04-25 05:55:05 +00:00
|
|
|
.I event_len
|
2014-05-19 05:16:20 +00:00
|
|
|
field of the metadata structure pointed to by
|
|
|
|
.IR meta
|
|
|
|
to calculate the address of the next metadata structure that follows
|
|
|
|
.IR meta .
|
|
|
|
.I len
|
|
|
|
is the number of bytes of metadata that currently remain in the buffer.
|
|
|
|
The macro returns a pointer to the next metadata structure that follows
|
|
|
|
.IR meta ,
|
|
|
|
and reduces
|
|
|
|
.I len
|
2015-03-15 01:12:59 +00:00
|
|
|
by the number of bytes in the metadata structure that
|
2014-05-19 05:16:20 +00:00
|
|
|
has been skipped over (i.e., it subtracts
|
|
|
|
.IR meta\->event_len
|
|
|
|
from
|
|
|
|
.IR len ).
|
2014-05-21 10:40:35 +00:00
|
|
|
.PP
|
|
|
|
In addition, there is:
|
|
|
|
.TP
|
|
|
|
.B FAN_EVENT_METADATA_LEN
|
2014-05-21 10:42:00 +00:00
|
|
|
This macro returns the size (in bytes) of the structure
|
|
|
|
.IR fanotify_event_metadata .
|
2014-05-21 10:40:35 +00:00
|
|
|
This is the minimum size (and currently the only size) of any event metadata.
|
2014-05-19 05:16:20 +00:00
|
|
|
.\"
|
2014-04-25 09:03:04 +00:00
|
|
|
.SS Monitoring an fanotify file descriptor for events
|
|
|
|
When an fanotify event occurs, the fanotify file descriptor indicates as
|
|
|
|
readable when passed to
|
|
|
|
.BR epoll (7),
|
|
|
|
.BR poll (2),
|
|
|
|
or
|
|
|
|
.BR select (2).
|
2014-04-25 08:50:02 +00:00
|
|
|
.SS Dealing with permission events
|
2014-04-25 05:55:05 +00:00
|
|
|
For permission events, the application must
|
|
|
|
.BR write (2)
|
|
|
|
a structure of the following form to the
|
2014-04-25 08:50:47 +00:00
|
|
|
fanotify file descriptor:
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-04-25 05:55:05 +00:00
|
|
|
.in +4n
|
execve.2, ioctl_console.2, ioctl_iflags.2, ioctl_ns.2, ioctl_userfaultfd.2, kcmp.2, kexec_load.2, keyctl.2, link.2, listxattr.2, membarrier.2, memfd_create.2, mmap.2, modify_ldt.2, mprotect.2, msgctl.2, nanosleep.2, open_by_handle_at.2, perf_event_open.2, poll.2, posix_fadvise.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, readdir.2, readv.2, recv.2, recvmmsg.2, request_key.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setscheduler.2, seccomp.2, select.2, select_tut.2, semctl.2, semop.2, send.2, sendmmsg.2, set_thread_area.2, setns.2, shmctl.2, shmget.2, sigaction.2, sigaltstack.2, signal.2, sigwaitinfo.2, stat.2, statfs.2, statx.2, sync_file_range.2, syscall.2, sysctl.2, sysinfo.2, tee.2, timer_create.2, timer_settime.2, timerfd_create.2, unshare.2, userfaultfd.2, ustat.2, utime.2, utimensat.2, vmsplice.2, wait.2, adjtime.3, aio_init.3, backtrace.3, basename.3, bswap.3, btree.3, clock_getcpuclockid.3, cmsg.3, confstr.3, dbopen.3, dl_iterate_phdr.3, dladdr.3, dlinfo.3, dlopen.3, duplocale.3, encrypt.3, end.3, endian.3, err.3, errno.3, ether_aton.3, fgetgrent.3, fgetpwent.3, fmemopen.3, frexp.3, ftime.3, fts.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, getifaddrs.3, getipnodebyname.3, getmntent.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, glob.3, gnu_get_libc_version.3, hash.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, isalpha.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, memchr.3, mq_getattr.3, mq_open.3, mq_receive.3, mq_send.3, mtrace.3, newlocale.3, ntp_gettime.3, posix_openpt.3, printf.3, pthread_attr_init.3, pthread_attr_setschedparam.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_tryjoin_np.3, readdir.3, realpath.3, recno.3, regex.3, rpc.3, scanf.3, sched_getcpu.3, sem_wait.3, setaliasent.3, sigqueue.3, statvfs.3, strcat.3, strcpy.3, strftime.3, strtok.3, strtol.3, strverscmp.3, toupper.3, ttyslot.3, xdr.3, fuse.4, loop.4, rtc.4, st.4, acct.5, core.5, elf.5, slabinfo.5, aio.7, arp.7, capabilities.7, cgroup_namespaces.7, cgroups.7, ddp.7, fanotify.7, feature_test_macros.7, inode.7, inotify.7, ip.7, keyrings.7, locale.7, mount_namespaces.7, namespaces.7, netdevice.7, netlink.7, packet.7, pkeys.7, pthreads.7, sched.7, session-keyring.7, sock_diag.7, socket.7, spufs.7, udplite.7, unix.7, user_namespaces.7, vdso.7, x25.7, ld.so.8: Use consistent markup for code snippets
Change .nf/.fi to .EX/.EE
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 19:52:46 +00:00
|
|
|
.EX
|
2014-04-25 05:55:05 +00:00
|
|
|
struct fanotify_response {
|
|
|
|
__s32 fd;
|
|
|
|
__u32 response;
|
|
|
|
};
|
execve.2, ioctl_console.2, ioctl_iflags.2, ioctl_ns.2, ioctl_userfaultfd.2, kcmp.2, kexec_load.2, keyctl.2, link.2, listxattr.2, membarrier.2, memfd_create.2, mmap.2, modify_ldt.2, mprotect.2, msgctl.2, nanosleep.2, open_by_handle_at.2, perf_event_open.2, poll.2, posix_fadvise.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, readdir.2, readv.2, recv.2, recvmmsg.2, request_key.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setscheduler.2, seccomp.2, select.2, select_tut.2, semctl.2, semop.2, send.2, sendmmsg.2, set_thread_area.2, setns.2, shmctl.2, shmget.2, sigaction.2, sigaltstack.2, signal.2, sigwaitinfo.2, stat.2, statfs.2, statx.2, sync_file_range.2, syscall.2, sysctl.2, sysinfo.2, tee.2, timer_create.2, timer_settime.2, timerfd_create.2, unshare.2, userfaultfd.2, ustat.2, utime.2, utimensat.2, vmsplice.2, wait.2, adjtime.3, aio_init.3, backtrace.3, basename.3, bswap.3, btree.3, clock_getcpuclockid.3, cmsg.3, confstr.3, dbopen.3, dl_iterate_phdr.3, dladdr.3, dlinfo.3, dlopen.3, duplocale.3, encrypt.3, end.3, endian.3, err.3, errno.3, ether_aton.3, fgetgrent.3, fgetpwent.3, fmemopen.3, frexp.3, ftime.3, fts.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, getifaddrs.3, getipnodebyname.3, getmntent.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, glob.3, gnu_get_libc_version.3, hash.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, isalpha.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, memchr.3, mq_getattr.3, mq_open.3, mq_receive.3, mq_send.3, mtrace.3, newlocale.3, ntp_gettime.3, posix_openpt.3, printf.3, pthread_attr_init.3, pthread_attr_setschedparam.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_tryjoin_np.3, readdir.3, realpath.3, recno.3, regex.3, rpc.3, scanf.3, sched_getcpu.3, sem_wait.3, setaliasent.3, sigqueue.3, statvfs.3, strcat.3, strcpy.3, strftime.3, strtok.3, strtol.3, strverscmp.3, toupper.3, ttyslot.3, xdr.3, fuse.4, loop.4, rtc.4, st.4, acct.5, core.5, elf.5, slabinfo.5, aio.7, arp.7, capabilities.7, cgroup_namespaces.7, cgroups.7, ddp.7, fanotify.7, feature_test_macros.7, inode.7, inotify.7, ip.7, keyrings.7, locale.7, mount_namespaces.7, namespaces.7, netdevice.7, netlink.7, packet.7, pkeys.7, pthreads.7, sched.7, session-keyring.7, sock_diag.7, socket.7, spufs.7, udplite.7, unix.7, user_namespaces.7, vdso.7, x25.7, ld.so.8: Use consistent markup for code snippets
Change .nf/.fi to .EX/.EE
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 19:52:46 +00:00
|
|
|
.EE
|
2014-04-25 05:55:05 +00:00
|
|
|
.in
|
2014-04-25 09:34:16 +00:00
|
|
|
.PP
|
|
|
|
The fields of this structure are as follows:
|
2014-04-25 08:16:17 +00:00
|
|
|
.TP
|
2014-04-25 05:55:05 +00:00
|
|
|
.I fd
|
|
|
|
This is the file descriptor from the structure
|
|
|
|
.IR fanotify_event_metadata .
|
|
|
|
.TP
|
|
|
|
.I response
|
|
|
|
This field indicates whether or not the permission is to be granted.
|
|
|
|
Its value must be either
|
|
|
|
.B FAN_ALLOW
|
|
|
|
to allow the file operation or
|
|
|
|
.B FAN_DENY
|
|
|
|
to deny the file operation.
|
|
|
|
.PP
|
2014-04-25 09:35:21 +00:00
|
|
|
If access is denied, the requesting application call will receive an
|
|
|
|
.BR EPERM
|
|
|
|
error.
|
2020-08-28 12:26:57 +00:00
|
|
|
.\"
|
2014-04-25 08:50:02 +00:00
|
|
|
.SS Closing the fanotify file descriptor
|
2014-04-25 08:53:38 +00:00
|
|
|
When all file descriptors referring to the fanotify notification group are
|
|
|
|
closed, the fanotify group is released and its resources
|
|
|
|
are freed for reuse by the kernel.
|
|
|
|
Upon
|
|
|
|
.BR close (2),
|
|
|
|
outstanding permission events will be set to allowed.
|
2014-04-25 09:46:16 +00:00
|
|
|
.SS /proc/[pid]/fdinfo
|
2014-04-25 05:55:05 +00:00
|
|
|
The file
|
2014-04-25 09:46:40 +00:00
|
|
|
.I /proc/[pid]/fdinfo/[fd]
|
2014-04-25 05:55:05 +00:00
|
|
|
contains information about fanotify marks for file descriptor
|
|
|
|
.I fd
|
|
|
|
of process
|
|
|
|
.IR pid .
|
2016-03-08 19:08:46 +00:00
|
|
|
See
|
|
|
|
.BR proc (5)
|
2014-04-25 05:55:05 +00:00
|
|
|
for details.
|
|
|
|
.SH ERRORS
|
|
|
|
In addition to the usual errors for
|
|
|
|
.BR read (2),
|
2014-05-05 09:45:37 +00:00
|
|
|
the following errors can occur when reading from the
|
|
|
|
fanotify file descriptor:
|
2014-04-25 05:55:05 +00:00
|
|
|
.TP
|
|
|
|
.B EINVAL
|
2014-05-07 08:07:26 +00:00
|
|
|
The buffer is too small to hold the event.
|
2014-04-25 05:55:05 +00:00
|
|
|
.TP
|
|
|
|
.B EMFILE
|
|
|
|
The per-process limit on the number of open files has been reached.
|
|
|
|
See the description of
|
|
|
|
.B RLIMIT_NOFILE
|
|
|
|
in
|
|
|
|
.BR getrlimit (2).
|
|
|
|
.TP
|
|
|
|
.B ENFILE
|
accept.2, acct.2, epoll_create.2, execve.2, futex.2, inotify_init.2, mmap.2, open.2, pipe.2, shmget.2, socket.2, socketpair.2, spu_create.2, swapon.2, uselib.2, getgrent.3, getgrnam.3, getlogin.3, getpwent.3, getpwnam.3, mq_open.3, opendir.3, sem_open.3, shm_open.3, tmpfile.3, fanotify.7: ERRORS: standardize text for ENFILE error
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-12-27 16:10:23 +00:00
|
|
|
The system-wide limit on the total number of open files has been reached.
|
2014-04-25 05:55:05 +00:00
|
|
|
See
|
2019-06-08 09:58:17 +00:00
|
|
|
.I /proc/sys/fs/file\-max
|
2014-04-25 05:55:05 +00:00
|
|
|
in
|
|
|
|
.BR proc (5).
|
|
|
|
.TP
|
|
|
|
.B ETXTBSY
|
|
|
|
This error is returned by
|
2014-04-25 09:38:09 +00:00
|
|
|
.BR read (2)
|
2014-04-25 05:55:05 +00:00
|
|
|
if
|
|
|
|
.B O_RDWR
|
|
|
|
or
|
|
|
|
.B O_WRONLY
|
|
|
|
was specified in the
|
|
|
|
.I event_f_flags
|
|
|
|
argument when calling
|
|
|
|
.BR fanotify_init (2)
|
2014-04-25 09:38:09 +00:00
|
|
|
and an event occurred for a monitored file that is currently being executed.
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
|
|
|
In addition to the usual errors for
|
|
|
|
.BR write (2),
|
|
|
|
the following errors can occur when writing to the fanotify file descriptor:
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
2014-05-05 09:45:37 +00:00
|
|
|
Fanotify access permissions are not enabled in the kernel configuration
|
|
|
|
or the value of
|
2014-04-25 05:55:05 +00:00
|
|
|
.I response
|
|
|
|
in the response structure is not valid.
|
|
|
|
.TP
|
|
|
|
.B ENOENT
|
|
|
|
The file descriptor
|
|
|
|
.I fd
|
|
|
|
in the response structure is not valid.
|
2014-05-07 03:49:39 +00:00
|
|
|
This may occur when a response for the permission event has already been
|
|
|
|
written.
|
2014-04-25 05:55:05 +00:00
|
|
|
.SH VERSIONS
|
|
|
|
The fanotify API was introduced in version 2.6.36 of the Linux kernel and
|
|
|
|
enabled in version 2.6.37.
|
|
|
|
Fdinfo support was added in version 3.8.
|
iconv.1, localedef.1, access.2, execveat.2, fanotify_init.2, futex.2, ioctl_fat.2, mount.2, ftw.3, sd.4, tty_ioctl.4, fanotify.7, futex.7, posixoptions.7, iconvconfig.8: srcfix: Remove useless quotes from .SS and .SH sections
Signed-off-by: Stéphane Aulery <saulery@free.fr>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-03-08 02:03:52 +00:00
|
|
|
.SH CONFORMING TO
|
2014-04-25 05:55:05 +00:00
|
|
|
The fanotify API is Linux-specific.
|
|
|
|
.SH NOTES
|
|
|
|
The fanotify API is available only if the kernel was built with the
|
|
|
|
.B CONFIG_FANOTIFY
|
|
|
|
configuration option enabled.
|
|
|
|
In addition, fanotify permission handling is available only if the
|
|
|
|
.B CONFIG_FANOTIFY_ACCESS_PERMISSIONS
|
|
|
|
configuration option is enabled.
|
|
|
|
.SS Limitations and caveats
|
|
|
|
Fanotify reports only events that a user-space program triggers through the
|
|
|
|
filesystem API.
|
2014-05-05 09:45:37 +00:00
|
|
|
As a result,
|
|
|
|
it does not catch remote events that occur on network filesystems.
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
|
|
|
The fanotify API does not report file accesses and modifications that
|
|
|
|
may occur because of
|
|
|
|
.BR mmap (2),
|
|
|
|
.BR msync (2),
|
|
|
|
and
|
|
|
|
.BR munmap (2).
|
|
|
|
.PP
|
|
|
|
Events for directories are created only if the directory itself is opened,
|
|
|
|
read, and closed.
|
|
|
|
Adding, removing, or changing children of a marked directory does not create
|
|
|
|
events for the monitored directory itself.
|
|
|
|
.PP
|
2014-05-05 09:45:37 +00:00
|
|
|
Fanotify monitoring of directories is not recursive:
|
|
|
|
to monitor subdirectories under a directory,
|
|
|
|
additional marks must be created.
|
2020-08-25 11:40:56 +00:00
|
|
|
The
|
|
|
|
.B FAN_CREATE
|
|
|
|
event can be used for detecting when a subdirectory has been created under
|
|
|
|
a marked directory.
|
|
|
|
An additional mark must then be set on the newly created subdirectory.
|
|
|
|
This approach is racy, because it can lose events that occurred inside the
|
|
|
|
newly created subdirectory, before a mark is added on that subdirectory.
|
|
|
|
Monitoring mounts offers the capability to monitor a whole directory tree
|
2020-08-28 12:26:12 +00:00
|
|
|
in a race-free manner.
|
2018-11-17 16:32:09 +00:00
|
|
|
Monitoring filesystems offers the capability to monitor changes made from
|
2020-08-28 12:26:12 +00:00
|
|
|
any mount of a filesystem instance in a race-free manner.
|
2014-04-25 05:55:05 +00:00
|
|
|
.PP
|
|
|
|
The event queue can overflow.
|
|
|
|
In this case, events are lost.
|
|
|
|
.SH BUGS
|
2015-04-30 10:11:53 +00:00
|
|
|
Before Linux 3.19,
|
|
|
|
.BR fallocate (2)
|
|
|
|
did not generate fanotify events.
|
|
|
|
Since Linux 3.19,
|
|
|
|
.\" commit 820c12d5d6c0890bc93dd63893924a13041fdc35
|
|
|
|
calls to
|
|
|
|
.BR fallocate (2)
|
|
|
|
generate
|
|
|
|
.B FAN_MODIFY
|
|
|
|
events.
|
aio.7, arp.7, attributes.7, boot.7, cgroups.7, cpuset.7, credentials.7, fanotify.7, fifo.7, glob.7, hier.7, hostname.7, icmp.7, inode.7, inotify.7, keyrings.7, libc.7, mailaddr.7, mount_namespaces.7, mq_overview.7, nptl.7, numa.7, path_resolution.7, persistent-keyring.7, pid_namespaces.7, pipe.7, pkeys.7, process-keyring.7, pthreads.7, pty.7, random.7, sched.7, sem_overview.7, session-keyring.7, shm_overview.7, signal-safety.7, signal.7, spufs.7, standards.7, symlink.7, termio.7, thread-keyring.7, time.7, unicode.7, user-keyring.7, user-session-keyring.7, user_namespaces.7, utf-8.7, xattr.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-17 22:59:04 +00:00
|
|
|
.PP
|
2014-10-02 22:05:03 +00:00
|
|
|
As of Linux 3.17,
|
2014-05-21 10:47:54 +00:00
|
|
|
the following bugs exist:
|
2014-04-25 05:55:05 +00:00
|
|
|
.IP * 3
|
2014-10-28 11:58:45 +00:00
|
|
|
On Linux, a filesystem object may be accessible through multiple paths,
|
2014-11-04 00:01:03 +00:00
|
|
|
for example, a part of a filesystem may be remounted using the
|
2014-10-28 11:58:45 +00:00
|
|
|
.IR \-\-bind
|
|
|
|
option of
|
|
|
|
.BR mount (8).
|
|
|
|
A listener that marked a mount will be notified only of events that were
|
|
|
|
triggered for a filesystem object using the same mount.
|
2014-10-28 11:52:42 +00:00
|
|
|
Any other event will pass unnoticed.
|
|
|
|
.IP *
|
adjtimex.2, bind.2, cacheflush.2, clone.2, fallocate.2, fanotify_init.2, fanotify_mark.2, flock.2, futex.2, getdents.2, getpriority.2, getrlimit.2, gettid.2, gettimeofday.2, ioprio_set.2, kexec_load.2, migrate_pages.2, modify_ldt.2, mount.2, move_pages.2, mprotect.2, msgop.2, nfsservctl.2, perf_event_open.2, pread.2, ptrace.2, recvmmsg.2, rename.2, restart_syscall.2, sched_setattr.2, send.2, shmop.2, shutdown.2, sigaction.2, signalfd.2, syscalls.2, timer_create.2, timerfd_create.2, tkill.2, vmsplice.2, wait.2, aio_init.3, confstr.3, exit.3, fmemopen.3, fopen.3, getaddrinfo.3, getauxval.3, getspnam.3, isalpha.3, isatty.3, mallinfo.3, malloc.3, mallopt.3, psignal.3, pthread_attr_setinheritsched.3, qecvt.3, queue.3, rtnetlink.3, strerror.3, strftime.3, toupper.3, towlower.3, towupper.3, initrd.4, locale.5, proc.5, bootparam.7, capabilities.7, ddp.7, fanotify.7, icmp.7, inotify.7, ip.7, ipv6.7, netdevice.7, netlink.7, path_resolution.7, rtld-audit.7, rtnetlink.7, sched.7, signal.7, socket.7, svipc.7, tcp.7, unix.7, ld.so.8: srcfix: Update FIXMEs
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2014-08-21 21:47:44 +00:00
|
|
|
.\" FIXME . A patch was proposed.
|
2014-05-05 09:45:37 +00:00
|
|
|
When an event is generated,
|
|
|
|
no check is made to see whether the user ID of the
|
|
|
|
receiving process has authorization to read or write the file
|
|
|
|
before passing a file descriptor for that file.
|
2014-04-25 05:55:05 +00:00
|
|
|
This poses a security risk, when the
|
|
|
|
.B CAP_SYS_ADMIN
|
|
|
|
capability is set for programs executed by unprivileged users.
|
2014-05-14 18:10:16 +00:00
|
|
|
.IP *
|
|
|
|
If a call to
|
2014-05-15 03:34:34 +00:00
|
|
|
.BR read (2)
|
2014-05-15 03:39:22 +00:00
|
|
|
processes multiple events from the fanotify queue and an error occurs,
|
|
|
|
the return value will be the total length of the events successfully
|
|
|
|
copied to the user-space buffer before the error occurred.
|
|
|
|
The return value will not be \-1, and
|
2014-05-14 18:10:16 +00:00
|
|
|
.I errno
|
|
|
|
will not be set.
|
2014-05-15 03:39:22 +00:00
|
|
|
Thus, the reading application has no way to detect the error.
|
2020-05-21 08:00:37 +00:00
|
|
|
.SH EXAMPLES
|
2019-06-06 09:48:02 +00:00
|
|
|
The two example programs below demonstrate the usage of the fanotify API.
|
2019-06-08 11:47:39 +00:00
|
|
|
.SS Example program: fanotify_example.c
|
|
|
|
The first program is an example of fanotify being
|
2019-06-06 09:48:02 +00:00
|
|
|
used with its event object information passed in the form of a file
|
|
|
|
descriptor.
|
2019-06-08 11:47:39 +00:00
|
|
|
The program marks the mount point passed as a command-line argument and
|
|
|
|
waits for events of type
|
2018-11-20 16:54:31 +00:00
|
|
|
.B FAN_OPEN_PERM
|
2014-04-25 05:55:05 +00:00
|
|
|
and
|
|
|
|
.BR FAN_CLOSE_WRITE .
|
|
|
|
When a permission event occurs, a
|
|
|
|
.B FAN_ALLOW
|
|
|
|
response is given.
|
|
|
|
.PP
|
2019-06-08 11:47:39 +00:00
|
|
|
The following shell session shows an example of
|
|
|
|
running this program.
|
2019-06-06 09:48:02 +00:00
|
|
|
This session involved editing the file
|
2014-04-25 05:55:05 +00:00
|
|
|
.IR /home/user/temp/notes .
|
|
|
|
Before the file was opened, a
|
|
|
|
.B FAN_OPEN_PERM
|
|
|
|
event occurred.
|
|
|
|
After the file was closed, a
|
|
|
|
.B FAN_CLOSE_WRITE
|
|
|
|
event occurred.
|
|
|
|
Execution of the program ends when the user presses the ENTER key.
|
2019-06-06 09:48:02 +00:00
|
|
|
.PP
|
2014-04-25 05:55:05 +00:00
|
|
|
.in +4n
|
execve.2, ioctl_console.2, ioctl_iflags.2, ioctl_ns.2, ioctl_userfaultfd.2, kcmp.2, kexec_load.2, keyctl.2, link.2, listxattr.2, membarrier.2, memfd_create.2, mmap.2, modify_ldt.2, mprotect.2, msgctl.2, nanosleep.2, open_by_handle_at.2, perf_event_open.2, poll.2, posix_fadvise.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, readdir.2, readv.2, recv.2, recvmmsg.2, request_key.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setscheduler.2, seccomp.2, select.2, select_tut.2, semctl.2, semop.2, send.2, sendmmsg.2, set_thread_area.2, setns.2, shmctl.2, shmget.2, sigaction.2, sigaltstack.2, signal.2, sigwaitinfo.2, stat.2, statfs.2, statx.2, sync_file_range.2, syscall.2, sysctl.2, sysinfo.2, tee.2, timer_create.2, timer_settime.2, timerfd_create.2, unshare.2, userfaultfd.2, ustat.2, utime.2, utimensat.2, vmsplice.2, wait.2, adjtime.3, aio_init.3, backtrace.3, basename.3, bswap.3, btree.3, clock_getcpuclockid.3, cmsg.3, confstr.3, dbopen.3, dl_iterate_phdr.3, dladdr.3, dlinfo.3, dlopen.3, duplocale.3, encrypt.3, end.3, endian.3, err.3, errno.3, ether_aton.3, fgetgrent.3, fgetpwent.3, fmemopen.3, frexp.3, ftime.3, fts.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, getifaddrs.3, getipnodebyname.3, getmntent.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, glob.3, gnu_get_libc_version.3, hash.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, isalpha.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, memchr.3, mq_getattr.3, mq_open.3, mq_receive.3, mq_send.3, mtrace.3, newlocale.3, ntp_gettime.3, posix_openpt.3, printf.3, pthread_attr_init.3, pthread_attr_setschedparam.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_tryjoin_np.3, readdir.3, realpath.3, recno.3, regex.3, rpc.3, scanf.3, sched_getcpu.3, sem_wait.3, setaliasent.3, sigqueue.3, statvfs.3, strcat.3, strcpy.3, strftime.3, strtok.3, strtol.3, strverscmp.3, toupper.3, ttyslot.3, xdr.3, fuse.4, loop.4, rtc.4, st.4, acct.5, core.5, elf.5, slabinfo.5, aio.7, arp.7, capabilities.7, cgroup_namespaces.7, cgroups.7, ddp.7, fanotify.7, feature_test_macros.7, inode.7, inotify.7, ip.7, keyrings.7, locale.7, mount_namespaces.7, namespaces.7, netdevice.7, netlink.7, packet.7, pkeys.7, pthreads.7, sched.7, session-keyring.7, sock_diag.7, socket.7, spufs.7, udplite.7, unix.7, user_namespaces.7, vdso.7, x25.7, ld.so.8: Use consistent markup for code snippets
Change .nf/.fi to .EX/.EE
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 19:52:46 +00:00
|
|
|
.EX
|
2019-06-08 10:40:03 +00:00
|
|
|
# \fB./fanotify_example /home\fP
|
2014-04-25 05:55:05 +00:00
|
|
|
Press enter key to terminate.
|
|
|
|
Listening for events.
|
|
|
|
FAN_OPEN_PERM: File /home/user/temp/notes
|
|
|
|
FAN_CLOSE_WRITE: File /home/user/temp/notes
|
|
|
|
|
|
|
|
Listening for events stopped.
|
execve.2, ioctl_console.2, ioctl_iflags.2, ioctl_ns.2, ioctl_userfaultfd.2, kcmp.2, kexec_load.2, keyctl.2, link.2, listxattr.2, membarrier.2, memfd_create.2, mmap.2, modify_ldt.2, mprotect.2, msgctl.2, nanosleep.2, open_by_handle_at.2, perf_event_open.2, poll.2, posix_fadvise.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, readdir.2, readv.2, recv.2, recvmmsg.2, request_key.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setscheduler.2, seccomp.2, select.2, select_tut.2, semctl.2, semop.2, send.2, sendmmsg.2, set_thread_area.2, setns.2, shmctl.2, shmget.2, sigaction.2, sigaltstack.2, signal.2, sigwaitinfo.2, stat.2, statfs.2, statx.2, sync_file_range.2, syscall.2, sysctl.2, sysinfo.2, tee.2, timer_create.2, timer_settime.2, timerfd_create.2, unshare.2, userfaultfd.2, ustat.2, utime.2, utimensat.2, vmsplice.2, wait.2, adjtime.3, aio_init.3, backtrace.3, basename.3, bswap.3, btree.3, clock_getcpuclockid.3, cmsg.3, confstr.3, dbopen.3, dl_iterate_phdr.3, dladdr.3, dlinfo.3, dlopen.3, duplocale.3, encrypt.3, end.3, endian.3, err.3, errno.3, ether_aton.3, fgetgrent.3, fgetpwent.3, fmemopen.3, frexp.3, ftime.3, fts.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, getifaddrs.3, getipnodebyname.3, getmntent.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, glob.3, gnu_get_libc_version.3, hash.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, isalpha.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, memchr.3, mq_getattr.3, mq_open.3, mq_receive.3, mq_send.3, mtrace.3, newlocale.3, ntp_gettime.3, posix_openpt.3, printf.3, pthread_attr_init.3, pthread_attr_setschedparam.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_tryjoin_np.3, readdir.3, realpath.3, recno.3, regex.3, rpc.3, scanf.3, sched_getcpu.3, sem_wait.3, setaliasent.3, sigqueue.3, statvfs.3, strcat.3, strcpy.3, strftime.3, strtok.3, strtol.3, strverscmp.3, toupper.3, ttyslot.3, xdr.3, fuse.4, loop.4, rtc.4, st.4, acct.5, core.5, elf.5, slabinfo.5, aio.7, arp.7, capabilities.7, cgroup_namespaces.7, cgroups.7, ddp.7, fanotify.7, feature_test_macros.7, inode.7, inotify.7, ip.7, keyrings.7, locale.7, mount_namespaces.7, namespaces.7, netdevice.7, netlink.7, packet.7, pkeys.7, pthreads.7, sched.7, session-keyring.7, sock_diag.7, socket.7, spufs.7, udplite.7, unix.7, user_namespaces.7, vdso.7, x25.7, ld.so.8: Use consistent markup for code snippets
Change .nf/.fi to .EX/.EE
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 19:52:46 +00:00
|
|
|
.EE
|
2019-06-08 11:47:39 +00:00
|
|
|
.in
|
2019-06-06 09:48:02 +00:00
|
|
|
.SS Program source: fanotify_example.c
|
getrlimit.2, signalfd.2, statfs.2, tee.2, dlopen.3, duplocale.3, ftw.3, get_nprocs.3, mbstowcs.3, posix_spawn.3, strftime.3, full.4, fanotify.7, inotify.7, ip.7, netdevice.7, rtld-audit.7, unix.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-19 19:02:23 +00:00
|
|
|
\&
|
memusage.1, clone.2, eventfd.2, futex.2, getdents.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, keyctl.2, mmap.2, mprotect.2, msgop.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, setns.2, tee.2, timer_create.2, timerfd_create.2, unshare.2, userfaultfd.2, wait.2, __ppc_get_timebase.3, backtrace.3, bswap.3, clock_getcpuclockid.3, dl_iterate_phdr.3, dlinfo.3, dlopen.3, duplocale.3, end.3, endian.3, fmemopen.3, fopencookie.3, frexp.3, ftw.3, getdate.3, getgrouplist.3, getifaddrs.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, mq_getattr.3, mq_notify.3, newlocale.3, offsetof.3, posix_spawn.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, scandir.3, sem_wait.3, strcat.3, strftime.3, strtok.3, strtol.3, strverscmp.3, loop.4, core.5, aio.7, fanotify.7, feature_test_macros.7, inotify.7, pkeys.7, unix.7, user_namespaces.7: Use .EX/.EE for EXAMPLE programs
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 08:44:33 +00:00
|
|
|
.EX
|
2014-04-25 09:55:32 +00:00
|
|
|
#define _GNU_SOURCE /* Needed to get O_LARGEFILE definition */
|
2014-04-25 05:55:05 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/fanotify.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-06-08 07:34:45 +00:00
|
|
|
/* Read all available fanotify events from the file descriptor \(aqfd\(aq */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2014-04-25 08:07:18 +00:00
|
|
|
static void
|
2014-04-25 05:55:05 +00:00
|
|
|
handle_events(int fd)
|
|
|
|
{
|
|
|
|
const struct fanotify_event_metadata *metadata;
|
2014-05-21 20:16:16 +00:00
|
|
|
struct fanotify_event_metadata buf[200];
|
2014-04-25 05:55:05 +00:00
|
|
|
ssize_t len;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
ssize_t path_len;
|
|
|
|
char procfd_path[PATH_MAX];
|
|
|
|
struct fanotify_response response;
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Loop while events can be read from fanotify file descriptor */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2019-06-08 10:34:55 +00:00
|
|
|
for (;;) {
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Read some events */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2020-09-05 11:28:45 +00:00
|
|
|
len = read(fd, buf, sizeof(buf));
|
2014-04-25 05:55:05 +00:00
|
|
|
if (len == \-1 && errno != EAGAIN) {
|
|
|
|
perror("read");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Check if end of available data reached */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
break;
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Point to the first event in the buffer */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2014-05-21 20:16:16 +00:00
|
|
|
metadata = buf;
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Loop over all events in the buffer */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
while (FAN_EVENT_OK(metadata, len)) {
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Check that run\-time and compile\-time structures match */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
if (metadata\->vers != FANOTIFY_METADATA_VERSION) {
|
|
|
|
fprintf(stderr,
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
"Mismatch of fanotify metadata version.\en");
|
2014-04-25 05:55:05 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-04-29 13:35:54 +00:00
|
|
|
/* metadata\->fd contains either FAN_NOFD, indicating a
|
|
|
|
queue overflow, or a file descriptor (a nonnegative
|
|
|
|
integer). Here, we simply ignore queue overflow. */
|
2014-04-25 18:07:02 +00:00
|
|
|
|
2014-04-25 05:55:05 +00:00
|
|
|
if (metadata\->fd >= 0) {
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Handle open permission event */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
if (metadata\->mask & FAN_OPEN_PERM) {
|
|
|
|
printf("FAN_OPEN_PERM: ");
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Allow file to be opened */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
response.fd = metadata\->fd;
|
|
|
|
response.response = FAN_ALLOW;
|
2020-09-03 19:58:14 +00:00
|
|
|
write(fd, &response, sizeof(response));
|
2014-04-25 05:55:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Handle closing of writable file event */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
if (metadata\->mask & FAN_CLOSE_WRITE)
|
2014-04-25 05:55:05 +00:00
|
|
|
printf("FAN_CLOSE_WRITE: ");
|
|
|
|
|
2014-04-25 08:06:21 +00:00
|
|
|
/* Retrieve and print pathname of the accessed file */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
snprintf(procfd_path, sizeof(procfd_path),
|
|
|
|
"/proc/self/fd/%d", metadata\->fd);
|
|
|
|
path_len = readlink(procfd_path, path,
|
|
|
|
sizeof(path) \- 1);
|
|
|
|
if (path_len == \-1) {
|
|
|
|
perror("readlink");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-06-08 07:34:45 +00:00
|
|
|
path[path_len] = \(aq\e0\(aq;
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
printf("File %s\en", path);
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Close the file descriptor of the event */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
close(metadata\->fd);
|
|
|
|
}
|
|
|
|
|
2014-04-25 08:03:54 +00:00
|
|
|
/* Advance to next event */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
metadata = FAN_EVENT_NEXT(metadata, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char buf;
|
|
|
|
int fd, poll_num;
|
|
|
|
nfds_t nfds;
|
|
|
|
struct pollfd fds[2];
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Check mount point is supplied */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
if (argc != 2) {
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
fprintf(stderr, "Usage: %s MOUNT\en", argv[0]);
|
2014-04-25 05:55:05 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
printf("Press enter key to terminate.\en");
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Create the file descriptor for accessing the fanotify API */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
fd = fanotify_init(FAN_CLOEXEC | FAN_CLASS_CONTENT | FAN_NONBLOCK,
|
|
|
|
O_RDONLY | O_LARGEFILE);
|
|
|
|
if (fd == \-1) {
|
|
|
|
perror("fanotify_init");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Mark the mount for:
|
2014-04-25 05:55:05 +00:00
|
|
|
\- permission events before opening files
|
2014-04-25 08:00:53 +00:00
|
|
|
\- notification events after closing a write\-enabled
|
|
|
|
file descriptor */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,
|
2014-11-03 18:06:38 +00:00
|
|
|
FAN_OPEN_PERM | FAN_CLOSE_WRITE, AT_FDCWD,
|
2014-04-25 05:55:05 +00:00
|
|
|
argv[1]) == \-1) {
|
|
|
|
perror("fanotify_mark");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Prepare for polling */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
nfds = 2;
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Console input */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
fds[0].fd = STDIN_FILENO;
|
|
|
|
fds[0].events = POLLIN;
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Fanotify input */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
fds[1].fd = fd;
|
|
|
|
fds[1].events = POLLIN;
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* This is the loop to wait for incoming events */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
printf("Listening for events.\en");
|
2014-04-25 09:58:21 +00:00
|
|
|
|
2014-04-25 05:55:05 +00:00
|
|
|
while (1) {
|
|
|
|
poll_num = poll(fds, nfds, \-1);
|
|
|
|
if (poll_num == \-1) {
|
2014-04-25 09:57:29 +00:00
|
|
|
if (errno == EINTR) /* Interrupted by a signal */
|
|
|
|
continue; /* Restart poll() */
|
|
|
|
|
|
|
|
perror("poll"); /* Unexpected error */
|
2014-04-25 05:55:05 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2014-04-25 09:58:21 +00:00
|
|
|
|
2014-04-25 05:55:05 +00:00
|
|
|
if (poll_num > 0) {
|
|
|
|
if (fds[0].revents & POLLIN) {
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Console input is available: empty stdin and quit */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
2019-06-08 07:34:45 +00:00
|
|
|
while (read(STDIN_FILENO, &buf, 1) > 0 && buf != \(aq\en\(aq)
|
2014-04-25 05:55:05 +00:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
2014-04-25 09:58:21 +00:00
|
|
|
|
2014-04-25 05:55:05 +00:00
|
|
|
if (fds[1].revents & POLLIN) {
|
|
|
|
|
2014-04-25 08:00:53 +00:00
|
|
|
/* Fanotify events are available */
|
2014-04-25 05:55:05 +00:00
|
|
|
|
|
|
|
handle_events(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
printf("Listening for events stopped.\en");
|
2014-04-25 08:00:53 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2014-04-25 05:55:05 +00:00
|
|
|
}
|
memusage.1, clone.2, eventfd.2, futex.2, getdents.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, keyctl.2, mmap.2, mprotect.2, msgop.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, setns.2, tee.2, timer_create.2, timerfd_create.2, unshare.2, userfaultfd.2, wait.2, __ppc_get_timebase.3, backtrace.3, bswap.3, clock_getcpuclockid.3, dl_iterate_phdr.3, dlinfo.3, dlopen.3, duplocale.3, end.3, endian.3, fmemopen.3, fopencookie.3, frexp.3, ftw.3, getdate.3, getgrouplist.3, getifaddrs.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, makecontext.3, mallinfo.3, malloc_info.3, mallopt.3, matherr.3, mbstowcs.3, mcheck.3, mq_getattr.3, mq_notify.3, newlocale.3, offsetof.3, posix_spawn.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, scandir.3, sem_wait.3, strcat.3, strftime.3, strtok.3, strtol.3, strverscmp.3, loop.4, core.5, aio.7, fanotify.7, feature_test_macros.7, inotify.7, pkeys.7, unix.7, user_namespaces.7: Use .EX/.EE for EXAMPLE programs
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 08:44:33 +00:00
|
|
|
.EE
|
2019-06-08 11:47:39 +00:00
|
|
|
.\"
|
|
|
|
.SS Example program: fanotify_fid.c
|
2020-08-25 11:40:56 +00:00
|
|
|
The second program is an example of fanotify being used with a group that
|
|
|
|
identifies objects by file handles.
|
2019-06-10 09:11:01 +00:00
|
|
|
The program marks the filesystem object that is passed as
|
2019-06-08 11:47:39 +00:00
|
|
|
a command-line argument
|
|
|
|
and waits until an event of type
|
|
|
|
.B FAN_CREATE
|
|
|
|
has occurred.
|
2019-06-10 09:11:01 +00:00
|
|
|
The event mask indicates which type of filesystem object\(emeither
|
2019-09-02 06:55:33 +00:00
|
|
|
a file or a directory\(emwas created.
|
2019-06-08 11:47:39 +00:00
|
|
|
Once all events have been read from the buffer and processed accordingly,
|
|
|
|
the program simply terminates.
|
|
|
|
.PP
|
|
|
|
The following shell sessions show two different invocations of
|
|
|
|
this program, with different actions performed on a watched object.
|
|
|
|
.PP
|
|
|
|
The first session shows a mark being placed on
|
|
|
|
.IR /home/user .
|
|
|
|
This is followed by the creation of a regular file,
|
|
|
|
.IR /home/user/testfile.txt .
|
|
|
|
This results in a
|
|
|
|
.B FAN_CREATE
|
2020-04-20 18:42:58 +00:00
|
|
|
event being generated and reported against the file's parent watched
|
2020-08-25 11:40:56 +00:00
|
|
|
directory object and with the created file name.
|
2019-06-08 11:47:39 +00:00
|
|
|
Program execution ends once all events captured within the buffer have
|
|
|
|
been processed.
|
|
|
|
.PP
|
|
|
|
.in +4n
|
|
|
|
.EX
|
|
|
|
# \fB./fanotify_fid /home/user\fP
|
|
|
|
Listening for events.
|
2020-04-20 18:42:58 +00:00
|
|
|
FAN_CREATE (file created):
|
|
|
|
Directory /home/user has been modified.
|
pldd.1, bpf.2, clone.2, dup.2, ioctl_fat.2, nfsservctl.2, open_by_handle_at.2, perf_event_open.2, pivot_root.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, statx.2, dl_iterate_phdr.3, dlinfo.3, dlopen.3, insque.3, newlocale.3, printf.3, pthread_setname_np.3, rpc.3, stdarg.3, strfmon.3, veth.4, proc.5, slabinfo.5, cgroup_namespaces.7, cgroups.7, cpuset.7, fanotify.7, inotify.7, mount_namespaces.7, sock_diag.7, user_namespaces.7, ld.so.8: Use \(aq instead of ' inside monospace fonts
Use \(aq to get an unslanted single quote inside monospace code
blocks. Using a simple ' results in a slanted quote inside PDFs.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-24 07:32:31 +00:00
|
|
|
Entry \(aqtestfile.txt\(aq is not a subdirectory.
|
2019-06-08 11:47:39 +00:00
|
|
|
All events processed successfully. Program exiting.
|
|
|
|
|
2020-04-20 18:42:58 +00:00
|
|
|
$ \fBtouch /home/user/testfile.txt\fP # In another terminal
|
2019-06-08 11:47:39 +00:00
|
|
|
.EE
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
The second session shows a mark being placed on
|
|
|
|
.IR /home/user .
|
|
|
|
This is followed by the creation of a directory,
|
|
|
|
.IR /home/user/testdir .
|
2020-04-20 18:42:58 +00:00
|
|
|
This specific action results in a
|
2019-06-08 11:47:39 +00:00
|
|
|
.B FAN_CREATE
|
2020-04-20 18:42:58 +00:00
|
|
|
event being generated and is reported with the
|
2019-06-08 11:47:39 +00:00
|
|
|
.B FAN_ONDIR
|
2020-08-25 11:40:56 +00:00
|
|
|
flag set and with the created directory name.
|
2019-06-08 11:47:39 +00:00
|
|
|
.PP
|
|
|
|
.in +4n
|
|
|
|
.EX
|
|
|
|
# \fB./fanotify_fid /home/user\fP
|
|
|
|
Listening for events.
|
|
|
|
FAN_CREATE | FAN_ONDIR (subdirectory created):
|
|
|
|
Directory /home/user has been modified.
|
pldd.1, bpf.2, clone.2, dup.2, ioctl_fat.2, nfsservctl.2, open_by_handle_at.2, perf_event_open.2, pivot_root.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, statx.2, dl_iterate_phdr.3, dlinfo.3, dlopen.3, insque.3, newlocale.3, printf.3, pthread_setname_np.3, rpc.3, stdarg.3, strfmon.3, veth.4, proc.5, slabinfo.5, cgroup_namespaces.7, cgroups.7, cpuset.7, fanotify.7, inotify.7, mount_namespaces.7, sock_diag.7, user_namespaces.7, ld.so.8: Use \(aq instead of ' inside monospace fonts
Use \(aq to get an unslanted single quote inside monospace code
blocks. Using a simple ' results in a slanted quote inside PDFs.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-09-24 07:32:31 +00:00
|
|
|
Entry \(aqtestdir\(aq is a subdirectory.
|
2019-06-08 11:47:39 +00:00
|
|
|
All events processed successfully. Program exiting.
|
|
|
|
|
2020-04-20 18:42:58 +00:00
|
|
|
$ \fBmkdir \-p /home/user/testdir\fP # In another terminal
|
2019-06-08 11:47:39 +00:00
|
|
|
.EE
|
2019-06-06 09:48:02 +00:00
|
|
|
.in
|
|
|
|
.SS Program source: fanotify_fid.c
|
|
|
|
\&
|
|
|
|
.EX
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/fanotify.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define BUF_SIZE 256
|
|
|
|
|
2019-06-08 10:27:01 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
2019-06-06 09:48:02 +00:00
|
|
|
{
|
2020-04-20 18:42:58 +00:00
|
|
|
int fd, ret, event_fd, mount_fd;
|
2019-06-06 09:48:02 +00:00
|
|
|
ssize_t len, path_len;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char procfd_path[PATH_MAX];
|
|
|
|
char events_buf[BUF_SIZE];
|
|
|
|
struct file_handle *file_handle;
|
|
|
|
struct fanotify_event_metadata *metadata;
|
|
|
|
struct fanotify_event_info_fid *fid;
|
2020-08-25 11:40:56 +00:00
|
|
|
const char *file_name;
|
|
|
|
struct stat sb;
|
2019-06-06 09:48:02 +00:00
|
|
|
|
|
|
|
if (argc != 2) {
|
2019-09-02 06:55:33 +00:00
|
|
|
fprintf(stderr, "Invalid number of command line arguments.\en");
|
2019-06-06 09:48:02 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2020-04-20 18:42:58 +00:00
|
|
|
mount_fd = open(argv[1], O_DIRECTORY | O_RDONLY);
|
|
|
|
if (mount_fd == \-1) {
|
|
|
|
perror(argv[1]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-15 05:38:52 +00:00
|
|
|
/* Create an fanotify file descriptor with FAN_REPORT_DFID_NAME as
|
|
|
|
a flag so that program can receive fid events with directory
|
|
|
|
entry name. */
|
2019-06-08 07:32:33 +00:00
|
|
|
|
2020-08-25 11:40:56 +00:00
|
|
|
fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, 0);
|
2019-06-08 07:34:45 +00:00
|
|
|
if (fd == \-1) {
|
2019-06-06 09:48:02 +00:00
|
|
|
perror("fanotify_init");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Place a mark on the filesystem object supplied in argv[1]. */
|
2019-06-08 07:32:33 +00:00
|
|
|
|
2019-06-06 09:48:02 +00:00
|
|
|
ret = fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_ONLYDIR,
|
2020-05-29 09:25:28 +00:00
|
|
|
FAN_CREATE | FAN_ONDIR,
|
2019-06-06 09:48:02 +00:00
|
|
|
AT_FDCWD, argv[1]);
|
2019-06-08 07:34:45 +00:00
|
|
|
if (ret == \-1) {
|
2019-06-06 09:48:02 +00:00
|
|
|
perror("fanotify_mark");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-09-02 06:55:33 +00:00
|
|
|
printf("Listening for events.\en");
|
2019-06-06 09:48:02 +00:00
|
|
|
|
|
|
|
/* Read events from the event queue into a buffer */
|
2019-06-08 07:32:33 +00:00
|
|
|
|
2020-09-05 11:28:45 +00:00
|
|
|
len = read(fd, events_buf, sizeof(events_buf));
|
2019-06-08 07:34:45 +00:00
|
|
|
if (len == \-1 && errno != EAGAIN) {
|
2019-06-06 09:48:02 +00:00
|
|
|
perror("read");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process all events within the buffer */
|
2019-06-08 07:32:33 +00:00
|
|
|
|
2019-06-06 09:48:02 +00:00
|
|
|
for (metadata = (struct fanotify_event_metadata *) events_buf;
|
|
|
|
FAN_EVENT_OK(metadata, len);
|
|
|
|
metadata = FAN_EVENT_NEXT(metadata, len)) {
|
|
|
|
fid = (struct fanotify_event_info_fid *) (metadata + 1);
|
2019-09-02 06:55:33 +00:00
|
|
|
file_handle = (struct file_handle *) fid\->handle;
|
2019-06-06 09:48:02 +00:00
|
|
|
|
|
|
|
/* Ensure that the event info is of the correct type */
|
2019-06-08 07:32:33 +00:00
|
|
|
|
2020-08-25 11:40:56 +00:00
|
|
|
if (fid\->hdr.info_type == FAN_EVENT_INFO_TYPE_FID ||
|
|
|
|
fid\->hdr.info_type == FAN_EVENT_INFO_TYPE_DFID) {
|
|
|
|
file_name = NULL;
|
|
|
|
} else if (fid\->hdr.info_type == FAN_EVENT_INFO_TYPE_DFID_NAME) {
|
|
|
|
file_name = file_handle->f_handle +
|
|
|
|
file_handle->handle_bytes;
|
|
|
|
} else {
|
2019-09-02 06:55:33 +00:00
|
|
|
fprintf(stderr, "Received unexpected event info type.\en");
|
2019-06-06 09:48:02 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-09-02 06:55:33 +00:00
|
|
|
if (metadata\->mask == FAN_CREATE)
|
2020-04-20 18:42:58 +00:00
|
|
|
printf("FAN_CREATE (file created):\en");
|
2019-06-06 09:48:02 +00:00
|
|
|
|
2020-04-20 18:42:58 +00:00
|
|
|
if (metadata\->mask == (FAN_CREATE | FAN_ONDIR))
|
|
|
|
printf("FAN_CREATE | FAN_ONDIR (subdirectory created):\en");
|
2019-06-06 09:48:02 +00:00
|
|
|
|
2020-09-15 05:38:52 +00:00
|
|
|
/* metadata\->fd is set to FAN_NOFD when the group identifies
|
|
|
|
objects by file handles. To obtain a file descriptor for
|
|
|
|
the file object corresponding to an event you can use the
|
|
|
|
struct file_handle that\(aqs provided within the
|
|
|
|
fanotify_event_info_fid in conjunction with the
|
|
|
|
open_by_handle_at(2) system call. A check for ESTALE is
|
|
|
|
done to accommodate for the situation where the file handle
|
|
|
|
for the object was deleted prior to this system call. */
|
2019-06-08 07:32:33 +00:00
|
|
|
|
2020-04-20 18:42:58 +00:00
|
|
|
event_fd = open_by_handle_at(mount_fd, file_handle, O_RDONLY);
|
|
|
|
if (event_fd == \-1) {
|
2019-06-08 10:32:17 +00:00
|
|
|
if (errno == ESTALE) {
|
|
|
|
printf("File handle is no longer valid. "
|
2019-09-02 06:55:33 +00:00
|
|
|
"File has been deleted\en");
|
2019-06-08 10:32:17 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
perror("open_by_handle_at");
|
|
|
|
exit(EXIT_FAILURE);
|
2020-04-20 18:42:58 +00:00
|
|
|
}
|
2019-06-06 09:48:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 10:27:01 +00:00
|
|
|
snprintf(procfd_path, sizeof(procfd_path), "/proc/self/fd/%d",
|
|
|
|
event_fd);
|
2019-06-06 09:48:02 +00:00
|
|
|
|
2019-06-08 07:07:48 +00:00
|
|
|
/* Retrieve and print the path of the modified dentry */
|
2019-06-08 07:32:33 +00:00
|
|
|
|
2019-06-08 07:34:45 +00:00
|
|
|
path_len = readlink(procfd_path, path, sizeof(path) \- 1);
|
|
|
|
if (path_len == \-1) {
|
2019-06-06 09:48:02 +00:00
|
|
|
perror("readlink");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-09-02 06:55:33 +00:00
|
|
|
path[path_len] = \(aq\e0\(aq;
|
|
|
|
printf("\etDirectory \(aq%s\(aq has been modified.\en", path);
|
2019-06-06 09:48:02 +00:00
|
|
|
|
2020-08-25 11:40:56 +00:00
|
|
|
if (file_name) {
|
|
|
|
ret = fstatat(event_fd, file_name, &sb, 0);
|
|
|
|
if (ret == \-1) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
perror("fstatat");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
printf("\etEntry \(aq%s\(aq does not exist.\en", file_name);
|
|
|
|
} else if ((sb.st_mode & S_IFMT) == S_IFDIR) {
|
|
|
|
printf("\etEntry \(aq%s\(aq is a subdirectory.\en", file_name);
|
|
|
|
} else {
|
|
|
|
printf("\etEntry \(aq%s\(aq is not a subdirectory.\en",
|
|
|
|
file_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 09:48:02 +00:00
|
|
|
/* Close associated file descriptor for this event */
|
2019-06-08 07:34:45 +00:00
|
|
|
|
2019-06-06 09:48:02 +00:00
|
|
|
close(event_fd);
|
|
|
|
}
|
|
|
|
|
2019-09-02 06:55:33 +00:00
|
|
|
printf("All events processed successfully. Program exiting.\en");
|
2019-06-06 09:48:02 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
.EE
|
iconv.1, localedef.1, access.2, execveat.2, fanotify_init.2, futex.2, ioctl_fat.2, mount.2, ftw.3, sd.4, tty_ioctl.4, fanotify.7, futex.7, posixoptions.7, iconvconfig.8: srcfix: Remove useless quotes from .SS and .SH sections
Signed-off-by: Stéphane Aulery <saulery@free.fr>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-03-08 02:03:52 +00:00
|
|
|
.SH SEE ALSO
|
2014-04-25 05:55:05 +00:00
|
|
|
.ad l
|
|
|
|
.BR fanotify_init (2),
|
|
|
|
.BR fanotify_mark (2),
|
|
|
|
.BR inotify (7)
|