man-pages/man2/fcntl.2

1671 lines
45 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
'\" t
.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
.\" and Copyright (C) 1993 Michael Haardt, Ian Jackson;
.\" and Copyright (C) 1998 Jamie Lokier;
.\" and Copyright (C) 2002-2010, 2014 Michael Kerrisk;
.\" and Copyright (C) 2014 Jeff Layton
2004-11-03 13:51:07 +00:00
.\"
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clock_getres.2, clock_nanosleep.2, close.2, connect.2, delete_module.2, dup.2, execve.2, exit_group.2, faccessat.2, fchmodat.2, fchownat.2, fcntl.2, fork.2, fstatat.2, fsync.2, futimesat.2, get_robust_list.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getpagesize.2, getpid.2, getresuid.2, getrlimit.2, getrusage.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, idle.2, init_module.2, intro.2, iopl.2, kcmp.2, kexec_load.2, kill.2, link.2, linkat.2, llseek.2, lookup_dcookie.2, madvise.2, mincore.2, mkdirat.2, mknodat.2, mmap.2, mmap2.2, mount.2, mprotect.2, mq_getsetattr.2, msgctl.2, msgget.2, msgop.2, msync.2, nice.2, open.2, openat.2, pause.2, perfmonctl.2, personality.2, pipe.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, quotactl.2, read.2, readahead.2, readdir.2, readlinkat.2, readv.2, reboot.2, recvmmsg.2, remap_file_pages.2, rename.2, renameat.2, rmdir.2, rt_sigqueueinfo.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, sendmmsg.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setresuid.2, setuid.2, setup.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, signal.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, splice.2, stat.2, statfs.2, stime.2, subpage_prot.2, swapon.2, symlink.2, symlinkat.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysfs.2, syslog.2, tee.2, time.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, times.2, tkill.2, umask.2, umount.2, uname.2, unlink.2, unlinkat.2, uselib.2, ustat.2, utime.2, utimensat.2, vfork.2, vhangup.2, vm86.2, vmsplice.2, wait.2, wait4.2, write.2, CPU_SET.3, INFINITY.3, abort.3, abs.3, acos.3, acosh.3, adjtime.3, aio_init.3, asin.3, asinh.3, asprintf.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atexit.3, atof.3, atoi.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, bsearch.3, bstring.3, byteorder.3, bzero.3, catgets.3, catopen.3, cbrt.3, ceil.3, clearenv.3, clock.3, clock_getcpuclockid.3, closedir.3, confstr.3, copysign.3, cos.3, cosh.3, ctermid.3, ctime.3, difftime.3, dirfd.3, div.3, dl_iterate_phdr.3, dprintf.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, end.3, endian.3, erf.3, erfc.3, ether_aton.3, euidaccess.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fcloseall.3, fexecve.3, ffs.3, fgetgrent.3, fgetpwent.3, finite.3, flockfile.3, floor.3, fmod.3, fnmatch.3, fopencookie.3, fpathconf.3, fpurge.3, frexp.3, fseeko.3, ftok.3, futimes.3, gcvt.3, get_nprocs_conf.3, getaddrinfo.3, getaddrinfo_a.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrnam.3, getgrouplist.3, gethostbyname.3, gethostid.3, getifaddrs.3, getipnodebyname.3, getline.3, getlogin.3, getmntent.3, getnetent.3, getnetent_r.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwnam.3, getrpcent_r.3, gets.3, getservent.3, getservent_r.3, getumask.3, getusershell.3, getutmp.3, getw.3, glob.3, gnu_get_libc_version.3, gsignal.3, hypot.3, if_nameindex.3, if_nametoindex.3, ilogb.3, index.3, inet.3, inet_ntop.3, inet_pton.3, infnan.3, initgroups.3, insque.3, intro.3, isalpha.3, isatty.3, j0.3, ldexp.3, localeconv.3, log.3, log10.3, log1p.3, log2.3, logb.3, lrint.3, lround.3, lsearch.3, lseek64.3, makecontext.3, makedev.3, mallinfo.3, malloc.3, malloc_get_state.3, malloc_info.3, malloc_stats.3, malloc_trim.3, malloc_usable_size.3, mallopt.3, matherr.3, mcheck.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, memset.3, mkdtemp.3, mkfifo.3, mkfifoat.3, mkstemp.3, mktemp.3, modf.3, mq_close.3, mq_getattr.3, mq_notify.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, on_exit.3, opendir.3, posix_fallocate.3, posix_memalign.3, posix_openpt.3, pow.3, pow10.3, profil.3, psignal.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_detach.3, pthread_equal.3, pthread_exit.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_join.3, pthread_kill.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_setschedprio.3, pthread_sigmask.3, pthread_sigqueue.3, pthread_testcancel.3, pthread_tryjoin_np.3, pthread_yield.3, putenv.3, putpwent.3, puts.3, qecvt.3, qsort.3, raise.3, rand.3, random.3, random_r.3, re_comp.3, readdir.3, realpath.3, regex.3, remainder.3, remove.3, resolver.3, rewinddir.3, rint.3, round.3, scalb.3, scalbln.3, scandir.3, sched_getcpu.3, seekdir.3, sem_close.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_open.3, sem_post.3, sem_unlink.3, sem_wait.3, setenv.3, setlocale.3, setlogmask.3, shm_open.3, siginterrupt.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sigwait.3, sin.3, sinh.3, sleep.3, sockatmark.3, sqrt.3, statvfs.3, stdio_ext.3, stpcpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strdup.3, strerror.3, strfry.3, strftime.3, string.3, strlen.3, strpbrk.3, strptime.3, strsep.3, strsignal.3, strspn.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, sysconf.3, syslog.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, timegm.3, timeradd.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, trunc.3, tsearch.3, ttyslot.3, tzset.3, ulimit.3, undocumented.3, unlocked_stdio.3, usleep.3, y0.3, cpuid.4, full.4, initrd.4, mouse.4, msr.4, sd.4, st.4, acct.5, core.5, services.5, slabinfo.5, aio.7, capabilities.7, credentials.7, feature_test_macros.7, hier.7, inotify.7, libc.7, locale.7, man-pages.7, man.7, math_error.7, mq_overview.7, numa.7, path_resolution.7, pipe.7, pthreads.7, pty.7, rtld-audit.7, sem_overview.7, shm_overview.7, sigevent.7, signal.7, suffixes.7, svipc.7, termio.7, time.7, udplite.7, units.7, uri.7, sln.8: s/LICENSE_START(verbatim)/LICENSE_START(VERBATIM)/ Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 09:29:01 +00:00
.\" %%%LICENSE_START(VERBATIM)
2004-11-03 13:51:07 +00:00
.\" 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.
.\"
2004-11-03 13:51:07 +00:00
.\" 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.
.\"
2004-11-03 13:51:07 +00:00
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clock_getres.2, clock_nanosleep.2, close.2, connect.2, delete_module.2, dup.2, execve.2, exit_group.2, faccessat.2, fchmodat.2, fchownat.2, fcntl.2, fork.2, fstatat.2, fsync.2, futimesat.2, get_robust_list.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getpagesize.2, getpid.2, getresuid.2, getrlimit.2, getrusage.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, idle.2, init_module.2, intro.2, iopl.2, kcmp.2, kexec_load.2, kill.2, link.2, linkat.2, llseek.2, lookup_dcookie.2, madvise.2, mincore.2, mkdirat.2, mknodat.2, mmap.2, mmap2.2, mount.2, mprotect.2, mq_getsetattr.2, msgctl.2, msgget.2, msgop.2, msync.2, nice.2, open.2, openat.2, pause.2, perfmonctl.2, personality.2, pipe.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, quotactl.2, read.2, readahead.2, readdir.2, readlinkat.2, readv.2, reboot.2, recvmmsg.2, remap_file_pages.2, rename.2, renameat.2, rmdir.2, rt_sigqueueinfo.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, sendmmsg.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setresuid.2, setuid.2, setup.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, signal.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, splice.2, stat.2, statfs.2, stime.2, subpage_prot.2, swapon.2, symlink.2, symlinkat.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysfs.2, syslog.2, tee.2, time.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, times.2, tkill.2, umask.2, umount.2, uname.2, unlink.2, unlinkat.2, uselib.2, ustat.2, utime.2, utimensat.2, vfork.2, vhangup.2, vm86.2, vmsplice.2, wait.2, wait4.2, write.2, CPU_SET.3, INFINITY.3, abort.3, abs.3, acos.3, acosh.3, adjtime.3, aio_init.3, asin.3, asinh.3, asprintf.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atexit.3, atof.3, atoi.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, bsearch.3, bstring.3, byteorder.3, bzero.3, catgets.3, catopen.3, cbrt.3, ceil.3, clearenv.3, clock.3, clock_getcpuclockid.3, closedir.3, confstr.3, copysign.3, cos.3, cosh.3, ctermid.3, ctime.3, difftime.3, dirfd.3, div.3, dl_iterate_phdr.3, dprintf.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, end.3, endian.3, erf.3, erfc.3, ether_aton.3, euidaccess.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fcloseall.3, fexecve.3, ffs.3, fgetgrent.3, fgetpwent.3, finite.3, flockfile.3, floor.3, fmod.3, fnmatch.3, fopencookie.3, fpathconf.3, fpurge.3, frexp.3, fseeko.3, ftok.3, futimes.3, gcvt.3, get_nprocs_conf.3, getaddrinfo.3, getaddrinfo_a.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrnam.3, getgrouplist.3, gethostbyname.3, gethostid.3, getifaddrs.3, getipnodebyname.3, getline.3, getlogin.3, getmntent.3, getnetent.3, getnetent_r.3, getopt.3, getprotoent.3, getprotoent_r.3, getpw.3, getpwent.3, getpwnam.3, getrpcent_r.3, gets.3, getservent.3, getservent_r.3, getumask.3, getusershell.3, getutmp.3, getw.3, glob.3, gnu_get_libc_version.3, gsignal.3, hypot.3, if_nameindex.3, if_nametoindex.3, ilogb.3, index.3, inet.3, inet_ntop.3, inet_pton.3, infnan.3, initgroups.3, insque.3, intro.3, isalpha.3, isatty.3, j0.3, ldexp.3, localeconv.3, log.3, log10.3, log1p.3, log2.3, logb.3, lrint.3, lround.3, lsearch.3, lseek64.3, makecontext.3, makedev.3, mallinfo.3, malloc.3, malloc_get_state.3, malloc_info.3, malloc_stats.3, malloc_trim.3, malloc_usable_size.3, mallopt.3, matherr.3, mcheck.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, memset.3, mkdtemp.3, mkfifo.3, mkfifoat.3, mkstemp.3, mktemp.3, modf.3, mq_close.3, mq_getattr.3, mq_notify.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, on_exit.3, opendir.3, posix_fallocate.3, posix_memalign.3, posix_openpt.3, pow.3, pow10.3, profil.3, psignal.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_cleanup_push_defer_np.3, pthread_create.3, pthread_detach.3, pthread_equal.3, pthread_exit.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_join.3, pthread_kill.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_setschedprio.3, pthread_sigmask.3, pthread_sigqueue.3, pthread_testcancel.3, pthread_tryjoin_np.3, pthread_yield.3, putenv.3, putpwent.3, puts.3, qecvt.3, qsort.3, raise.3, rand.3, random.3, random_r.3, re_comp.3, readdir.3, realpath.3, regex.3, remainder.3, remove.3, resolver.3, rewinddir.3, rint.3, round.3, scalb.3, scalbln.3, scandir.3, sched_getcpu.3, seekdir.3, sem_close.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_open.3, sem_post.3, sem_unlink.3, sem_wait.3, setenv.3, setlocale.3, setlogmask.3, shm_open.3, siginterrupt.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sigwait.3, sin.3, sinh.3, sleep.3, sockatmark.3, sqrt.3, statvfs.3, stdio_ext.3, stpcpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strdup.3, strerror.3, strfry.3, strftime.3, string.3, strlen.3, strpbrk.3, strptime.3, strsep.3, strsignal.3, strspn.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, sysconf.3, syslog.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, timegm.3, timeradd.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, trunc.3, tsearch.3, ttyslot.3, tzset.3, ulimit.3, undocumented.3, unlocked_stdio.3, usleep.3, y0.3, cpuid.4, full.4, initrd.4, mouse.4, msr.4, sd.4, st.4, acct.5, core.5, services.5, slabinfo.5, aio.7, capabilities.7, credentials.7, feature_test_macros.7, hier.7, inotify.7, libc.7, locale.7, man-pages.7, man.7, math_error.7, mq_overview.7, numa.7, path_resolution.7, pipe.7, pthreads.7, pty.7, rtld-audit.7, sem_overview.7, shm_overview.7, sigevent.7, signal.7, suffixes.7, svipc.7, termio.7, time.7, udplite.7, units.7, uri.7, sln.8: Global fix: Add LICENSE_START(verbatim) Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 09:28:40 +00:00
.\" %%%LICENSE_END
2004-11-03 13:51:07 +00:00
.\"
.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
.\" Modified 1995-09-26 by Andries Brouwer <aeb@cwi.nl>
.\" and again on 960413 and 980804 and 981223.
.\" Modified 1998-12-11 by Jamie Lokier <jamie@imbolc.ucc.ie>
.\" Applied correction by Christian Ehrhardt - aeb, 990712
2007-09-20 06:52:22 +00:00
.\" Modified 2002-04-23 by Michael Kerrisk <mtk.manpages@gmail.com>
2004-11-03 13:51:07 +00:00
.\" Added note on F_SETFL and O_DIRECT
.\" Complete rewrite + expansion of material on file locking
.\" Incorporated description of F_NOTIFY, drawing on
.\" Stephen Rothwell's notes in Documentation/dnotify.txt.
.\" Added description of F_SETLEASE and F_GETLEASE
.\" Corrected and polished, aeb, 020527.
2007-09-20 06:52:22 +00:00
.\" Modified 2004-03-03 by Michael Kerrisk <mtk.manpages@gmail.com>
2004-11-03 13:51:07 +00:00
.\" Modified description of file leases: fixed some errors of detail
.\" Replaced the term "lease contestant" by "lease breaker"
2007-09-20 06:52:22 +00:00
.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
2004-11-03 13:51:07 +00:00
.\" Added notes on capability requirements
.\" Modified 2004-12-08, added O_NOATIME after note from Martin Pool
.\" 2004-12-10, mtk, noted F_GETOWN bug after suggestion from aeb.
.\" 2005-04-08 Jamie Lokier <jamie@shareable.org>, mtk
.\" Described behavior of F_SETOWN/F_SETSIG in
.\" multithreaded processes, and generally cleaned
.\" up the discussion of F_SETOWN.
.\" 2005-05-20, Johannes Nicolai <johannes.nicolai@hpi.uni-potsdam.de>,
Noted F_SETOWN bug for socket file descriptor in Linux 2.4 and earlier. Added text on permissions required to send signal to owner. ==== Hello Johannes, > Betreff: Inaccuracy of fcntl man page > Datum: Mon, 2 May 2005 20:07:12 +0200 Thanks for yor note. Sorry for the delay in getting back to you. I needed to find time to set aside to look at the details. Now I've finally got there. > I have attached a simple program Thanks -- a little program is always helpful. > that uses the fcntl system call in order > to kill an arbitrary process of the same user. > According to the fcntl man page, fcntl(fd,F_SETOWN,pid) returns zero if > it has success. Yes. > If you strace the program while killing for exampe man running in another > terminal, you will see that man is killed, but fcntl(fd,F_SETOWN,pid) > will return EPERM, I confirm that I see this problem in 2.4, with both Unix domain and Internet domain sockets. > where you can only find a very confusing explanation > in the fcntl man page. I'm not sure what explanation you mean here. As far as I can tell, the manual page just doesn't cover this point. > I have looked into the kernel source of 2.4.30 and found out, that > net/core/socket::sock_no_fcntl is the culprit if you use fcntl on Unix > sockets. Yes, looks that way to me, as well, And the 2.2 code looks similar. > If pid is not your own pid or not your own process group, > the system call will return EPERM but will also set the pid > as you wanted to. Yes. > In the 2.6 kernel line, fcntl will react according the specification in > the manual page. Yes. > If you also think, that one should clarify the return specification of > fcntl(fd,F_SETOWN,pid) or 2.4.x kernels, please tell me and I will > provide you with a patch for the manual page. In fact I've written some new text under BUGS, which describes the problem: In Linux 2.4 and earlier, there is bug that can occur when an unprivileged process uses F_SETOWN to specify the owner of a socket file descriptor as a process (group) other than the caller. In this case, fcntl() can return -1 with errno set to EPERM, even when the owner process (group) is one that the caller has permission to send signals to. Despite this error return, the file descriptor owner is set, and signals will be sent to the owner. Does that seem okay to you? > Furthermore, it would be interseting to write there, what permissions > one need in order to send signals to processes via fcntl Good idea. I added the following new text: Sending a signal to the owner process (group) specified by F_SETOWN is subject to the same permissions checks as are described for kill(2), where the sending process is the one that employs F_SETOWN (but see BUGS below). ==== #define _GNU_SOURCE /* needed to get the defines */ #include <fcntl.h> /* in glibc 2.2 this has the needed values defined */ #include <signal.h> #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> /** * Funnykill kills a program with fcntl **/ int main (int argc, char **argv) { if (argc != 2) { fprintf (stderr, "Usage: funnykill <pid>\n"); return 1; } int sockets[2]; socketpair (AF_UNIX, SOCK_STREAM, 0, sockets); if (fcntl (sockets[0], F_SETFL, O_ASYNC | O_NONBLOCK) == -1) errMsg("fcntl-F_SETFL"); if (fcntl (sockets[0], F_SETOWN, atoi (argv[1])) == -1) errMsg("fcntl-F_SETOWN"); // fcntl (sockets[0], F_SETOWN, getpid()); if (fcntl (sockets[0], F_SETSIG, SIGKILL) == -1) errMsg("fcntl-_FSETSIG"); write (sockets[1], "good bye", 9); }
2005-05-20 12:11:25 +00:00
.\" mtk: Noted F_SETOWN bug for socket file descriptor in Linux 2.4
.\" and earlier. Added text on permissions required to send signal.
.\" 2009-09-30, Michael Kerrisk
.\" Note obsolete F_SETOWN behavior with threads.
.\" Document F_SETOWN_EX and F_GETOWN_EX
.\" 2010-06-17, Michael Kerrisk
.\" Document F_SETPIPE_SZ and F_GETPIPE_SZ.
2004-11-03 13:51:07 +00:00
.\"
.TH FCNTL 2 2014-05-21 "Linux" "Linux Programmer's Manual"
2004-11-03 13:51:07 +00:00
.SH NAME
fcntl \- manipulate file descriptor
.SH SYNOPSIS
.nf
.B #include <unistd.h>
.B #include <fcntl.h>
.sp
.BI "int fcntl(int " fd ", int " cmd ", ... /* " arg " */ );"
2004-11-03 13:51:07 +00:00
.fi
.SH DESCRIPTION
.BR fcntl ()
performs one of the operations described below on the open file descriptor
2004-11-03 13:51:07 +00:00
.IR fd .
The operation is determined by
2004-11-03 13:51:07 +00:00
.IR cmd .
.BR fcntl ()
can take an optional third argument.
Whether or not this argument is required is determined by
.IR cmd .
2008-11-19 19:32:47 +00:00
The required argument type is indicated in parentheses after each
.I cmd
name (in most cases, the required type is
.IR int ,
and we identify the argument using the name
.IR arg ),
or
.I void
is specified if the argument is not required.
Certain of the operations below are supported only since a particular
Linux kernel version.
The preferred method of checking whether the host kernel supports
a particular operation is to invoke
.BR fcntl ()
with the desired
.IR cmd
value and then test whether the call failed with
.BR EINVAL ,
indicating that the kernel does not recognize this value.
.SS Duplicating a file descriptor
2004-11-03 13:51:07 +00:00
.TP
.BR F_DUPFD " (\fIint\fP)"
2004-11-03 13:51:07 +00:00
Find the lowest numbered available file descriptor
greater than or equal to
.I arg
and make it be a copy of
.IR fd .
This is different from
.BR dup2 (2),
2004-11-03 13:51:07 +00:00
which uses exactly the descriptor specified.
2008-01-01 14:13:55 +00:00
.IP
2004-11-03 13:51:07 +00:00
On success, the new descriptor is returned.
2008-01-01 14:13:55 +00:00
.IP
See
.BR dup (2)
for further details.
2007-11-29 17:59:49 +00:00
.TP
.BR F_DUPFD_CLOEXEC " (\fIint\fP; since Linux 2.6.24)"
2008-04-08 13:04:03 +00:00
As for
2007-11-29 17:59:49 +00:00
.BR F_DUPFD ,
but additionally set the
close-on-exec flag for the duplicate descriptor.
Specifying this flag permits a program to avoid an additional
.BR fcntl ()
2007-11-29 17:59:49 +00:00
.B F_SETFD
operation to set the
.B FD_CLOEXEC
flag.
For an explanation of why this flag is useful,
2007-12-28 04:39:57 +00:00
see the description of
2007-11-29 17:59:49 +00:00
.B O_CLOEXEC
in
.BR open (2).
.SS File descriptor flags
The following commands manipulate the flags associated with
a file descriptor.
Currently, only one such flag is defined:
.BR FD_CLOEXEC ,
the close-on-exec flag.
If the
2004-11-03 13:51:07 +00:00
.B FD_CLOEXEC
bit is 0, the file descriptor will remain open across an
.BR execve (2),
2004-11-03 13:51:07 +00:00
otherwise it will be closed.
.TP
.BR F_GETFD " (\fIvoid\fP)"
Read the file descriptor flags;
.I arg
is ignored.
.TP
.BR F_SETFD " (\fIint\fP)"
Set the file descriptor flags to the value specified by
2004-11-03 13:51:07 +00:00
.IR arg .
.PP
In multithreaded programs, using
.BR fcntl ()
.B F_SETFD
to set the close-on-exec flag at the same time as another thread performs a
.BR fork (2)
plus
.BR execve (2)
is vulnerable to a race condition that may unintentionally leak
the file descriptor to the program executed in the child process.
See the discussion of the
.BR O_CLOEXEC
flag in
.BR open (2)
for details and a remedy to the problem.
.SS File status flags
2005-06-27 14:42:40 +00:00
Each open file description has certain associated status flags,
initialized by
2004-11-03 13:51:07 +00:00
.BR open (2)
.\" or
.\" .BR creat (2),
and possibly modified by
.BR fcntl ().
Duplicated file descriptors
(made with
.BR dup (2),
.BR fcntl (F_DUPFD),
.BR fork (2),
etc.) refer to the same open file description, and thus
share the same file status flags.
2008-01-01 14:13:55 +00:00
The file status flags and their semantics are described in
2004-11-03 13:51:07 +00:00
.BR open (2).
.TP
.BR F_GETFL " (\fIvoid\fP)"
Get the file access mode and the file status flags;
.I arg
is ignored.
2004-11-03 13:51:07 +00:00
.TP
.BR F_SETFL " (\fIint\fP)"
Set the file status flags to the value specified by
2004-11-03 13:51:07 +00:00
.IR arg .
File access mode
.RB ( O_RDONLY ", " O_WRONLY ", " O_RDWR )
and file creation flags
2006-02-02 03:25:50 +00:00
(i.e.,
.BR O_CREAT ", " O_EXCL ", " O_NOCTTY ", " O_TRUNC )
in
2004-11-03 13:51:07 +00:00
.I arg
are ignored.
On Linux this command can change only the
.BR O_APPEND ,
.BR O_ASYNC ,
.BR O_DIRECT ,
.BR O_NOATIME ,
and
2007-09-20 16:26:31 +00:00
.B O_NONBLOCK
flags.
It is not possible to change the
.BR O_DSYNC
and
.BR O_SYNC
flags; see BUGS, below.
.SS Advisory record locking
Linux implements traditional ("process-associated") UNIX record locks,
as standardized by POSIX.
For a Linux-specific alternative with better semantics,
see the discussion of open file description locks below.
.BR F_SETLK ,
.BR F_SETLKW ,
and
.BR F_GETLK
2004-11-03 13:51:07 +00:00
are used to acquire, release, and test for the existence of record
locks (also known as byte-range, file-segment, or file-region locks).
The third argument,
.IR lock ,
2004-11-03 13:51:07 +00:00
is a pointer to a structure that has at least the following fields
(in unspecified order).
.in +4n
2004-11-03 13:51:07 +00:00
.nf
.sp
struct flock {
...
short l_type; /* Type of lock: F_RDLCK,
F_WRLCK, F_UNLCK */
short l_whence; /* How to interpret l_start:
SEEK_SET, SEEK_CUR, SEEK_END */
off_t l_start; /* Starting offset for lock */
off_t l_len; /* Number of bytes to lock */
pid_t l_pid; /* PID of process blocking our lock
(set by F_GETLK and F_OFD_GETLK) */
2004-11-03 13:51:07 +00:00
...
};
.fi
.in
2004-11-03 13:51:07 +00:00
.P
The
.IR l_whence ", " l_start ", and " l_len
fields of this structure specify the range of bytes we wish to lock.
Bytes past the end of the file may be locked,
but not bytes before the start of the file.
2004-11-03 13:51:07 +00:00
.I l_start
is the starting offset for the lock, and is interpreted
relative to either:
the start of the file (if
.I l_whence
is
.BR SEEK_SET );
the current file offset (if
.I l_whence
is
.BR SEEK_CUR );
or the end of the file (if
.I l_whence
is
.BR SEEK_END ).
In the final two cases,
.I l_start
can be a negative number provided the
offset does not lie before the start of the file.
2004-11-03 13:51:07 +00:00
.I l_len
specifies the number of bytes to be locked.
If
.I l_len
is positive, then the range to be locked covers bytes
.I l_start
up to and including
.IR l_start + l_len \-1.
2004-11-03 13:51:07 +00:00
Specifying 0 for
.I l_len
has the special meaning: lock all bytes starting at the
location specified by
.IR l_whence " and " l_start
through to the end of file, no matter how large the file grows.
POSIX.1-2001 allows (but does not require)
an implementation to support a negative
.I l_len
value; if
.I l_len
is negative, the interval described by
.I lock
covers bytes
.IR l_start + l_len
up to and including
.IR l_start \-1.
This is supported by Linux since kernel versions 2.4.21 and 2.5.49.
2004-11-03 13:51:07 +00:00
The
.I l_type
field can be used to place a read
.RB ( F_RDLCK )
or a write
2004-12-06 13:39:28 +00:00
.RB ( F_WRLCK )
2004-11-03 13:51:07 +00:00
lock on a file.
Any number of processes may hold a read lock (shared lock)
on a file region, but only one process may hold a write lock
2007-05-12 12:58:31 +00:00
(exclusive lock).
An exclusive lock excludes all other locks,
2004-11-03 13:51:07 +00:00
both shared and exclusive.
A single process can hold only one type of lock on a file region;
if a new lock is applied to an already-locked region,
2005-07-05 13:50:51 +00:00
then the existing lock is converted to the new lock type.
2004-11-03 13:51:07 +00:00
(Such conversions may involve splitting, shrinking, or coalescing with
an existing lock if the byte range specified by the new lock does not
precisely coincide with the range of the existing lock.)
.TP
.BR F_SETLK " (\fIstruct flock *\fP)"
2004-11-03 13:51:07 +00:00
Acquire a lock (when
.I l_type
is
.B F_RDLCK
or
.BR F_WRLCK )
or release a lock (when
.I l_type
is
.BR F_UNLCK )
on the bytes specified by the
.IR l_whence ", " l_start ", and " l_len
fields of
.IR lock .
If a conflicting lock is held by another process,
this call returns \-1 and sets
.I errno
to
.B EACCES
or
.BR EAGAIN .
(The error returned in this case differs across implementations,
so POSIX requires a portable application to check for both errors.)
2004-11-03 13:51:07 +00:00
.TP
.BR F_SETLKW " (\fIstruct flock *\fP)"
2004-11-03 13:51:07 +00:00
As for
.BR F_SETLK ,
but if a conflicting lock is held on the file, then wait for that
lock to be released.
If a signal is caught while waiting, then the call is interrupted
and (after the signal handler has returned)
returns immediately (with return value \-1 and
.I errno
set to
.BR EINTR ;
see
.BR signal (7)).
2004-11-03 13:51:07 +00:00
.TP
.BR F_GETLK " (\fIstruct flock *\fP)"
2004-11-03 13:51:07 +00:00
On input to this call,
.I lock
describes a lock we would like to place on the file.
If the lock could be placed,
.BR fcntl ()
does not actually place it, but returns
.B F_UNLCK
in the
.I l_type
field of
.I lock
and leaves the other fields of the structure unchanged.
2004-11-03 13:51:07 +00:00
If one or more incompatible locks would prevent
this lock being placed, then
.BR fcntl ()
returns details about one of those locks in the
2004-11-03 13:51:07 +00:00
.IR l_type ", " l_whence ", " l_start ", and " l_len
fields of
.IR lock .
If the conflicting lock is a traditional (process-associated) record lock,
then the
2004-11-03 13:51:07 +00:00
.I l_pid
field is set to the PID of the process holding that lock.
If the conflicting lock is an open file description lock, then
.I l_pid
is set to \-1.
Note that the returned information
may already be out of date by the time the caller inspects it.
2004-11-03 13:51:07 +00:00
.P
In order to place a read lock,
.I fd
must be open for reading.
In order to place a write lock,
.I fd
must be open for writing.
To place both types of lock, open a file read-write.
When placing locks with
.BR F_SETLKW ,
the kernel detects
.IR deadlocks ,
whereby two or more processes have their
lock requests mutually blocked by locks held by the other processes.
For example, suppose process A holds a write lock on byte 100 of a file,
and process B holds a write lock on byte 200.
If each process then attempts to lock the byte already
locked by the other process using
.BR F_SETLKW ,
then, without deadlock detection,
both processes would remain blocked indefinitely.
When the kernel detects such deadlocks,
it causes one of the blocking lock requests to immediately fail with the error
.BR EDEADLK ;
an application that encounters such an error should release
some of its locks to allow other applications to proceed before
attempting regain the locks that it requires.
Circular deadlocks involving more than two processes are also detected.
Note, however, that there are limitations to the kernel's
deadlock-detection algorithm; see BUGS.
2004-11-03 13:51:07 +00:00
As well as being removed by an explicit
.BR F_UNLCK ,
record locks are automatically released when the process terminates.
2004-11-03 13:51:07 +00:00
.P
Record locks are not inherited by a child created via
.BR fork (2),
but are preserved across an
.BR execve (2).
.P
Because of the buffering performed by the
.BR stdio (3)
library, the use of record locking with routines in that package
should be avoided; use
2005-10-19 13:48:50 +00:00
.BR read (2)
and
2005-10-19 13:48:50 +00:00
.BR write (2)
2004-11-03 13:51:07 +00:00
instead.
The record locks described above are associated with the process
(unlike the open file description locks described below).
This has some unfortunate consequences:
.IP * 3
If a process closes
.I any
file descriptor referring to a file,
then all of the process's locks on that file are released,
regardless of the file descriptor(s) on which the locks were obtained.
.\" (Additional file descriptors referring to the same file
.\" may have been obtained by calls to
.\" .BR open "(2), " dup "(2), " dup2 "(2), or " fcntl ().)
This is bad: it means that a process can lose its locks on
a file such as
.I /etc/passwd
or
.I /etc/mtab
when for some reason a library function decides to open, read,
and close the same file.
.IP *
The threads in a process share locks.
In other words,
a multithreaded program can't use record locking to ensure
that threads don't simultaneously access the same region of a file.
.PP
Open file description locks solve both of these problems.
.SS Open file description locks (non-POSIX)
Open file description locks are advisory byte-range locks whose operation is
in most respects identical to the traditional record locks described above.
This lock type is Linux-specific,
and available since Linux 3.15.
For an explanation of open file descriptions, see
.BR open (2)
The principal difference between the two lock types
is that whereas traditional record locks
are associated with a process,
open file description locks are associated with the
open file description on which they are acquired,
much like locks acquired with
.BR flock (2).
Consequently (and unlike traditional advisory record locks),
open file description locks are inherited across
.BR fork (2)
(and
.BR clone (2)
with
.BR CLONE_FILES ),
and are only automatically released on the last close
of the open file description,
instead of being released on any close of the file.
.PP
Open file description locks always conflict with traditional record locks,
even when they are acquired by the same process on the same file descriptor.
Open file description locks placed via the same open file description
(i.e., via the same file descriptor,
or via a duplicate of the file descriptor created by
.BR fork (2),
.BR dup (2),
.BR fcntl (2)
.BR F_DUPFD ,
and so on) are always compatible:
if a new lock is placed on an already locked region,
then the existing lock is converted to the new lock type.
(Such conversions may result in splitting, shrinking, or coalescing with
an existing lock as discussed above.)
On the other hand, open file description locks may conflict with
each other when they are acquired via different open file descriptions.
Thus, the threads in a multithreaded program can use
open file description locks to synchronize access to a file region
by having each thread perform its own
.BR open (2)
on the file and applying locks via the resulting file descriptor.
.PP
As with traditional advisory locks, the third argument to
.BR fcntl (),
.IR lock ,
is a pointer to an
.IR flock
structure.
By contrast with traditional record locks, the
.I l_pid
field of that structure must be set to zero
when using the commands described below.
The commands for working with open file description locks are analogous
to those used with traditional locks:
.TP
.BR F_OFD_SETLK " (\fIstruct flock *\fP)"
Acquire an open file description lock (when
.I l_type
is
.B F_RDLCK
or
.BR F_WRLCK )
or release an open file description lock (when
.I l_type
is
.BR F_UNLCK )
on the bytes specified by the
.IR l_whence ", " l_start ", and " l_len
fields of
.IR lock .
If a conflicting lock is held by another process,
this call returns \-1 and sets
.I errno
to
.BR EAGAIN .
.TP
.BR F_OFD_SETLKW " (\fIstruct flock *\fP)"
As for
.BR F_OFD_SETLK ,
but if a conflicting lock is held on the file, then wait for that lock to be
released.
If a signal is caught while waiting, then the call is interrupted
and (after the signal handler has returned) returns immediately
(with return value \-1 and
.I errno
set to
.BR EINTR ;
see
.BR signal (7)).
.TP
.BR F_OFD_GETLK " (\fIstruct flock *\fP)"
On input to this call,
.I lock
describes an open file description lock we would like to place on the file.
If the lock could be placed,
.BR fcntl ()
does not actually place it, but returns
.B F_UNLCK
in the
.I l_type
field of
.I lock
and leaves the other fields of the structure unchanged.
If one or more incompatible locks would prevent this lock being placed,
then details about one of these locks are returned via
.IR lock ,
as described above for
.BR F_GETLK .
.PP
In the current implementation,
.\" commit 57b65325fe34ec4c917bc4e555144b4a94d9e1f7
no deadlock detection is performed for open file description locks.
(This contrasts with process-associated record locks,
for which the kernel does perform deadlock detection.)
.\"
.SS Mandatory locking
.IR Warning :
the Linux implementation of mandatory locking is unreliable.
See BUGS below.
By default, both traditional (process-associated) and open file description
record locks are advisory.
2004-11-03 13:51:07 +00:00
Advisory locks are not enforced and are useful only between
cooperating processes.
Both lock types can also be mandatory.
Mandatory locks are enforced for all processes.
If a process tries to perform an incompatible access (e.g.,
.BR read (2)
or
.BR write (2))
on a file region that has an incompatible mandatory lock,
then the result depends upon whether the
.B O_NONBLOCK
flag is enabled for its open file description.
If the
.B O_NONBLOCK
flag is not enabled, then
the system call is blocked until the lock is removed
or converted to a mode that is compatible with the access.
If the
.B O_NONBLOCK
flag is enabled, then the system call fails with the error
.BR EAGAIN .
To make use of mandatory locks, mandatory locking must be enabled
intro.1, time.1, access.2, acct.2, alloc_hugepages.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clone.2, close.2, execve.2, fallocate.2, fcntl.2, getdents.2, getrusage.2, getxattr.2, init_module.2, inotify_add_watch.2, ioprio_set.2, kcmp.2, link.2, listxattr.2, lseek.2, madvise.2, mkdir.2, mknod.2, mmap.2, mount.2, move_pages.2, msgctl.2, nfsservctl.2, open.2, pivot_root.2, quotactl.2, read.2, readlink.2, removexattr.2, rename.2, rmdir.2, semctl.2, setfsgid.2, setfsuid.2, setresuid.2, setuid.2, setup.2, setxattr.2, shmctl.2, splice.2, spu_create.2, stat.2, statfs.2, swapon.2, symlink.2, sync.2, sync_file_range.2, sysfs.2, truncate.2, umount.2, unlink.2, unshare.2, ustat.2, utime.2, utimensat.2, write.2, btree.3, errno.3, fexecve.3, ftw.3, futimes.3, get_nprocs_conf.3, getcwd.3, getdirentries.3, getmntent.3, glob.3, mkfifo.3, mq_open.3, readdir.3, realpath.3, recno.3, remove.3, sem_open.3, shm_open.3, statvfs.3, sysconf.3, telldir.3, tmpfile.3, cciss.4, initrd.4, pts.4, sk98lin.4, vcs.4, core.5, filesystems.5, proc.5, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, feature_test_macros.7, fifo.7, hier.7, inotify.7, intro.7, mq_overview.7, path_resolution.7, pipe.7, sem_overview.7, shm_overview.7, spufs.7, symlink.7, unix.7, uri.7, sync.8: Global fix: s/file system/filesystem/ Notwithstanding 24d01c530c5a3f75217543d02bf6712395e5f90c, "filesystem" is the form used by the great majority of man pages outside the man-pages project and in a number of other sources, so let's go with that. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-08-08 08:07:57 +00:00
both on the filesystem that contains the file to be locked,
and on the file itself.
intro.1, time.1, access.2, acct.2, alloc_hugepages.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clone.2, close.2, execve.2, fallocate.2, fcntl.2, getdents.2, getrusage.2, getxattr.2, init_module.2, inotify_add_watch.2, ioprio_set.2, kcmp.2, link.2, listxattr.2, lseek.2, madvise.2, mkdir.2, mknod.2, mmap.2, mount.2, move_pages.2, msgctl.2, nfsservctl.2, open.2, pivot_root.2, quotactl.2, read.2, readlink.2, removexattr.2, rename.2, rmdir.2, semctl.2, setfsgid.2, setfsuid.2, setresuid.2, setuid.2, setup.2, setxattr.2, shmctl.2, splice.2, spu_create.2, stat.2, statfs.2, swapon.2, symlink.2, sync.2, sync_file_range.2, sysfs.2, truncate.2, umount.2, unlink.2, unshare.2, ustat.2, utime.2, utimensat.2, write.2, btree.3, errno.3, fexecve.3, ftw.3, futimes.3, get_nprocs_conf.3, getcwd.3, getdirentries.3, getmntent.3, glob.3, mkfifo.3, mq_open.3, readdir.3, realpath.3, recno.3, remove.3, sem_open.3, shm_open.3, statvfs.3, sysconf.3, telldir.3, tmpfile.3, cciss.4, initrd.4, pts.4, sk98lin.4, vcs.4, core.5, filesystems.5, proc.5, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, feature_test_macros.7, fifo.7, hier.7, inotify.7, intro.7, mq_overview.7, path_resolution.7, pipe.7, sem_overview.7, shm_overview.7, spufs.7, symlink.7, unix.7, uri.7, sync.8: Global fix: s/file system/filesystem/ Notwithstanding 24d01c530c5a3f75217543d02bf6712395e5f90c, "filesystem" is the form used by the great majority of man pages outside the man-pages project and in a number of other sources, so let's go with that. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-08-08 08:07:57 +00:00
Mandatory locking is enabled on a filesystem
using the "\-o mand" option to
.BR mount (8),
or the
.B MS_MANDLOCK
flag for
.BR mount (2).
Mandatory locking is enabled on a file by disabling
group execute permission on the file and enabling the set-group-ID
permission bit (see
.BR chmod (1)
and
.BR chmod (2)).
Mandatory locking is not specified by POSIX.
Some other systems also support mandatory locking,
although the details of how to enable it vary across systems.
.SS Managing signals
.BR F_GETOWN ,
.BR F_SETOWN ,
.BR F_GETOWN_EX ,
.BR F_SETOWN_EX ,
.BR F_GETSIG
and
.B F_SETSIG
2004-11-03 13:51:07 +00:00
are used to manage I/O availability signals:
.TP
.BR F_GETOWN " (\fIvoid\fP)"
Return (as the function result)
the process ID or process group currently receiving
2007-06-21 05:38:48 +00:00
.B SIGIO
and
.B SIGURG
signals for events on file descriptor
2004-11-03 13:51:07 +00:00
.IR fd .
Process IDs are returned as positive values;
process group IDs are returned as negative values (but see BUGS below).
.I arg
is ignored.
2004-11-03 13:51:07 +00:00
.TP
.BR F_SETOWN " (\fIint\fP)"
2007-06-21 05:38:48 +00:00
Set the process ID or process group ID that will receive
.B SIGIO
and
.B SIGURG
signals for events on file descriptor
.IR fd
to the ID given in
.IR arg .
A process ID is specified as a positive value;
a process group ID is specified as a negative value.
Noted F_SETOWN bug for socket file descriptor in Linux 2.4 and earlier. Added text on permissions required to send signal to owner. ==== Hello Johannes, > Betreff: Inaccuracy of fcntl man page > Datum: Mon, 2 May 2005 20:07:12 +0200 Thanks for yor note. Sorry for the delay in getting back to you. I needed to find time to set aside to look at the details. Now I've finally got there. > I have attached a simple program Thanks -- a little program is always helpful. > that uses the fcntl system call in order > to kill an arbitrary process of the same user. > According to the fcntl man page, fcntl(fd,F_SETOWN,pid) returns zero if > it has success. Yes. > If you strace the program while killing for exampe man running in another > terminal, you will see that man is killed, but fcntl(fd,F_SETOWN,pid) > will return EPERM, I confirm that I see this problem in 2.4, with both Unix domain and Internet domain sockets. > where you can only find a very confusing explanation > in the fcntl man page. I'm not sure what explanation you mean here. As far as I can tell, the manual page just doesn't cover this point. > I have looked into the kernel source of 2.4.30 and found out, that > net/core/socket::sock_no_fcntl is the culprit if you use fcntl on Unix > sockets. Yes, looks that way to me, as well, And the 2.2 code looks similar. > If pid is not your own pid or not your own process group, > the system call will return EPERM but will also set the pid > as you wanted to. Yes. > In the 2.6 kernel line, fcntl will react according the specification in > the manual page. Yes. > If you also think, that one should clarify the return specification of > fcntl(fd,F_SETOWN,pid) or 2.4.x kernels, please tell me and I will > provide you with a patch for the manual page. In fact I've written some new text under BUGS, which describes the problem: In Linux 2.4 and earlier, there is bug that can occur when an unprivileged process uses F_SETOWN to specify the owner of a socket file descriptor as a process (group) other than the caller. In this case, fcntl() can return -1 with errno set to EPERM, even when the owner process (group) is one that the caller has permission to send signals to. Despite this error return, the file descriptor owner is set, and signals will be sent to the owner. Does that seem okay to you? > Furthermore, it would be interseting to write there, what permissions > one need in order to send signals to processes via fcntl Good idea. I added the following new text: Sending a signal to the owner process (group) specified by F_SETOWN is subject to the same permissions checks as are described for kill(2), where the sending process is the one that employs F_SETOWN (but see BUGS below). ==== #define _GNU_SOURCE /* needed to get the defines */ #include <fcntl.h> /* in glibc 2.2 this has the needed values defined */ #include <signal.h> #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> /** * Funnykill kills a program with fcntl **/ int main (int argc, char **argv) { if (argc != 2) { fprintf (stderr, "Usage: funnykill <pid>\n"); return 1; } int sockets[2]; socketpair (AF_UNIX, SOCK_STREAM, 0, sockets); if (fcntl (sockets[0], F_SETFL, O_ASYNC | O_NONBLOCK) == -1) errMsg("fcntl-F_SETFL"); if (fcntl (sockets[0], F_SETOWN, atoi (argv[1])) == -1) errMsg("fcntl-F_SETOWN"); // fcntl (sockets[0], F_SETOWN, getpid()); if (fcntl (sockets[0], F_SETSIG, SIGKILL) == -1) errMsg("fcntl-_FSETSIG"); write (sockets[1], "good bye", 9); }
2005-05-20 12:11:25 +00:00
Most commonly, the calling process specifies itself as the owner
(that is,
.I arg
is specified as
.BR getpid (2)).
2004-11-03 13:51:07 +00:00
.\" From glibc.info:
If you set the
.B O_ASYNC
status flag on a file descriptor by using the
2004-11-03 13:51:07 +00:00
.B F_SETFL
command of
2007-07-10 03:57:50 +00:00
.BR fcntl (),
2007-06-21 05:38:48 +00:00
a
.B SIGIO
signal is sent whenever input or output becomes possible
2004-11-03 13:51:07 +00:00
on that file descriptor.
.B F_SETSIG
2007-06-21 05:38:48 +00:00
can be used to obtain delivery of a signal other than
.BR SIGIO .
Noted F_SETOWN bug for socket file descriptor in Linux 2.4 and earlier. Added text on permissions required to send signal to owner. ==== Hello Johannes, > Betreff: Inaccuracy of fcntl man page > Datum: Mon, 2 May 2005 20:07:12 +0200 Thanks for yor note. Sorry for the delay in getting back to you. I needed to find time to set aside to look at the details. Now I've finally got there. > I have attached a simple program Thanks -- a little program is always helpful. > that uses the fcntl system call in order > to kill an arbitrary process of the same user. > According to the fcntl man page, fcntl(fd,F_SETOWN,pid) returns zero if > it has success. Yes. > If you strace the program while killing for exampe man running in another > terminal, you will see that man is killed, but fcntl(fd,F_SETOWN,pid) > will return EPERM, I confirm that I see this problem in 2.4, with both Unix domain and Internet domain sockets. > where you can only find a very confusing explanation > in the fcntl man page. I'm not sure what explanation you mean here. As far as I can tell, the manual page just doesn't cover this point. > I have looked into the kernel source of 2.4.30 and found out, that > net/core/socket::sock_no_fcntl is the culprit if you use fcntl on Unix > sockets. Yes, looks that way to me, as well, And the 2.2 code looks similar. > If pid is not your own pid or not your own process group, > the system call will return EPERM but will also set the pid > as you wanted to. Yes. > In the 2.6 kernel line, fcntl will react according the specification in > the manual page. Yes. > If you also think, that one should clarify the return specification of > fcntl(fd,F_SETOWN,pid) or 2.4.x kernels, please tell me and I will > provide you with a patch for the manual page. In fact I've written some new text under BUGS, which describes the problem: In Linux 2.4 and earlier, there is bug that can occur when an unprivileged process uses F_SETOWN to specify the owner of a socket file descriptor as a process (group) other than the caller. In this case, fcntl() can return -1 with errno set to EPERM, even when the owner process (group) is one that the caller has permission to send signals to. Despite this error return, the file descriptor owner is set, and signals will be sent to the owner. Does that seem okay to you? > Furthermore, it would be interseting to write there, what permissions > one need in order to send signals to processes via fcntl Good idea. I added the following new text: Sending a signal to the owner process (group) specified by F_SETOWN is subject to the same permissions checks as are described for kill(2), where the sending process is the one that employs F_SETOWN (but see BUGS below). ==== #define _GNU_SOURCE /* needed to get the defines */ #include <fcntl.h> /* in glibc 2.2 this has the needed values defined */ #include <signal.h> #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> /** * Funnykill kills a program with fcntl **/ int main (int argc, char **argv) { if (argc != 2) { fprintf (stderr, "Usage: funnykill <pid>\n"); return 1; } int sockets[2]; socketpair (AF_UNIX, SOCK_STREAM, 0, sockets); if (fcntl (sockets[0], F_SETFL, O_ASYNC | O_NONBLOCK) == -1) errMsg("fcntl-F_SETFL"); if (fcntl (sockets[0], F_SETOWN, atoi (argv[1])) == -1) errMsg("fcntl-F_SETOWN"); // fcntl (sockets[0], F_SETOWN, getpid()); if (fcntl (sockets[0], F_SETSIG, SIGKILL) == -1) errMsg("fcntl-_FSETSIG"); write (sockets[1], "good bye", 9); }
2005-05-20 12:11:25 +00:00
If this permission check fails, then the signal is
silently discarded.
Sending a signal to the owner process (group) specified by
.B F_SETOWN
is subject to the same permissions checks as are described for
.BR kill (2),
where the sending process is the one that employs
2007-09-20 16:26:31 +00:00
.B F_SETOWN
Noted F_SETOWN bug for socket file descriptor in Linux 2.4 and earlier. Added text on permissions required to send signal to owner. ==== Hello Johannes, > Betreff: Inaccuracy of fcntl man page > Datum: Mon, 2 May 2005 20:07:12 +0200 Thanks for yor note. Sorry for the delay in getting back to you. I needed to find time to set aside to look at the details. Now I've finally got there. > I have attached a simple program Thanks -- a little program is always helpful. > that uses the fcntl system call in order > to kill an arbitrary process of the same user. > According to the fcntl man page, fcntl(fd,F_SETOWN,pid) returns zero if > it has success. Yes. > If you strace the program while killing for exampe man running in another > terminal, you will see that man is killed, but fcntl(fd,F_SETOWN,pid) > will return EPERM, I confirm that I see this problem in 2.4, with both Unix domain and Internet domain sockets. > where you can only find a very confusing explanation > in the fcntl man page. I'm not sure what explanation you mean here. As far as I can tell, the manual page just doesn't cover this point. > I have looked into the kernel source of 2.4.30 and found out, that > net/core/socket::sock_no_fcntl is the culprit if you use fcntl on Unix > sockets. Yes, looks that way to me, as well, And the 2.2 code looks similar. > If pid is not your own pid or not your own process group, > the system call will return EPERM but will also set the pid > as you wanted to. Yes. > In the 2.6 kernel line, fcntl will react according the specification in > the manual page. Yes. > If you also think, that one should clarify the return specification of > fcntl(fd,F_SETOWN,pid) or 2.4.x kernels, please tell me and I will > provide you with a patch for the manual page. In fact I've written some new text under BUGS, which describes the problem: In Linux 2.4 and earlier, there is bug that can occur when an unprivileged process uses F_SETOWN to specify the owner of a socket file descriptor as a process (group) other than the caller. In this case, fcntl() can return -1 with errno set to EPERM, even when the owner process (group) is one that the caller has permission to send signals to. Despite this error return, the file descriptor owner is set, and signals will be sent to the owner. Does that seem okay to you? > Furthermore, it would be interseting to write there, what permissions > one need in order to send signals to processes via fcntl Good idea. I added the following new text: Sending a signal to the owner process (group) specified by F_SETOWN is subject to the same permissions checks as are described for kill(2), where the sending process is the one that employs F_SETOWN (but see BUGS below). ==== #define _GNU_SOURCE /* needed to get the defines */ #include <fcntl.h> /* in glibc 2.2 this has the needed values defined */ #include <signal.h> #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> /** * Funnykill kills a program with fcntl **/ int main (int argc, char **argv) { if (argc != 2) { fprintf (stderr, "Usage: funnykill <pid>\n"); return 1; } int sockets[2]; socketpair (AF_UNIX, SOCK_STREAM, 0, sockets); if (fcntl (sockets[0], F_SETFL, O_ASYNC | O_NONBLOCK) == -1) errMsg("fcntl-F_SETFL"); if (fcntl (sockets[0], F_SETOWN, atoi (argv[1])) == -1) errMsg("fcntl-F_SETOWN"); // fcntl (sockets[0], F_SETOWN, getpid()); if (fcntl (sockets[0], F_SETSIG, SIGKILL) == -1) errMsg("fcntl-_FSETSIG"); write (sockets[1], "good bye", 9); }
2005-05-20 12:11:25 +00:00
(but see BUGS below).
2008-01-01 14:13:55 +00:00
If the file descriptor
.I fd
refers to a socket,
2004-11-03 13:51:07 +00:00
.B F_SETOWN
also selects
2007-06-21 05:38:48 +00:00
the recipient of
.B SIGURG
signals that are delivered when out-of-band
data arrives on that socket.
2007-06-21 05:38:48 +00:00
.RB ( SIGURG
is sent in any situation where
2004-11-03 13:51:07 +00:00
.BR select (2)
would report the socket as having an "exceptional condition".)
.\" The following appears to be rubbish. It doesn't seem to
.\" be true according to the kernel source, and I can write
.\" a program that gets a terminal-generated SIGIO even though
.\" it is not the foreground process group of the terminal.
.\" -- MTK, 8 Apr 05
.\"
.\" If the file descriptor
.\" .I fd
.\" refers to a terminal device, then SIGIO
.\" signals are sent to the foreground process group of the terminal.
The following was true in 2.6.x kernels up to and including
kernel 2.6.11:
.RS
.IP
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/ The tendency in English, as prescribed in style guides like Chicago MoS, is towards removing hyphens after prefixes like "non-" etc. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
If a nonzero value is given to
.B F_SETSIG
in a multithreaded process running with a threading library
Date: Fri, 28 Jan 2005 11:00:59 +0000 From: Jamie Lokier <jamie@shareable.org> To: mtk-manpages@gmx.net Subject: Update to fcntl(2) man page Hi Michael, I have a correction to the fcntl(2) man page. Under the section for F_SETOWN, which describes how to set the recipient process or group for SIGIO signals, see this paragraph: The process or process group to receive the signal can be selected by using the F_SETOWN command to the fcntl function. If the file descriptor is a socket, this also selects the recip- ient of SIGURG signals that are delivered when out-of-band data arrives on that socket. (SIGURG is sent in any situation where select(2) would report the socket as having an "exceptional con- dition".) If the file descriptor corresponds to a terminal device, then SIGIO signals are sent to the foreground process group of the terminal. I would like to add an additional paragraph: The value given to F_SETOWN has a slightly different meaning when F_SETSIG is used in a multi-threaded process. If a non-zero value is given to F_SETSIG, then a positive value given to F_SETOWN identifies a specific thread within a process, instead of a whole process. The value is a thread id not a process id, so you may need to pass the result of gettid() instead of getpid() to get sensible results when F_SETSIG is used. (Thread ids are different from process ids, although they have the same value for some threads depending on details of the threading library used). Also, this is the first paragraph of the F_SETSIG section: Sets the signal sent when input or output becomes possible. A value of zero means to send the default SIGIO signal. Any other value (including SIGIO) is the signal to send instead, and in this case additional info is available to the signal handler if installed with SA_SIGINFO. I'd like to append another paragraph right after that one: Additionally, passing a non-zero value to F_SETSIG changes the signal recipient from a whole process to a specific thread within a process. The section on F_SETOWN gives more details. Date: Thu, 7 Apr 2005 17:58:59 +0100 From: Jamie Lokier <jamie@shareable.org> To: Michael Kerrisk <mtk-manpages@gmx.net> Subject: Re: Update to fcntl(2) man page [[...]] > I've been trying to follow the kernel source code to verify > the details you describe above. The relevant place is the > 'switch' in fs/fcntl.c::send_sigio_to_task() right? Yes. > Also, for NPTL, perhaps one needs to mention that for the main > thread, gettid() == getpid(), which allows the traditional > use of F_SETSIG / F_SETOWN in programs consisting of a single > thread -- right? Yes, that makes sense. It's also fine for the "main thread" with NPTL, so programs which spawn threads can still use F_SETOWN/F_SETSIG in the main thread using getpid(). Date: Tue, 12 Apr 2005 15:25:49 +0100 From: Jamie Lokier <jamie@shareable.org> To: Michael Kerrisk <mtk-manpages@gmx.net> Subject: Re: Update to fcntl(2) man page Michael Kerrisk wrote: > F_SETOWN > Set the process ID or process group ID that will > receive SIGIO and SIGURG signals for events on > file descriptor fd. A process ID is specified as > a positive value; a process group ID is specified > as a negative value. > > If you set the O_ASYNC status flag on a file > descriptor (either by providing this flag with the > open(2) call, or by using the F_SETFL command of > fcntl), a SIGIO signal is sent whenever input or > output becomes possible on that file descriptor. > F_SETSIG can be used to obtain delivery of a sig&#8208; > nal other than SIGIO. > > If the file descriptor fd refers to a socket, > F_SETOWN also selects the recipient of SIGURG sig&#8208; > nals that are delivered when out-of-band data > arrives on that socket. (SIGURG is sent in any > situation where select(2) would report the socket > as having an "exceptional condition".) > > If a non-zero value is given to F_SETSIG in a > multi-threaded process, then a positive value > value given to F_SETOWN has a different meaning: > instead of being a process ID identifying a whole > process, it is a thread ID identifying a specific > thread within a process. Consequently, it may be > necessary to pass F_SETOWN the result of gettid() > instead of getpid() to get sensible results when > F_SETSIG is used. (In current Linux threading > implementations, a main thread's thread ID is the > same as its process ID. This means that a single- > threaded program can equally use gettid() or get&#8208; > pid() in this scenario.) Note, however, that the > statements in this paragraph do not apply to the > SIGURG signal generated for out-of-band data on a > socket: this signal is always sent to either a > process or a process group, depending on the value > given to F_SETOWN. > > And the first part of the description of F_SETSIG now reads: > > F_SETSIG > Sets the signal sent when input or output becomes > possible. A value of zero means to send the > default SIGIO signal. Any other value (including > SIGIO) is the signal to send instead, and in this > case additional info is available to the signal > handler if installed with SA_SIGINFO. > > Additionally, passing a non-zero value to F_SETSIG > changes the signal recipient from a whole process > to a specific thread within a process. See the > desciption of F_SETOWN for more details. > > Does the above seem okay to you? It looks good, but: 1. An omission: It mentions that SIGURG is always sent to the whole process. SIGIO is also sent to the whole process, instead of queueing a thread-specific signal, when the signal queue is full. Programs that mustn't miss readiness events need to handle it. 2. The description could be confusing to LinuxThreads users, because all the signals are thread-specific in LinuxThreads. Date: Tue, 12 Apr 2005 16:53:19 +0100 From: Jamie Lokier <jamie@shareable.org> To: Michael Kerrisk <mtk-manpages@gmx.net> Subject: Re: Update to fcntl(2) man page Michael Kerrisk wrote: > > 1. An omission: It mentions that SIGURG is always sent to the whole > > process. SIGIO is also sent to the whole process, instead of > > queueing a thread-specific signal, when the signal queue is full. > > Programs that mustn't miss readiness events need to handle it. > > Sorry -- can you point me to the relevant code for the > above point please. In 2.6: switch (fown->signum) { siginfo_t si; default: /* Queue a rt signal with the appropriate fd as its value. We use SI_SIGIO as the source, not SI_KERNEL, since kernel signals always get delivered even if we can't queue. Failure to queue in this case _should_ be reported; we fall back to SIGIO in that case. --sct */ si.si_signo = fown->signum; si.si_errno = 0; si.si_code = reason; /* Make sure we are called with one of the POLL_* reasons, otherwise we could leak kernel stack into userspace. */ if ((reason & __SI_MASK) != __SI_POLL) BUG(); if (reason - POLL_IN >= NSIGPOLL) si.si_band = ~0L; else si.si_band = band_table[reason - POLL_IN]; si.si_fd = fd; if (!send_sig_info(fown->signum, &si, p)) break; /* fall-through: fall back on the old plain SIGIO signal */ case 0: send_group_sig_info(SIGIO, SEND_SIG_PRIV, p); 2.4 is exactly the same, except: /* fall-through: fall back on the old plain SIGIO signal */ case 0: send_sig(SIGIO, p, 1); The fall-through happens when send_sig_info() fails, which happens when the real-time signal queue is full. Programs using a queued signal to track file readiness efficiently (as an alternative to select/poll), must listen for SIGIO in addition to the real-time signal, as otherwise they will miss notifications when the queue is full (which happens often on a busy server). Multi-threaded programs using NPTL must be aware this SIGIO is process-wide - so receiving it on one thread must cause all threads to assume a queued signal may be lost. Programs using LinuxThreads do not have to assume this (but it's safe if they do). Date: Wed, 13 Apr 2005 17:25:44 +0100 From: Jamie Lokier <jamie@shareable.org> To: Michael Kerrisk <mtk-manpages@gmx.net> Subject: Re: Update to fcntl(2) man page Michael Kerrisk wrote: > I added a few more sentences to the end of that paragraph > on F_SETOWN: > > If a non-zero value is given to F_SETSIG in a multi-threaded > process running with a threading library that supports thread > groups (e.g., NPTL), then a positive value value given to > F_SETOWN has a different meaning: instead of being a process ID > identifying a whole process, it is a thread ID identifying a > specific thread within a process. Consequently, it may be nec- > essary to pass F_SETOWN the result of gettid() instead of get > pid() to get sensible results when F_SETSIG is used. (In cur- > rent Linux threading implementations, a main thread's thread ID > is the same as its process ID. This means that a single- > threaded program can equally use gettid() or getpid() in this > scenario.) Note, however, that the statements in this paragraph > do not apply to the SIGURG signal generated for out-of-band data > on a socket: this signal is always sent to either a process or a > process group, depending on the value given to F_SETOWN. Note > also that Linux imposes a limit on the number of real-time sig- > nals that may be queued to a process (see getrlimit(2) and sig- > nal(7)) and if this limit is reached, then the kernel reverts to > delivering SIGIO, and this signal is delivered to the entire > process rather than to a specifc thread. > > Look oay now? Looks ood. It will take a minor genius to translate that to working multi-threaded RT-SIGIO code without a tutorial -- and in fact I haven't heard of any program or library which does it (though I'm trying to write one) -- but technically it seems to include everything.
2005-04-05 05:54:09 +00:00
that supports thread groups (e.g., NPTL),
then a positive value given to
.B F_SETOWN
has a different meaning:
.\" The relevant place in the (2.6) kernel source is the
.\" 'switch' in fs/fcntl.c::send_sigio_to_task() -- MTK, Apr 2005
instead of being a process ID identifying a whole process,
it is a thread ID identifying a specific thread within a process.
Consequently, it may be necessary to pass
.B F_SETOWN
the result of
.BR gettid (2)
instead of
.BR getpid (2)
to get sensible results when
.B F_SETSIG
is used.
(In current Linux threading implementations,
a main thread's thread ID is the same as its process ID.
This means that a single-threaded program can equally use
.BR gettid (2)
or
.BR getpid (2)
in this scenario.)
Note, however, that the statements in this paragraph do not apply
2007-06-21 05:38:48 +00:00
to the
.B SIGURG
signal generated for out-of-band data on a socket:
this signal is always sent to either a process or a process group,
depending on the value given to
.BR F_SETOWN .
.\" send_sigurg()/send_sigurg_to_task() bypasses
.\" kill_fasync()/send_sigio()/send_sigio_to_task()
.\" to directly call send_group_sig_info()
.\" -- MTK, Apr 2005 (kernel 2.6.11)
.RE
.IP
The above behavior was accidentally dropped in Linux 2.6.12,
and won't be restored.
From Linux 2.6.32 onward, use
.BR F_SETOWN_EX
to target
.B SIGIO
Date: Fri, 28 Jan 2005 11:00:59 +0000 From: Jamie Lokier <jamie@shareable.org> To: mtk-manpages@gmx.net Subject: Update to fcntl(2) man page Hi Michael, I have a correction to the fcntl(2) man page. Under the section for F_SETOWN, which describes how to set the recipient process or group for SIGIO signals, see this paragraph: The process or process group to receive the signal can be selected by using the F_SETOWN command to the fcntl function. If the file descriptor is a socket, this also selects the recip- ient of SIGURG signals that are delivered when out-of-band data arrives on that socket. (SIGURG is sent in any situation where select(2) would report the socket as having an "exceptional con- dition".) If the file descriptor corresponds to a terminal device, then SIGIO signals are sent to the foreground process group of the terminal. I would like to add an additional paragraph: The value given to F_SETOWN has a slightly different meaning when F_SETSIG is used in a multi-threaded process. If a non-zero value is given to F_SETSIG, then a positive value given to F_SETOWN identifies a specific thread within a process, instead of a whole process. The value is a thread id not a process id, so you may need to pass the result of gettid() instead of getpid() to get sensible results when F_SETSIG is used. (Thread ids are different from process ids, although they have the same value for some threads depending on details of the threading library used). Also, this is the first paragraph of the F_SETSIG section: Sets the signal sent when input or output becomes possible. A value of zero means to send the default SIGIO signal. Any other value (including SIGIO) is the signal to send instead, and in this case additional info is available to the signal handler if installed with SA_SIGINFO. I'd like to append another paragraph right after that one: Additionally, passing a non-zero value to F_SETSIG changes the signal recipient from a whole process to a specific thread within a process. The section on F_SETOWN gives more details. Date: Thu, 7 Apr 2005 17:58:59 +0100 From: Jamie Lokier <jamie@shareable.org> To: Michael Kerrisk <mtk-manpages@gmx.net> Subject: Re: Update to fcntl(2) man page [[...]] > I've been trying to follow the kernel source code to verify > the details you describe above. The relevant place is the > 'switch' in fs/fcntl.c::send_sigio_to_task() right? Yes. > Also, for NPTL, perhaps one needs to mention that for the main > thread, gettid() == getpid(), which allows the traditional > use of F_SETSIG / F_SETOWN in programs consisting of a single > thread -- right? Yes, that makes sense. It's also fine for the "main thread" with NPTL, so programs which spawn threads can still use F_SETOWN/F_SETSIG in the main thread using getpid(). Date: Tue, 12 Apr 2005 15:25:49 +0100 From: Jamie Lokier <jamie@shareable.org> To: Michael Kerrisk <mtk-manpages@gmx.net> Subject: Re: Update to fcntl(2) man page Michael Kerrisk wrote: > F_SETOWN > Set the process ID or process group ID that will > receive SIGIO and SIGURG signals for events on > file descriptor fd. A process ID is specified as > a positive value; a process group ID is specified > as a negative value. > > If you set the O_ASYNC status flag on a file > descriptor (either by providing this flag with the > open(2) call, or by using the F_SETFL command of > fcntl), a SIGIO signal is sent whenever input or > output becomes possible on that file descriptor. > F_SETSIG can be used to obtain delivery of a sig&#8208; > nal other than SIGIO. > > If the file descriptor fd refers to a socket, > F_SETOWN also selects the recipient of SIGURG sig&#8208; > nals that are delivered when out-of-band data > arrives on that socket. (SIGURG is sent in any > situation where select(2) would report the socket > as having an "exceptional condition".) > > If a non-zero value is given to F_SETSIG in a > multi-threaded process, then a positive value > value given to F_SETOWN has a different meaning: > instead of being a process ID identifying a whole > process, it is a thread ID identifying a specific > thread within a process. Consequently, it may be > necessary to pass F_SETOWN the result of gettid() > instead of getpid() to get sensible results when > F_SETSIG is used. (In current Linux threading > implementations, a main thread's thread ID is the > same as its process ID. This means that a single- > threaded program can equally use gettid() or get&#8208; > pid() in this scenario.) Note, however, that the > statements in this paragraph do not apply to the > SIGURG signal generated for out-of-band data on a > socket: this signal is always sent to either a > process or a process group, depending on the value > given to F_SETOWN. > > And the first part of the description of F_SETSIG now reads: > > F_SETSIG > Sets the signal sent when input or output becomes > possible. A value of zero means to send the > default SIGIO signal. Any other value (including > SIGIO) is the signal to send instead, and in this > case additional info is available to the signal > handler if installed with SA_SIGINFO. > > Additionally, passing a non-zero value to F_SETSIG > changes the signal recipient from a whole process > to a specific thread within a process. See the > desciption of F_SETOWN for more details. > > Does the above seem okay to you? It looks good, but: 1. An omission: It mentions that SIGURG is always sent to the whole process. SIGIO is also sent to the whole process, instead of queueing a thread-specific signal, when the signal queue is full. Programs that mustn't miss readiness events need to handle it. 2. The description could be confusing to LinuxThreads users, because all the signals are thread-specific in LinuxThreads. Date: Tue, 12 Apr 2005 16:53:19 +0100 From: Jamie Lokier <jamie@shareable.org> To: Michael Kerrisk <mtk-manpages@gmx.net> Subject: Re: Update to fcntl(2) man page Michael Kerrisk wrote: > > 1. An omission: It mentions that SIGURG is always sent to the whole > > process. SIGIO is also sent to the whole process, instead of > > queueing a thread-specific signal, when the signal queue is full. > > Programs that mustn't miss readiness events need to handle it. > > Sorry -- can you point me to the relevant code for the > above point please. In 2.6: switch (fown->signum) { siginfo_t si; default: /* Queue a rt signal with the appropriate fd as its value. We use SI_SIGIO as the source, not SI_KERNEL, since kernel signals always get delivered even if we can't queue. Failure to queue in this case _should_ be reported; we fall back to SIGIO in that case. --sct */ si.si_signo = fown->signum; si.si_errno = 0; si.si_code = reason; /* Make sure we are called with one of the POLL_* reasons, otherwise we could leak kernel stack into userspace. */ if ((reason & __SI_MASK) != __SI_POLL) BUG(); if (reason - POLL_IN >= NSIGPOLL) si.si_band = ~0L; else si.si_band = band_table[reason - POLL_IN]; si.si_fd = fd; if (!send_sig_info(fown->signum, &si, p)) break; /* fall-through: fall back on the old plain SIGIO signal */ case 0: send_group_sig_info(SIGIO, SEND_SIG_PRIV, p); 2.4 is exactly the same, except: /* fall-through: fall back on the old plain SIGIO signal */ case 0: send_sig(SIGIO, p, 1); The fall-through happens when send_sig_info() fails, which happens when the real-time signal queue is full. Programs using a queued signal to track file readiness efficiently (as an alternative to select/poll), must listen for SIGIO in addition to the real-time signal, as otherwise they will miss notifications when the queue is full (which happens often on a busy server). Multi-threaded programs using NPTL must be aware this SIGIO is process-wide - so receiving it on one thread must cause all threads to assume a queued signal may be lost. Programs using LinuxThreads do not have to assume this (but it's safe if they do). Date: Wed, 13 Apr 2005 17:25:44 +0100 From: Jamie Lokier <jamie@shareable.org> To: Michael Kerrisk <mtk-manpages@gmx.net> Subject: Re: Update to fcntl(2) man page Michael Kerrisk wrote: > I added a few more sentences to the end of that paragraph > on F_SETOWN: > > If a non-zero value is given to F_SETSIG in a multi-threaded > process running with a threading library that supports thread > groups (e.g., NPTL), then a positive value value given to > F_SETOWN has a different meaning: instead of being a process ID > identifying a whole process, it is a thread ID identifying a > specific thread within a process. Consequently, it may be nec- > essary to pass F_SETOWN the result of gettid() instead of get > pid() to get sensible results when F_SETSIG is used. (In cur- > rent Linux threading implementations, a main thread's thread ID > is the same as its process ID. This means that a single- > threaded program can equally use gettid() or getpid() in this > scenario.) Note, however, that the statements in this paragraph > do not apply to the SIGURG signal generated for out-of-band data > on a socket: this signal is always sent to either a process or a > process group, depending on the value given to F_SETOWN. Note > also that Linux imposes a limit on the number of real-time sig- > nals that may be queued to a process (see getrlimit(2) and sig- > nal(7)) and if this limit is reached, then the kernel reverts to > delivering SIGIO, and this signal is delivered to the entire > process rather than to a specifc thread. > > Look oay now? Looks ood. It will take a minor genius to translate that to working multi-threaded RT-SIGIO code without a tutorial -- and in fact I haven't heard of any program or library which does it (though I'm trying to write one) -- but technically it seems to include everything.
2005-04-05 05:54:09 +00:00
and
.B SIGURG
signals at a particular thread.
.TP
.BR F_GETOWN_EX " (struct f_owner_ex *) (since Linux 2.6.32)"
Return the current file descriptor owner settings
as defined by a previous
.BR F_SETOWN_EX
operation.
The information is returned in the structure pointed to by
.IR arg ,
which has the following form:
.nf
.in +4n
struct f_owner_ex {
int type;
pid_t pid;
};
.in
.fi
The
.I type
field will have one of the values
.BR F_OWNER_TID ,
.BR F_OWNER_PID ,
or
.BR F_OWNER_PGRP .
The
.I pid
field is a positive integer representing a thread ID, process ID,
or process group ID.
See
.B F_SETOWN_EX
for more details.
.TP
.BR F_SETOWN_EX " (struct f_owner_ex *) (since Linux 2.6.32)"
This operation performs a similar task to
.BR F_SETOWN .
It allows the caller to direct I/O availability signals
to a specific thread, process, or process group.
The caller specifies the target of signals via
.IR arg ,
which is a pointer to a
.IR f_owner_ex
structure.
The
.I type
field has one of the following values, which define how
.I pid
is interpreted:
.RS
.TP
.BR F_OWNER_TID
Send the signal to the thread whose thread ID
(the value returned by a call to
.BR clone (2)
or
.BR gettid (2))
is specified in
.IR pid .
.TP
.BR F_OWNER_PID
Send the signal to the process whose ID
is specified in
.IR pid .
.TP
.BR F_OWNER_PGRP
Send the signal to the process group whose ID
is specified in
.IR pid .
(Note that, unlike with
.BR F_SETOWN ,
a process group ID is specified as a positive value here.)
.RE
2004-11-03 13:51:07 +00:00
.TP
.BR F_GETSIG " (\fIvoid\fP)"
Return (as the function result)
the signal sent when input or output becomes possible.
2007-06-21 05:38:48 +00:00
A value of zero means
.B SIGIO
is sent.
Any other value (including
.BR SIGIO )
is the
2004-11-03 13:51:07 +00:00
signal sent instead, and in this case additional info is available to
2007-06-21 05:38:48 +00:00
the signal handler if installed with
.BR SA_SIGINFO .
.I arg
is ignored.
2004-11-03 13:51:07 +00:00
.TP
.BR F_SETSIG " (\fIint\fP)"
Set the signal sent when input or output becomes possible
to the value given in
.IR arg .
2007-06-21 05:38:48 +00:00
A value of zero means to send the default
.B SIGIO
signal.
Any other value (including
2007-06-21 05:38:48 +00:00
.BR SIGIO )
is the signal to send instead, and in this case additional info
is available to the signal handler if installed with
.BR SA_SIGINFO .
.\"
.\" The following was true only up until 2.6.11:
.\"
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/ The tendency in English, as prescribed in style guides like Chicago MoS, is towards removing hyphens after prefixes like "non-" etc. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
.\" Additionally, passing a nonzero value to
.\" .B F_SETSIG
.\" changes the signal recipient from a whole process to a specific thread
.\" within a process.
.\" See the description of
.\" .B F_SETOWN
.\" for more details.
2008-01-01 14:13:55 +00:00
By using
.B F_SETSIG
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/ The tendency in English, as prescribed in style guides like Chicago MoS, is towards removing hyphens after prefixes like "non-" etc. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
with a nonzero value, and setting
2007-06-21 05:38:48 +00:00
.B SA_SIGINFO
for the
2004-11-03 13:51:07 +00:00
signal handler (see
.BR sigaction (2)),
extra information about I/O events is passed to
the handler in a
.I siginfo_t
structure.
If the
.I si_code
2007-06-21 05:38:48 +00:00
field indicates the source is
.BR SI_SIGIO ,
the
2004-11-03 13:51:07 +00:00
.I si_fd
field gives the file descriptor associated with the event.
Otherwise,
2004-11-03 13:51:07 +00:00
there is no indication which file descriptors are pending, and you
should use the usual mechanisms
.RB ( select (2),
.BR poll (2),
.BR read (2)
with
.B O_NONBLOCK
set etc.) to determine which file descriptors are available for I/O.
2008-01-01 14:13:55 +00:00
2007-06-21 22:55:04 +00:00
By selecting a real time signal (value >=
2007-06-21 05:38:48 +00:00
.BR SIGRTMIN ),
multiple I/O events may be queued using the same signal numbers.
(Queuing is dependent on available memory).
Extra information is available
2007-06-21 05:38:48 +00:00
if
.B SA_SIGINFO
is set for the signal handler, as above.
Note that Linux imposes a limit on the
number of real-time signals that may be queued to a
process (see
.BR getrlimit (2)
and
.BR signal (7))
and if this limit is reached, then the kernel reverts to
delivering
.BR SIGIO ,
and this signal is delivered to the entire
process rather than to a specific thread.
.\" See fs/fcntl.c::send_sigio_to_task() (2.4/2.6) sources -- MTK, Apr 05
2004-11-03 13:51:07 +00:00
.PP
Using these mechanisms, a program can implement fully asynchronous I/O
without using
.BR select (2)
or
.BR poll (2)
most of the time.
.PP
The use of
.BR O_ASYNC
2004-11-03 13:51:07 +00:00
is specific to BSD and Linux.
The only use of
.BR F_GETOWN
and
.B F_SETOWN
specified in POSIX.1 is in conjunction with the use of the
.B SIGURG
signal on sockets.
(POSIX does not specify the
.BR SIGIO
signal.)
.BR F_GETOWN_EX ,
.BR F_SETOWN_EX ,
.BR F_GETSIG ,
2004-11-03 13:51:07 +00:00
and
.B F_SETSIG
2007-12-25 21:28:09 +00:00
are Linux-specific.
POSIX has asynchronous I/O and the
2004-11-03 13:51:07 +00:00
.I aio_sigevent
structure to achieve similar things; these are also available
in Linux as part of the GNU C Library (Glibc).
.SS Leases
.B F_SETLEASE
and
.B F_GETLEASE
(Linux 2.4 onward) are used (respectively) to establish a new lease,
and retrieve the current lease, on the open file description
referred to by the file descriptor
2004-11-03 13:51:07 +00:00
.IR fd .
A file lease provides a mechanism whereby the process holding
the lease (the "lease holder") is notified (via delivery of a signal)
when a process (the "lease breaker") tries to
2004-11-03 13:51:07 +00:00
.BR open (2)
or
.BR truncate (2)
the file referred to by that file descriptor.
2004-11-03 13:51:07 +00:00
.TP
.BR F_SETLEASE " (\fIint\fP)"
2004-11-03 13:51:07 +00:00
Set or remove a file lease according to which of the following
values is specified in the integer
.IR arg :
.RS
.TP
2004-11-03 13:51:07 +00:00
.B F_RDLCK
Take out a read lease.
This will cause the calling process to be notified when
the file is opened for writing or is truncated.
.\" The following became true in kernel 2.6.10:
.\" See the man-pages-2.09 Changelog for further info.
intro.1, _syscall.2, access.2, arch_prctl.2, cacheflush.2, chown.2, clock_getres.2, clone.2, create_module.2, fcntl.2, flock.2, get_kernel_syms.2, get_robust_list.2, get_thread_area.2, getcpu.2, getpriority.2, getrlimit.2, getrusage.2, ioprio_set.2, kexec_load.2, madvise.2, mbind.2, migrate_pages.2, mknod.2, mmap.2, mount.2, move_pages.2, mprotect.2, open.2, pause.2, pciconfig_read.2, perf_event_open.2, prctl.2, ptrace.2, query_module.2, read.2, reboot.2, recv.2, s390_runtime_instr.2, sched_setscheduler.2, select_tut.2, send.2, set_mempolicy.2, setfsgid.2, setfsuid.2, sigaction.2, spu_create.2, spu_run.2, stime.2, swapon.2, syslog.2, timer_create.2, timer_getoverrun.2, times.2, tkill.2, umount.2, unimplemented.2, ustat.2, vm86.2, wait.2, abs.3, aio_read.3, aio_write.3, bsd_signal.3, catgets.3, clearenv.3, cmsg.3, dbopen.3, dirfd.3, dlopen.3, exec.3, fenv.3, ferror.3, fmemopen.3, fnmatch.3, fopen.3, futimes.3, getaddrinfo.3, getifaddrs.3, getipnodebyname.3, hsearch.3, if_nameindex.3, inet_pton.3, mblen.3, mbrlen.3, mbsrtowcs.3, mbtowc.3, mcheck.3, memfrob.3, mq_notify.3, netlink.3, posix_memalign.3, printf.3, pthread_attr_setscope.3, pthread_cleanup_push.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setcancelstate.3, pthread_setconcurrency.3, raise.3, resolver.3, rpc.3, rtime.3, rtnetlink.3, scanf.3, setbuf.3, setnetgrent.3, shm_open.3, sigpause.3, sigset.3, sigwait.3, sockatmark.3, strcasecmp.3, strcmp.3, strdup.3, strftime.3, strptime.3, strsignal.3, strverscmp.3, sysv_signal.3, termios.3, wcrtomb.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wctomb.3, wprintf.3, console_codes.4, cpuid.4, msr.4, rtc.4, sk98lin.4, st.4, tty.4, charmap.5, core.5, elf.5, hosts.equiv.5, proc.5, resolv.conf.5, services.5, slabinfo.5, arp.7, bootparam.7, capabilities.7, charsets.7, cpuset.7, ddp.7, epoll.7, feature_test_macros.7, futex.7, hier.7, icmp.7, inotify.7, ip.7, ipv6.7, man-pages.7, mdoc.7, mdoc.samples.7, netdevice.7, netlink.7, numa.7, packet.7, path_resolution.7, posixoptions.7, pthreads.7, raw.7, rtld-audit.7, rtnetlink.7, sem_overview.7, sigevent.7, socket.7, spufs.7, tcp.7, udp.7, unicode.7, uri.7, utf-8.7, intro.8, ldconfig.8, sync.8: Global fix: fix placement of word "only" Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-31 08:53:00 +00:00
A read lease can be placed only on a file descriptor that
is opened read-only.
2004-11-03 13:51:07 +00:00
.TP
.B F_WRLCK
Take out a write lease.
This will cause the caller to be notified when
the file is opened for reading or writing or is truncated.
A write lease may be placed on a file only if there are no
other open file descriptors for the file.
2004-11-03 13:51:07 +00:00
.TP
.B F_UNLCK
Remove our lease from the file.
.RE
.P
Leases are associated with an open file description (see
.BR open (2)).
This means that duplicate file descriptors (created by, for example,
.BR fork (2)
or
.BR dup (2))
refer to the same lease, and this lease may be modified
or released using any of these descriptors.
Furthermore, the lease is released by either an explicit
.B F_UNLCK
operation on any of these duplicate descriptors, or when all
such descriptors have been closed.
2004-11-03 13:51:07 +00:00
.P
intro.1, _syscall.2, access.2, arch_prctl.2, cacheflush.2, chown.2, clock_getres.2, clone.2, create_module.2, fcntl.2, flock.2, get_kernel_syms.2, get_robust_list.2, get_thread_area.2, getcpu.2, getpriority.2, getrlimit.2, getrusage.2, ioprio_set.2, kexec_load.2, madvise.2, mbind.2, migrate_pages.2, mknod.2, mmap.2, mount.2, move_pages.2, mprotect.2, open.2, pause.2, pciconfig_read.2, perf_event_open.2, prctl.2, ptrace.2, query_module.2, read.2, reboot.2, recv.2, s390_runtime_instr.2, sched_setscheduler.2, select_tut.2, send.2, set_mempolicy.2, setfsgid.2, setfsuid.2, sigaction.2, spu_create.2, spu_run.2, stime.2, swapon.2, syslog.2, timer_create.2, timer_getoverrun.2, times.2, tkill.2, umount.2, unimplemented.2, ustat.2, vm86.2, wait.2, abs.3, aio_read.3, aio_write.3, bsd_signal.3, catgets.3, clearenv.3, cmsg.3, dbopen.3, dirfd.3, dlopen.3, exec.3, fenv.3, ferror.3, fmemopen.3, fnmatch.3, fopen.3, futimes.3, getaddrinfo.3, getifaddrs.3, getipnodebyname.3, hsearch.3, if_nameindex.3, inet_pton.3, mblen.3, mbrlen.3, mbsrtowcs.3, mbtowc.3, mcheck.3, memfrob.3, mq_notify.3, netlink.3, posix_memalign.3, printf.3, pthread_attr_setscope.3, pthread_cleanup_push.3, pthread_kill_other_threads_np.3, pthread_self.3, pthread_setcancelstate.3, pthread_setconcurrency.3, raise.3, resolver.3, rpc.3, rtime.3, rtnetlink.3, scanf.3, setbuf.3, setnetgrent.3, shm_open.3, sigpause.3, sigset.3, sigwait.3, sockatmark.3, strcasecmp.3, strcmp.3, strdup.3, strftime.3, strptime.3, strsignal.3, strverscmp.3, sysv_signal.3, termios.3, wcrtomb.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wctomb.3, wprintf.3, console_codes.4, cpuid.4, msr.4, rtc.4, sk98lin.4, st.4, tty.4, charmap.5, core.5, elf.5, hosts.equiv.5, proc.5, resolv.conf.5, services.5, slabinfo.5, arp.7, bootparam.7, capabilities.7, charsets.7, cpuset.7, ddp.7, epoll.7, feature_test_macros.7, futex.7, hier.7, icmp.7, inotify.7, ip.7, ipv6.7, man-pages.7, mdoc.7, mdoc.samples.7, netdevice.7, netlink.7, numa.7, packet.7, path_resolution.7, posixoptions.7, pthreads.7, raw.7, rtld-audit.7, rtnetlink.7, sem_overview.7, sigevent.7, socket.7, spufs.7, tcp.7, udp.7, unicode.7, uri.7, utf-8.7, intro.8, ldconfig.8, sync.8: Global fix: fix placement of word "only" Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-31 08:53:00 +00:00
Leases may be taken out only on regular files.
An unprivileged process may take out a lease only on a file whose
intro.1, time.1, access.2, acct.2, alloc_hugepages.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clone.2, close.2, execve.2, fallocate.2, fcntl.2, getdents.2, getrusage.2, getxattr.2, init_module.2, inotify_add_watch.2, ioprio_set.2, kcmp.2, link.2, listxattr.2, lseek.2, madvise.2, mkdir.2, mknod.2, mmap.2, mount.2, move_pages.2, msgctl.2, nfsservctl.2, open.2, pivot_root.2, quotactl.2, read.2, readlink.2, removexattr.2, rename.2, rmdir.2, semctl.2, setfsgid.2, setfsuid.2, setresuid.2, setuid.2, setup.2, setxattr.2, shmctl.2, splice.2, spu_create.2, stat.2, statfs.2, swapon.2, symlink.2, sync.2, sync_file_range.2, sysfs.2, truncate.2, umount.2, unlink.2, unshare.2, ustat.2, utime.2, utimensat.2, write.2, btree.3, errno.3, fexecve.3, ftw.3, futimes.3, get_nprocs_conf.3, getcwd.3, getdirentries.3, getmntent.3, glob.3, mkfifo.3, mq_open.3, readdir.3, realpath.3, recno.3, remove.3, sem_open.3, shm_open.3, statvfs.3, sysconf.3, telldir.3, tmpfile.3, cciss.4, initrd.4, pts.4, sk98lin.4, vcs.4, core.5, filesystems.5, proc.5, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, feature_test_macros.7, fifo.7, hier.7, inotify.7, intro.7, mq_overview.7, path_resolution.7, pipe.7, sem_overview.7, shm_overview.7, spufs.7, symlink.7, unix.7, uri.7, sync.8: Global fix: s/file system/filesystem/ Notwithstanding 24d01c530c5a3f75217543d02bf6712395e5f90c, "filesystem" is the form used by the great majority of man pages outside the man-pages project and in a number of other sources, so let's go with that. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-08-08 08:07:57 +00:00
UID (owner) matches the filesystem UID of the process.
2004-11-03 13:51:07 +00:00
A process with the
.B CAP_LEASE
capability may take out leases on arbitrary files.
.TP
.BR F_GETLEASE " (\fIvoid\fP)"
Indicates what type of lease is associated with the file descriptor
2004-11-03 13:51:07 +00:00
.I fd
by returning either
2007-09-04 06:30:39 +00:00
.BR F_RDLCK ", " F_WRLCK ", or " F_UNLCK ,
indicating, respectively, a read lease , a write lease, or no lease.
.I arg
is ignored.
2004-11-03 13:51:07 +00:00
.PP
When a process (the "lease breaker") performs an
.BR open (2)
2004-11-03 13:51:07 +00:00
or
.BR truncate (2)
2004-11-03 13:51:07 +00:00
that conflicts with a lease established via
.BR F_SETLEASE ,
the system call is blocked by the kernel and
the kernel notifies the lease holder by sending it a signal
2007-06-21 05:38:48 +00:00
.RB ( SIGIO
by default).
2004-11-03 13:51:07 +00:00
The lease holder should respond to receipt of this signal by doing
whatever cleanup is required in preparation for the file to be
accessed by another process (e.g., flushing cached buffers) and
then either remove or downgrade its lease.
A lease is removed by performing an
.B F_SETLEASE
command specifying
.I arg
as
.BR F_UNLCK .
If the lease holder currently holds a write lease on the file,
2004-11-03 13:51:07 +00:00
and the lease breaker is opening the file for reading,
then it is sufficient for the lease holder to downgrade
the lease to a read lease.
2004-11-03 13:51:07 +00:00
This is done by performing an
.B F_SETLEASE
command specifying
.I arg
as
.BR F_RDLCK .
If the lease holder fails to downgrade or remove the lease within
the number of seconds specified in
.IR /proc/sys/fs/lease-break-time ,
2004-11-03 13:51:07 +00:00
then the kernel forcibly removes or downgrades the lease holder's lease.
Once a lease break has been initiated,
.B F_GETLEASE
returns the target lease type (either
.B F_RDLCK
or
.BR F_UNLCK ,
depending on what would be compatible with the lease breaker)
until the lease holder voluntarily downgrades or removes the lease or
the kernel forcibly does so after the lease break timer expires.
2004-11-03 13:51:07 +00:00
Once the lease has been voluntarily or forcibly removed or downgraded,
and assuming the lease breaker has not unblocked its system call,
the kernel permits the lease breaker's system call to proceed.
If the lease breaker's blocked
.BR open (2)
or
.BR truncate (2)
is interrupted by a signal handler,
then the system call fails with the error
.BR EINTR ,
but the other steps still occur as described above.
If the lease breaker is killed by a signal while blocked in
.BR open (2)
or
.BR truncate (2),
then the other steps still occur as described above.
If the lease breaker specifies the
.B O_NONBLOCK
flag when calling
.BR open (2),
then the call immediately fails with the error
.BR EWOULDBLOCK ,
but the other steps still occur as described above.
2007-06-21 05:38:48 +00:00
The default signal used to notify the lease holder is
.BR SIGIO ,
2004-11-03 13:51:07 +00:00
but this can be changed using the
.B F_SETSIG
command to
.BR fcntl ().
2004-11-03 13:51:07 +00:00
If a
.B F_SETSIG
2007-06-21 05:38:48 +00:00
command is performed (even one specifying
.BR SIGIO ),
and the signal
handler is established using
.BR SA_SIGINFO ,
then the handler will receive a
2004-11-03 13:51:07 +00:00
.I siginfo_t
2005-04-18 13:35:29 +00:00
structure as its second argument, and the
2004-11-03 13:51:07 +00:00
.I si_fd
field of this argument will hold the descriptor of the leased file
that has been accessed by another process.
(This is useful if the caller holds leases against multiple files).
.SS File and directory change notification (dnotify)
2004-11-03 13:51:07 +00:00
.TP
.BR F_NOTIFY " (\fIint\fP)"
(Linux 2.4 onward)
2004-11-03 13:51:07 +00:00
Provide notification when the directory referred to by
.I fd
or any of the files that it contains is changed.
The events to be notified are specified in
.IR arg ,
which is a bit mask specified by ORing together zero or more of
the following bits:
2008-01-13 09:40:31 +00:00
.RS
2004-11-03 13:51:07 +00:00
.sp
2008-01-13 09:40:31 +00:00
.PD 0
.TP 12
.B DN_ACCESS
A file was accessed (read, pread, readv)
.TP
.B DN_MODIFY
A file was modified (write, pwrite, writev, truncate, ftruncate).
.TP
.B DN_CREATE
A file was created (open, creat, mknod, mkdir, link, symlink, rename).
.TP
.B DN_DELETE
A file was unlinked (unlink, rename to another directory, rmdir).
.TP
.B DN_RENAME
A file was renamed within this directory (rename).
.TP
.B DN_ATTRIB
The attributes of a file were changed (chown, chmod, utime[s]).
.PD
.RE
.IP
2007-06-22 17:16:20 +00:00
(In order to obtain these definitions, the
.B _GNU_SOURCE
feature test macro must be defined before including
.I any
header files.)
2008-01-01 14:13:55 +00:00
2004-11-03 13:51:07 +00:00
Directory notifications are normally "one-shot", and the application
must reregister to receive further notifications.
2004-11-03 13:51:07 +00:00
Alternatively, if
.B DN_MULTISHOT
is included in
.IR arg ,
then notification will remain in effect until explicitly removed.
.\" The following does seem a poor API-design choice...
A series of
.B F_NOTIFY
requests is cumulative, with the events in
.I arg
being added to the set already monitored.
To disable notification of all events, make an
.B F_NOTIFY
call specifying
.I arg
as 0.
2008-01-01 14:13:55 +00:00
2004-11-03 13:51:07 +00:00
Notification occurs via delivery of a signal.
2007-06-21 05:38:48 +00:00
The default signal is
.BR SIGIO ,
but this can be changed using the
2004-11-03 13:51:07 +00:00
.B F_SETSIG
command to
.BR fcntl ().
In the latter case, the signal handler receives a
.I siginfo_t
structure as its second argument (if the handler was
2007-06-21 05:38:48 +00:00
established using
.BR SA_SIGINFO )
and the
2004-11-03 13:51:07 +00:00
.I si_fd
field of this structure contains the file descriptor which
generated the notification (useful when establishing notification
on multiple directories).
2008-01-01 14:13:55 +00:00
2004-11-03 13:51:07 +00:00
Especially when using
.BR DN_MULTISHOT ,
a real time signal should be used for notification,
2004-11-03 13:51:07 +00:00
so that multiple notifications can be queued.
.B NOTE:
New applications should use the
.I inotify
interface (available since kernel 2.6.13),
which provides a much superior interface for obtaining notifications of
intro.1, time.1, access.2, acct.2, alloc_hugepages.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clone.2, close.2, execve.2, fallocate.2, fcntl.2, getdents.2, getrusage.2, getxattr.2, init_module.2, inotify_add_watch.2, ioprio_set.2, kcmp.2, link.2, listxattr.2, lseek.2, madvise.2, mkdir.2, mknod.2, mmap.2, mount.2, move_pages.2, msgctl.2, nfsservctl.2, open.2, pivot_root.2, quotactl.2, read.2, readlink.2, removexattr.2, rename.2, rmdir.2, semctl.2, setfsgid.2, setfsuid.2, setresuid.2, setuid.2, setup.2, setxattr.2, shmctl.2, splice.2, spu_create.2, stat.2, statfs.2, swapon.2, symlink.2, sync.2, sync_file_range.2, sysfs.2, truncate.2, umount.2, unlink.2, unshare.2, ustat.2, utime.2, utimensat.2, write.2, btree.3, errno.3, fexecve.3, ftw.3, futimes.3, get_nprocs_conf.3, getcwd.3, getdirentries.3, getmntent.3, glob.3, mkfifo.3, mq_open.3, readdir.3, realpath.3, recno.3, remove.3, sem_open.3, shm_open.3, statvfs.3, sysconf.3, telldir.3, tmpfile.3, cciss.4, initrd.4, pts.4, sk98lin.4, vcs.4, core.5, filesystems.5, proc.5, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, feature_test_macros.7, fifo.7, hier.7, inotify.7, intro.7, mq_overview.7, path_resolution.7, pipe.7, sem_overview.7, shm_overview.7, spufs.7, symlink.7, unix.7, uri.7, sync.8: Global fix: s/file system/filesystem/ Notwithstanding 24d01c530c5a3f75217543d02bf6712395e5f90c, "filesystem" is the form used by the great majority of man pages outside the man-pages project and in a number of other sources, so let's go with that. Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-08-08 08:07:57 +00:00
filesystem events.
See
.BR inotify (7).
.SS Changing the capacity of a pipe
.TP
.BR F_SETPIPE_SZ " (\fIint\fP; since Linux 2.6.35)"
Change the capacity of the pipe referred to by
.I fd
to be at least
.I arg
bytes.
An unprivileged process can adjust the pipe capacity to any value
between the system page size and the limit defined in
.IR /proc/sys/fs/pipe-max-size
(see
.BR proc (5)).
Attempts to set the pipe capacity below the page size are silently
rounded up to the page size.
Attempts by an unprivileged process to set the pipe capacity above the limit in
.IR /proc/sys/fs/pipe-max-size
yield the error
.BR EPERM ;
a privileged process
.RB ( CAP_SYS_RESOURCE )
can override the limit.
When allocating the buffer for the pipe,
the kernel may use a capacity larger than
.IR arg ,
if that is convenient for the implementation.
The
.B F_GETPIPE_SZ
operation returns the actual size used.
Attempting to set the pipe capacity smaller than the amount
of buffer space currently used to store data produces the error
.BR EBUSY .
.TP
.BR F_GETPIPE_SZ " (\fIvoid\fP; since Linux 2.6.35)"
Return (as the function result) the capacity of the pipe referred to by
.IR fd .
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bdflush.2, bind.2, brk.2, cacheflush.2, capget.2, chdir.2, chmod.2, chown.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, exit_group.2, faccessat.2, fchmodat.2, fchownat.2, fcntl.2, flock.2, fork.2, fstatat.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_robust_list.2, get_thread_area.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpid.2, getpriority.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, getxattr.2, idle.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl.2, ioctl_list.2, ioperm.2, iopl.2, ioprio_set.2, ipc.2, kcmp.2, kill.2, killpg.2, link.2, linkat.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, migrate_pages.2, mincore.2, mkdir.2, mkdirat.2, mknod.2, mknodat.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, mount.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open.2, openat.2, outb.2, pause.2, pciconfig_read.2, perf_event_open.2, perfmonctl.2, personality.2, pipe.2, pivot_root.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readlink.2, readlinkat.2, readv.2, reboot.2, recv.2, remap_file_pages.2, removexattr.2, rename.2, renameat.2, rmdir.2, rt_sigqueueinfo.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, setup.2, setxattr.2, shmctl.2, shmget.2, shmop.2, shutdown.2, sigaction.2, sigaltstack.2, signal.2, signalfd.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, stat.2, statfs.2, stime.2, swapon.2, symlink.2, symlinkat.2, sync.2, sync_file_range.2, sysctl.2, sysfs.2, sysinfo.2, syslog.2, tee.2, time.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, uname.2, unimplemented.2, unlink.2, unlinkat.2, uselib.2, ustat.2, utime.2, utimensat.2, vfork.2, vhangup.2, vm86.2, vmsplice.2, wait.2, wait4.2, write.2, CPU_SET.3, INFINITY.3, MB_CUR_MAX.3, MB_LEN_MAX.3, __setfpucw.3, a64l.3, abort.3, abs.3, acos.3, acosh.3, addseverity.3, adjtime.3, aio_cancel.3, aio_error.3, aio_fsync.3, aio_read.3, aio_return.3, aio_suspend.3, aio_write.3, alloca.3, argz_add.3, asin.3, asinh.3, asprintf.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atexit.3, atof.3, atoi.3, backtrace.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, bsearch.3, bstring.3, btowc.3, btree.3, byteorder.3, bzero.3, cabs.3, cacos.3, cacosh.3, canonicalize_file_name.3, carg.3, casin.3, casinh.3, catan.3, catanh.3, catgets.3, catopen.3, cbrt.3, ccos.3, ccosh.3, ceil.3, cerf.3, cexp.3, cexp2.3, cfree.3, cimag.3, clearenv.3, clock.3, clock_getcpuclockid.3, clog.3, clog10.3, clog2.3, closedir.3, cmsg.3, confstr.3, conj.3, copysign.3, cos.3, cosh.3, cpow.3, cproj.3, creal.3, crypt.3, csin.3, csinh.3, csqrt.3, ctan.3, ctanh.3, ctermid.3, ctime.3, daemon.3, dbopen.3, des_crypt.3, difftime.3, dirfd.3, div.3, dl_iterate_phdr.3, dlopen.3, dprintf.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, encrypt.3, end.3, endian.3, envz_add.3, erf.3, erfc.3, err.3, errno.3, error.3, ether_aton.3, euidaccess.3, exec.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fclose.3, fcloseall.3, fdim.3, fenv.3, ferror.3, fexecve.3, fflush.3, ffs.3, fgetgrent.3, fgetpwent.3, fgetwc.3, fgetws.3, finite.3, flockfile.3, floor.3, fma.3, fmax.3, fmemopen.3, fmin.3, fmod.3, fmtmsg.3, fnmatch.3, fopen.3, fpathconf.3, fpclassify.3, fpurge.3, fputwc.3, fputws.3, fread.3, frexp.3, fseek.3, fseeko.3, ftime.3, ftok.3, fts.3, ftw.3, futimes.3, fwide.3, gamma.3, gcvt.3, getaddrinfo.3, getaddrinfo_a.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, gethostid.3, getipnodebyname.3, getline.3, getloadavg.3, getlogin.3, getmntent.3, getnameinfo.3, getnetent.3, getnetent_r.3, getopt.3, getpass.3, getprotoent.3, getprotoent_r.3, getpt.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getrpcent_r.3, getrpcport.3, gets.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, getumask.3, getusershell.3, getutent.3, getw.3, getwchar.3, glob.3, grantpt.3, gsignal.3, hash.3, hsearch.3, hypot.3, iconv.3, iconv_close.3, iconv_open.3, ilogb.3, index.3, inet.3, inet_ntop.3, inet_pton.3, infnan.3, initgroups.3, insque.3, intro.3, isalpha.3, isatty.3, isgreater.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, j0.3, key_setsecret.3, ldexp.3, lgamma.3, lio_listio.3, localeconv.3, lockf.3, log.3, log10.3, log1p.3, log2.3, logb.3, login.3, longjmp.3, lrint.3, lround.3, lsearch.3, lseek64.3, makecontext.3, makedev.3, malloc.3, malloc_hook.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, mempcpy.3, memset.3, mkdtemp.3, mkfifo.3, mkfifoat.3, mkstemp.3, mktemp.3, modf.3, mpool.3, mq_close.3, mq_getattr.3, mq_notify.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, nan.3, netlink.3, nextafter.3, nl_langinfo.3, offsetof.3, on_exit.3, opendir.3, openpty.3, perror.3, popen.3, posix_fallocate.3, posix_memalign.3, posix_openpt.3, pow.3, pow10.3, printf.3, profil.3, program_invocation_name.3, psignal.3, pthread_kill_other_threads_np.3, ptsname.3, putenv.3, putgrent.3, putpwent.3, puts.3, putwchar.3, qecvt.3, qsort.3, queue.3, raise.3, rand.3, random.3, random_r.3, rcmd.3, re_comp.3, readdir.3, realpath.3, recno.3, regex.3, remainder.3, remove.3, remquo.3, resolver.3, rewinddir.3, rexec.3, rint.3, round.3, rpc.3, rpmatch.3, rtime.3, rtnetlink.3, scalb.3, scalbln.3, scandir.3, scandirat.3, scanf.3, seekdir.3, sem_close.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_open.3, sem_post.3, sem_unlink.3, sem_wait.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, setlocale.3, setlogmask.3, setnetgrent.3, shm_open.3, siginterrupt.3, signbit.3, significand.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sin.3, sincos.3, sinh.3, sleep.3, sockatmark.3, sqrt.3, statvfs.3, stdarg.3, stdin.3, stdio.3, stdio_ext.3, stpcpy.3, stpncpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strdup.3, strerror.3, strfmon.3, strfry.3, strftime.3, string.3, strlen.3, strnlen.3, strpbrk.3, strptime.3, strsep.3, strsignal.3, strspn.3, strstr.3, strtod.3, strtoimax.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, sysconf.3, syslog.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, termios.3, tgamma.3, timegm.3, timeradd.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, towctrans.3, towlower.3, towupper.3, trunc.3, tsearch.3, ttyname.3, ttyslot.3, tzset.3, ualarm.3, ulimit.3, ungetwc.3, unlocked_stdio.3, unlockpt.3, updwtmp.3, usleep.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstoimax.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wordexp.3, wprintf.3, xcrypt.3, xdr.3, y0.3, cciss.4, console.4, console_codes.4, console_ioctl.4, dsp56k.4, fd.4, full.4, hd.4, hpsa.4, initrd.4, intro.4, lp.4, mem.4, mouse.4, null.4, pts.4, ram.4, random.4, rtc.4, sk98lin.4, st.4, tty.4, ttyS.4, tty_ioctl.4, vcs.4, wavelan.4, acct.5, charmap.5, dir_colors.5, filesystems.5, ftpusers.5, group.5, host.conf.5, hosts.5, hosts.equiv.5, intro.5, issue.5, locale.5, motd.5, networks.5, nologin.5, nscd.conf.5, passwd.5, proc.5, protocols.5, resolv.conf.5, rpc.5, securetty.5, services.5, shells.5, termcap.5, ttytype.5, utmp.5, armscii-8.7, arp.7, ascii.7, bootparam.7, capabilities.7, charsets.7, complex.7, cp1251.7, credentials.7, ddp.7, environ.7, epoll.7, fifo.7, futex.7, glob.7, hier.7, icmp.7, inotify.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, locale.7, mailaddr.7, man.7, mq_overview.7, netdevice.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, posixoptions.7, pthreads.7, pty.7, raw.7, regex.7, rtld-audit.7, rtnetlink.7, sem_overview.7, shm_overview.7, sigevent.7, signal.7, socket.7, standards.7, suffixes.7, svipc.7, tcp.7, termio.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, nscd.8, sync.8, tzselect.8, zdump.8, zic.8: Global fix: remove unneeded double quotes in .SH headings Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 18:01:36 +00:00
.SH RETURN VALUE
2004-11-03 13:51:07 +00:00
For a successful call, the return value depends on the operation:
.TP 0.9i
.B F_DUPFD
The new descriptor.
.TP
.B F_GETFD
Value of file descriptor flags.
2004-11-03 13:51:07 +00:00
.TP
.B F_GETFL
Value of file status flags.
2004-11-03 13:51:07 +00:00
.TP
2007-11-17 06:23:13 +00:00
.B F_GETLEASE
Type of lease held on file descriptor.
.TP
2004-11-03 13:51:07 +00:00
.B F_GETOWN
Value of descriptor owner.
.TP
.B F_GETSIG
Value of signal sent when read or write becomes possible, or zero
2007-06-21 05:38:48 +00:00
for traditional
.B SIGIO
behavior.
2004-11-03 13:51:07 +00:00
.TP
.B F_GETPIPE_SZ
The pipe capacity.
.TP
2004-11-03 13:51:07 +00:00
All other commands
Zero.
.PP
On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.BR EACCES " or " EAGAIN
Operation is prohibited by locks held by other processes.
.TP
.B EAGAIN
The operation is prohibited because the file has been memory-mapped by
2004-11-03 13:51:07 +00:00
another process.
.TP
.B EBADF
.I fd
is not an open file descriptor, or the command was
.B F_SETLK
or
.B F_SETLKW
and the file descriptor open mode doesn't match with the
type of lock requested.
.TP
.B EDEADLK
It was detected that the specified
.B F_SETLKW
command would cause a deadlock.
.TP
.B EFAULT
.I lock
is outside your accessible address space.
.TP
.B EINTR
For
.BR F_SETLKW ,
the command was interrupted by a signal; see
.BR signal (7).
2004-11-03 13:51:07 +00:00
For
.BR F_GETLK " and " F_SETLK ,
the command was interrupted by a signal before the lock was checked or
acquired.
Most likely when locking a remote file (e.g., locking over
2004-11-03 13:51:07 +00:00
NFS), but can sometimes happen locally.
.TP
.B EINVAL
The value specified in
.I cmd
is not recognized by this kernel.
.TP
.B EINVAL
2004-11-03 13:51:07 +00:00
For
.BR F_DUPFD ,
.I arg
is negative or is greater than the maximum allowable value.
For
2004-11-03 13:51:07 +00:00
.BR F_SETSIG ,
.I arg
is not an allowable signal number.
.TP
.B EINVAL
.I cmd
is
.BR F_OFD_SETLK ,
.BR F_OFD_SETLKW ,
or
.BR F_OFD_GETLK ,
and
.I l_pid
was not specified as zero.
.TP
2004-11-03 13:51:07 +00:00
.B EMFILE
For
.BR F_DUPFD ,
the process already has the maximum number of file descriptors open.
.TP
.B ENOLCK
Too many segment locks open, lock table is full, or a remote locking
protocol failed (e.g., locking over NFS).
2004-11-03 13:51:07 +00:00
.TP
.B EPERM
Attempted to clear the
.B O_APPEND
flag on a file that has the append-only attribute set.
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bdflush.2, bind.2, brk.2, cacheflush.2, capget.2, chdir.2, chmod.2, chown.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, exit_group.2, faccessat.2, fchmodat.2, fchownat.2, fcntl.2, flock.2, fork.2, fstatat.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_robust_list.2, get_thread_area.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpid.2, getpriority.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, getxattr.2, idle.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl.2, ioctl_list.2, ioperm.2, iopl.2, ioprio_set.2, ipc.2, kcmp.2, kill.2, killpg.2, link.2, linkat.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, migrate_pages.2, mincore.2, mkdir.2, mkdirat.2, mknod.2, mknodat.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, mount.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open.2, openat.2, outb.2, pause.2, pciconfig_read.2, perf_event_open.2, perfmonctl.2, personality.2, pipe.2, pivot_root.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readlink.2, readlinkat.2, readv.2, reboot.2, recv.2, remap_file_pages.2, removexattr.2, rename.2, renameat.2, rmdir.2, rt_sigqueueinfo.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, setup.2, setxattr.2, shmctl.2, shmget.2, shmop.2, shutdown.2, sigaction.2, sigaltstack.2, signal.2, signalfd.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, stat.2, statfs.2, stime.2, swapon.2, symlink.2, symlinkat.2, sync.2, sync_file_range.2, sysctl.2, sysfs.2, sysinfo.2, syslog.2, tee.2, time.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, uname.2, unimplemented.2, unlink.2, unlinkat.2, uselib.2, ustat.2, utime.2, utimensat.2, vfork.2, vhangup.2, vm86.2, vmsplice.2, wait.2, wait4.2, write.2, CPU_SET.3, INFINITY.3, MB_CUR_MAX.3, MB_LEN_MAX.3, __setfpucw.3, a64l.3, abort.3, abs.3, acos.3, acosh.3, addseverity.3, adjtime.3, aio_cancel.3, aio_error.3, aio_fsync.3, aio_read.3, aio_return.3, aio_suspend.3, aio_write.3, alloca.3, argz_add.3, asin.3, asinh.3, asprintf.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atexit.3, atof.3, atoi.3, backtrace.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, bsearch.3, bstring.3, btowc.3, btree.3, byteorder.3, bzero.3, cabs.3, cacos.3, cacosh.3, canonicalize_file_name.3, carg.3, casin.3, casinh.3, catan.3, catanh.3, catgets.3, catopen.3, cbrt.3, ccos.3, ccosh.3, ceil.3, cerf.3, cexp.3, cexp2.3, cfree.3, cimag.3, clearenv.3, clock.3, clock_getcpuclockid.3, clog.3, clog10.3, clog2.3, closedir.3, cmsg.3, confstr.3, conj.3, copysign.3, cos.3, cosh.3, cpow.3, cproj.3, creal.3, crypt.3, csin.3, csinh.3, csqrt.3, ctan.3, ctanh.3, ctermid.3, ctime.3, daemon.3, dbopen.3, des_crypt.3, difftime.3, dirfd.3, div.3, dl_iterate_phdr.3, dlopen.3, dprintf.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, encrypt.3, end.3, endian.3, envz_add.3, erf.3, erfc.3, err.3, errno.3, error.3, ether_aton.3, euidaccess.3, exec.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fclose.3, fcloseall.3, fdim.3, fenv.3, ferror.3, fexecve.3, fflush.3, ffs.3, fgetgrent.3, fgetpwent.3, fgetwc.3, fgetws.3, finite.3, flockfile.3, floor.3, fma.3, fmax.3, fmemopen.3, fmin.3, fmod.3, fmtmsg.3, fnmatch.3, fopen.3, fpathconf.3, fpclassify.3, fpurge.3, fputwc.3, fputws.3, fread.3, frexp.3, fseek.3, fseeko.3, ftime.3, ftok.3, fts.3, ftw.3, futimes.3, fwide.3, gamma.3, gcvt.3, getaddrinfo.3, getaddrinfo_a.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, gethostid.3, getipnodebyname.3, getline.3, getloadavg.3, getlogin.3, getmntent.3, getnameinfo.3, getnetent.3, getnetent_r.3, getopt.3, getpass.3, getprotoent.3, getprotoent_r.3, getpt.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getrpcent_r.3, getrpcport.3, gets.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, getumask.3, getusershell.3, getutent.3, getw.3, getwchar.3, glob.3, grantpt.3, gsignal.3, hash.3, hsearch.3, hypot.3, iconv.3, iconv_close.3, iconv_open.3, ilogb.3, index.3, inet.3, inet_ntop.3, inet_pton.3, infnan.3, initgroups.3, insque.3, intro.3, isalpha.3, isatty.3, isgreater.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, j0.3, key_setsecret.3, ldexp.3, lgamma.3, lio_listio.3, localeconv.3, lockf.3, log.3, log10.3, log1p.3, log2.3, logb.3, login.3, longjmp.3, lrint.3, lround.3, lsearch.3, lseek64.3, makecontext.3, makedev.3, malloc.3, malloc_hook.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, mempcpy.3, memset.3, mkdtemp.3, mkfifo.3, mkfifoat.3, mkstemp.3, mktemp.3, modf.3, mpool.3, mq_close.3, mq_getattr.3, mq_notify.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, nan.3, netlink.3, nextafter.3, nl_langinfo.3, offsetof.3, on_exit.3, opendir.3, openpty.3, perror.3, popen.3, posix_fallocate.3, posix_memalign.3, posix_openpt.3, pow.3, pow10.3, printf.3, profil.3, program_invocation_name.3, psignal.3, pthread_kill_other_threads_np.3, ptsname.3, putenv.3, putgrent.3, putpwent.3, puts.3, putwchar.3, qecvt.3, qsort.3, queue.3, raise.3, rand.3, random.3, random_r.3, rcmd.3, re_comp.3, readdir.3, realpath.3, recno.3, regex.3, remainder.3, remove.3, remquo.3, resolver.3, rewinddir.3, rexec.3, rint.3, round.3, rpc.3, rpmatch.3, rtime.3, rtnetlink.3, scalb.3, scalbln.3, scandir.3, scandirat.3, scanf.3, seekdir.3, sem_close.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_open.3, sem_post.3, sem_unlink.3, sem_wait.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, setlocale.3, setlogmask.3, setnetgrent.3, shm_open.3, siginterrupt.3, signbit.3, significand.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sin.3, sincos.3, sinh.3, sleep.3, sockatmark.3, sqrt.3, statvfs.3, stdarg.3, stdin.3, stdio.3, stdio_ext.3, stpcpy.3, stpncpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strdup.3, strerror.3, strfmon.3, strfry.3, strftime.3, string.3, strlen.3, strnlen.3, strpbrk.3, strptime.3, strsep.3, strsignal.3, strspn.3, strstr.3, strtod.3, strtoimax.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, sysconf.3, syslog.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, termios.3, tgamma.3, timegm.3, timeradd.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, towctrans.3, towlower.3, towupper.3, trunc.3, tsearch.3, ttyname.3, ttyslot.3, tzset.3, ualarm.3, ulimit.3, ungetwc.3, unlocked_stdio.3, unlockpt.3, updwtmp.3, usleep.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstoimax.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wordexp.3, wprintf.3, xcrypt.3, xdr.3, y0.3, cciss.4, console.4, console_codes.4, console_ioctl.4, dsp56k.4, fd.4, full.4, hd.4, hpsa.4, initrd.4, intro.4, lp.4, mem.4, mouse.4, null.4, pts.4, ram.4, random.4, rtc.4, sk98lin.4, st.4, tty.4, ttyS.4, tty_ioctl.4, vcs.4, wavelan.4, acct.5, charmap.5, dir_colors.5, filesystems.5, ftpusers.5, group.5, host.conf.5, hosts.5, hosts.equiv.5, intro.5, issue.5, locale.5, motd.5, networks.5, nologin.5, nscd.conf.5, passwd.5, proc.5, protocols.5, resolv.conf.5, rpc.5, securetty.5, services.5, shells.5, termcap.5, ttytype.5, utmp.5, armscii-8.7, arp.7, ascii.7, bootparam.7, capabilities.7, charsets.7, complex.7, cp1251.7, credentials.7, ddp.7, environ.7, epoll.7, fifo.7, futex.7, glob.7, hier.7, icmp.7, inotify.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, locale.7, mailaddr.7, man.7, mq_overview.7, netdevice.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, posixoptions.7, pthreads.7, pty.7, raw.7, regex.7, rtld-audit.7, rtnetlink.7, sem_overview.7, shm_overview.7, sigevent.7, signal.7, socket.7, standards.7, suffixes.7, svipc.7, tcp.7, termio.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, nscd.8, sync.8, tzselect.8, zdump.8, zic.8: Global fix: remove unneeded double quotes in .SH headings Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 18:01:36 +00:00
.SH CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001.
2007-06-21 05:38:48 +00:00
Only the operations
.BR F_DUPFD ,
.BR F_GETFD ,
.BR F_SETFD ,
.BR F_GETFL ,
.BR F_SETFL ,
.BR F_GETLK ,
.BR F_SETLK ,
and
.BR F_SETLKW
are specified in POSIX.1-2001.
.BR F_GETOWN
2007-06-21 05:38:48 +00:00
and
2007-09-20 16:26:31 +00:00
.B F_SETOWN
2007-06-21 05:38:48 +00:00
are specified in POSIX.1-2001.
(To get their definitions, define
.BR _BSD_SOURCE ,
or
.BR _XOPEN_SOURCE
with the value 500 or greater, or define
.BR _POSIX_C_SOURCE
with the value 200809L or greater.)
.B F_DUPFD_CLOEXEC
is specified in POSIX.1-2008.
(To get this definition, define
.B _POSIX_C_SOURCE
with the value 200809L or greater, or
.B _XOPEN_SOURCE
with the value 700 or greater.)
.BR F_GETOWN_EX ,
.BR F_SETOWN_EX ,
.BR F_SETPIPE_SZ ,
.BR F_GETPIPE_SZ ,
2007-06-21 05:38:48 +00:00
.BR F_GETSIG ,
.BR F_SETSIG ,
.BR F_NOTIFY ,
.BR F_GETLEASE ,
and
2007-09-20 16:26:31 +00:00
.B F_SETLEASE
2007-12-25 21:28:09 +00:00
are Linux-specific.
2007-06-21 22:55:04 +00:00
(Define the
2007-09-20 16:26:31 +00:00
.B _GNU_SOURCE
2007-06-21 05:38:48 +00:00
macro to obtain these definitions.)
.\" .PP
.\" SVr4 documents additional EIO, ENOLINK and EOVERFLOW error conditions.
.BR F_OFD_SETLK ,
.BR F_OFD_SETLKW ,
and
.BR F_OFD_GETLK
are Linux-specific,
but work is being done to have them included in the next version of POSIX.1.
.\" FIXME Presumably, glibc will require _GNU_SOURCE
2004-11-03 13:51:07 +00:00
.SH NOTES
The errors returned by
.BR dup2 (2)
are different from those returned by
.BR F_DUPFD .
.\"
.SS File locking
The original Linux
.BR fcntl ()
system call was not designed to handle large file offsets
(in the
.I flock
structure).
Consequently, an
.BR fcntl64 ()
system call was added in Linux 2.4.
The newer system call employs a different structure for file locking,
.IR flock64 ,
and corresponding commands,
.BR F_GETLK64 ,
.BR F_SETLK64 ,
and
.BR F_SETLKW64 .
However, these details can be ignored by applications using glibc, whose
.BR fcntl ()
wrapper function transparently employs the more recent system call
where it is available.
The errors returned by
.BR dup2 (2)
are different from those returned by
.BR F_DUPFD .
.SS Record locks
2004-11-03 13:51:07 +00:00
Since kernel 2.0, there is no interaction between the types of lock
placed by
.BR flock (2)
and
.BR fcntl ().
2004-11-03 13:51:07 +00:00
Several systems have more fields in
.I "struct flock"
such as, for example,
2004-11-03 13:51:07 +00:00
.IR l_sysid .
2007-05-27 11:52:46 +00:00
.\" e.g., Solaris 8 documents this field in fcntl(2), and Irix 6.5
.\" documents it in fcntl(5). mtk, May 2007
.\" Also, FreeBSD documents it (Apr 2014).
2004-11-03 13:51:07 +00:00
Clearly,
.I l_pid
alone is not going to be very useful if the process holding the lock
may live on a different machine.
The original Linux
.BR fcntl ()
system call was not designed to handle large file offsets
(in the
.I flock
structure).
Consequently, an
.BR fcntl64 ()
system call was added in Linux 2.4.
The newer system call employs a different structure for file locking,
.IR flock64 ,
and corresponding commands,
.BR F_GETLK64 ,
.BR F_SETLK64 ,
and
.BR F_SETLKW64 .
However, these details can be ignored by applications using glibc, whose
.BR fcntl ()
wrapper function transparently employs the more recent system call
where it is available.
.SS Record locking and NFS
Before Linux 3.12, if an NFSv4 client
loses contact with the server for a period of time
(defined as more than 90 seconds with no communication),
.\"
.\" Neil Brown: With NFSv3 the failure mode is the reverse. If
.\" the server loses contact with a client then any lock stays in place
.\" indefinitely ("why can't I read my mail"... I remember it well).
.\"
it might lose and regain a lock without ever being aware of the fact.
2014-04-29 10:00:44 +00:00
(The period of time after which contact is assumed lost is known as
the NFSv4 leasetime.
On a Linux NFS server, this can be determined by looking at
.IR /proc/fs/nfsd/nfsv4leasetime ,
which expresses the period in seconds.
The default value for this file is 90.)
.\"
.\" Jeff Layton:
.\" Note that this is not a firm timeout. The server runs a job
.\" periodically to clean out expired stateful objects, and it's likely
.\" that there is some time (maybe even up to another whole lease period)
.\" between when the timeout expires and the job actually runs. If the
.\" client gets a RENEW in there within that window, its lease will be
.\" renewed and its state preserved.
.\"
This scenario potentially risks data corruption,
since another process might acquire a lock in the intervening period
and perform file I/O.
Since Linux 3.12,
.\" commit ef1820f9be27b6ad158f433ab38002ab8131db4d
if an NFSv4 client loses contact with the server,
any I/O to the file by a process which "thinks" it holds
a lock will fail until that process closes and reopens the file.
A kernel parameter,
.IR nfs.recover_lost_locks ,
can be set to 1 to obtain the pre-3.12 behavior,
whereby the client will attempt to recover lost locks
when contact is reestablished with the server.
Because of the attendant risk of data corruption,
.\" commit f6de7a39c181dfb8a2c534661a53c73afb3081cd
this parameter defaults to 0 (disabled).
.SH BUGS
.SS F_SETFL
It is not possible to use
.BR F_SETFL
to change the state of the
.BR O_DSYNC
and
.BR O_SYNC
flags.
.\" FIXME . According to POSIX.1-2001, O_SYNC should also be modifiable
.\" via fcntl(2), but currently Linux does not permit this
.\" See http://bugzilla.kernel.org/show_bug.cgi?id=5994
Attempts to change the state of these flags are silently ignored.
.SS F_GETOWN
Date: Mon, 13 Dec 2004 12:09:43 +0100 (MET) From: "Michael Kerrisk" <mtk-manpages@gmx.net> To: Andries Brouwer <Andries.Brouwer@cwi.nl> Subject: Re: errno Hi Andries, > On Fri, Dec 10, 2004 at 05:07:36PM +0100, Michael Kerrisk wrote: > > > I added this text to fcntl.2: > > > > BUGS > > A limitation of the Linux system call conventions means that > > if a (negative) process group ID to be returned by F_GETOWN > > falls in the range -1 to -4095, then the return value is > > wrongly interpreted by glibc as an error in the system call; > > that is, the return value of fcntl() will be -1, and errno > > will contain the (positive) process group ID. > > Yes. > > (Maybe glibc always did this, early libc considered any negative > return value an error. On the other hand, not all the world is an i386 - > IBM has just decided that we don't need any i386's anymore > and sold their stuff to the Chinese - we must use PPC, as Linus > does already - and on other architectures we do not have this > ugliness, I think.) > > You might consider adding "i386" somewhere: > A limitation of the Linux i386 system call conventions ... Some testing on ia64 (RedHat EL 3.0, 2.4.21) and alpha (2.4.18, Debian 3.0) showed that any negative PGID value causes F_GETOWN to fail. My limited reading of the ia64 source: sysdeps/unix/sysv/linux/ia64/sysdep.h shows that there is a comment about the -4095 value there, but that doesn't seem to reflect the reality of the code. Reading the source, the -4095 limit seems to hold on some other architectures, e.g.: sysdeps/unix/sysv/linux/m68k/sysdep.h sysdeps/unix/sysv/linux/hppa/sysdep.h sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h sysdeps/unix/sysv/linux/x86_64/sysdep.h Unfortunately, I have no non-x86 systems other than the above alpha and ia64 (HP-testdrive) on which I can test. I modified the text a little: BUGS A limitation of the Linux system call conventions on some architectures (notably x86) means that if a (negative) pro&#8208; cess group ID to be returned by F_GETOWN falls in the range -1 to -4095, then the return value is wrongly interpreted by glibc as an error in the system call; that is, the return value of fcntl() will be -1, and errno will contain the (positive) process group ID. I've left a FIXME in the man page source noting that details have yet to be sorted out for ia64, alpha, etc.
2004-12-13 11:32:37 +00:00
A limitation of the Linux system call conventions on some
2007-12-24 17:31:35 +00:00
architectures (notably i386) means that if a (negative)
Date: Mon, 13 Dec 2004 12:09:43 +0100 (MET) From: "Michael Kerrisk" <mtk-manpages@gmx.net> To: Andries Brouwer <Andries.Brouwer@cwi.nl> Subject: Re: errno Hi Andries, > On Fri, Dec 10, 2004 at 05:07:36PM +0100, Michael Kerrisk wrote: > > > I added this text to fcntl.2: > > > > BUGS > > A limitation of the Linux system call conventions means that > > if a (negative) process group ID to be returned by F_GETOWN > > falls in the range -1 to -4095, then the return value is > > wrongly interpreted by glibc as an error in the system call; > > that is, the return value of fcntl() will be -1, and errno > > will contain the (positive) process group ID. > > Yes. > > (Maybe glibc always did this, early libc considered any negative > return value an error. On the other hand, not all the world is an i386 - > IBM has just decided that we don't need any i386's anymore > and sold their stuff to the Chinese - we must use PPC, as Linus > does already - and on other architectures we do not have this > ugliness, I think.) > > You might consider adding "i386" somewhere: > A limitation of the Linux i386 system call conventions ... Some testing on ia64 (RedHat EL 3.0, 2.4.21) and alpha (2.4.18, Debian 3.0) showed that any negative PGID value causes F_GETOWN to fail. My limited reading of the ia64 source: sysdeps/unix/sysv/linux/ia64/sysdep.h shows that there is a comment about the -4095 value there, but that doesn't seem to reflect the reality of the code. Reading the source, the -4095 limit seems to hold on some other architectures, e.g.: sysdeps/unix/sysv/linux/m68k/sysdep.h sysdeps/unix/sysv/linux/hppa/sysdep.h sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h sysdeps/unix/sysv/linux/x86_64/sysdep.h Unfortunately, I have no non-x86 systems other than the above alpha and ia64 (HP-testdrive) on which I can test. I modified the text a little: BUGS A limitation of the Linux system call conventions on some architectures (notably x86) means that if a (negative) pro&#8208; cess group ID to be returned by F_GETOWN falls in the range -1 to -4095, then the return value is wrongly interpreted by glibc as an error in the system call; that is, the return value of fcntl() will be -1, and errno will contain the (positive) process group ID. I've left a FIXME in the man page source noting that details have yet to be sorted out for ia64, alpha, etc.
2004-12-13 11:32:37 +00:00
process group ID to be returned by
.B F_GETOWN
2005-06-15 14:10:23 +00:00
falls in the range \-1 to \-4095, then the return value is wrongly
interpreted by glibc as an error in the system call;
Date: Mon, 13 Dec 2004 12:09:43 +0100 (MET) From: "Michael Kerrisk" <mtk-manpages@gmx.net> To: Andries Brouwer <Andries.Brouwer@cwi.nl> Subject: Re: errno Hi Andries, > On Fri, Dec 10, 2004 at 05:07:36PM +0100, Michael Kerrisk wrote: > > > I added this text to fcntl.2: > > > > BUGS > > A limitation of the Linux system call conventions means that > > if a (negative) process group ID to be returned by F_GETOWN > > falls in the range -1 to -4095, then the return value is > > wrongly interpreted by glibc as an error in the system call; > > that is, the return value of fcntl() will be -1, and errno > > will contain the (positive) process group ID. > > Yes. > > (Maybe glibc always did this, early libc considered any negative > return value an error. On the other hand, not all the world is an i386 - > IBM has just decided that we don't need any i386's anymore > and sold their stuff to the Chinese - we must use PPC, as Linus > does already - and on other architectures we do not have this > ugliness, I think.) > > You might consider adding "i386" somewhere: > A limitation of the Linux i386 system call conventions ... Some testing on ia64 (RedHat EL 3.0, 2.4.21) and alpha (2.4.18, Debian 3.0) showed that any negative PGID value causes F_GETOWN to fail. My limited reading of the ia64 source: sysdeps/unix/sysv/linux/ia64/sysdep.h shows that there is a comment about the -4095 value there, but that doesn't seem to reflect the reality of the code. Reading the source, the -4095 limit seems to hold on some other architectures, e.g.: sysdeps/unix/sysv/linux/m68k/sysdep.h sysdeps/unix/sysv/linux/hppa/sysdep.h sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h sysdeps/unix/sysv/linux/x86_64/sysdep.h Unfortunately, I have no non-x86 systems other than the above alpha and ia64 (HP-testdrive) on which I can test. I modified the text a little: BUGS A limitation of the Linux system call conventions on some architectures (notably x86) means that if a (negative) pro&#8208; cess group ID to be returned by F_GETOWN falls in the range -1 to -4095, then the return value is wrongly interpreted by glibc as an error in the system call; that is, the return value of fcntl() will be -1, and errno will contain the (positive) process group ID. I've left a FIXME in the man page source noting that details have yet to be sorted out for ia64, alpha, etc.
2004-12-13 11:32:37 +00:00
.\" glibc source: sysdeps/unix/sysv/linux/i386/sysdep.h
that is, the return value of
.BR fcntl ()
will be \-1, and
.I errno
will contain the (positive) process group ID.
The Linux-specific
.BR F_GETOWN_EX
operation avoids this problem.
2007-06-13 21:48:16 +00:00
.\" mtk, Dec 04: some limited testing on alpha and ia64 seems to
Date: Mon, 13 Dec 2004 12:09:43 +0100 (MET) From: "Michael Kerrisk" <mtk-manpages@gmx.net> To: Andries Brouwer <Andries.Brouwer@cwi.nl> Subject: Re: errno Hi Andries, > On Fri, Dec 10, 2004 at 05:07:36PM +0100, Michael Kerrisk wrote: > > > I added this text to fcntl.2: > > > > BUGS > > A limitation of the Linux system call conventions means that > > if a (negative) process group ID to be returned by F_GETOWN > > falls in the range -1 to -4095, then the return value is > > wrongly interpreted by glibc as an error in the system call; > > that is, the return value of fcntl() will be -1, and errno > > will contain the (positive) process group ID. > > Yes. > > (Maybe glibc always did this, early libc considered any negative > return value an error. On the other hand, not all the world is an i386 - > IBM has just decided that we don't need any i386's anymore > and sold their stuff to the Chinese - we must use PPC, as Linus > does already - and on other architectures we do not have this > ugliness, I think.) > > You might consider adding "i386" somewhere: > A limitation of the Linux i386 system call conventions ... Some testing on ia64 (RedHat EL 3.0, 2.4.21) and alpha (2.4.18, Debian 3.0) showed that any negative PGID value causes F_GETOWN to fail. My limited reading of the ia64 source: sysdeps/unix/sysv/linux/ia64/sysdep.h shows that there is a comment about the -4095 value there, but that doesn't seem to reflect the reality of the code. Reading the source, the -4095 limit seems to hold on some other architectures, e.g.: sysdeps/unix/sysv/linux/m68k/sysdep.h sysdeps/unix/sysv/linux/hppa/sysdep.h sysdeps/unix/sysv/linux/s390/s390-32/sysdep.h sysdeps/unix/sysv/linux/s390/s390-64/sysdep.h sysdeps/unix/sysv/linux/x86_64/sysdep.h Unfortunately, I have no non-x86 systems other than the above alpha and ia64 (HP-testdrive) on which I can test. I modified the text a little: BUGS A limitation of the Linux system call conventions on some architectures (notably x86) means that if a (negative) pro&#8208; cess group ID to be returned by F_GETOWN falls in the range -1 to -4095, then the return value is wrongly interpreted by glibc as an error in the system call; that is, the return value of fcntl() will be -1, and errno will contain the (positive) process group ID. I've left a FIXME in the man page source noting that details have yet to be sorted out for ia64, alpha, etc.
2004-12-13 11:32:37 +00:00
.\" indicate that ANY negative PGID value will cause F_GETOWN
2005-04-18 13:35:29 +00:00
.\" to misinterpret the return as an error. Some other architectures
2007-12-24 17:31:35 +00:00
.\" seem to have the same range check as i386.
Since glibc version 2.11, glibc makes the kernel
.B F_GETOWN
problem invisible by implementing
.B F_GETOWN
using
.BR F_GETOWN_EX .
.SS F_SETOWN
Noted F_SETOWN bug for socket file descriptor in Linux 2.4 and earlier. Added text on permissions required to send signal to owner. ==== Hello Johannes, > Betreff: Inaccuracy of fcntl man page > Datum: Mon, 2 May 2005 20:07:12 +0200 Thanks for yor note. Sorry for the delay in getting back to you. I needed to find time to set aside to look at the details. Now I've finally got there. > I have attached a simple program Thanks -- a little program is always helpful. > that uses the fcntl system call in order > to kill an arbitrary process of the same user. > According to the fcntl man page, fcntl(fd,F_SETOWN,pid) returns zero if > it has success. Yes. > If you strace the program while killing for exampe man running in another > terminal, you will see that man is killed, but fcntl(fd,F_SETOWN,pid) > will return EPERM, I confirm that I see this problem in 2.4, with both Unix domain and Internet domain sockets. > where you can only find a very confusing explanation > in the fcntl man page. I'm not sure what explanation you mean here. As far as I can tell, the manual page just doesn't cover this point. > I have looked into the kernel source of 2.4.30 and found out, that > net/core/socket::sock_no_fcntl is the culprit if you use fcntl on Unix > sockets. Yes, looks that way to me, as well, And the 2.2 code looks similar. > If pid is not your own pid or not your own process group, > the system call will return EPERM but will also set the pid > as you wanted to. Yes. > In the 2.6 kernel line, fcntl will react according the specification in > the manual page. Yes. > If you also think, that one should clarify the return specification of > fcntl(fd,F_SETOWN,pid) or 2.4.x kernels, please tell me and I will > provide you with a patch for the manual page. In fact I've written some new text under BUGS, which describes the problem: In Linux 2.4 and earlier, there is bug that can occur when an unprivileged process uses F_SETOWN to specify the owner of a socket file descriptor as a process (group) other than the caller. In this case, fcntl() can return -1 with errno set to EPERM, even when the owner process (group) is one that the caller has permission to send signals to. Despite this error return, the file descriptor owner is set, and signals will be sent to the owner. Does that seem okay to you? > Furthermore, it would be interseting to write there, what permissions > one need in order to send signals to processes via fcntl Good idea. I added the following new text: Sending a signal to the owner process (group) specified by F_SETOWN is subject to the same permissions checks as are described for kill(2), where the sending process is the one that employs F_SETOWN (but see BUGS below). ==== #define _GNU_SOURCE /* needed to get the defines */ #include <fcntl.h> /* in glibc 2.2 this has the needed values defined */ #include <signal.h> #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> /** * Funnykill kills a program with fcntl **/ int main (int argc, char **argv) { if (argc != 2) { fprintf (stderr, "Usage: funnykill <pid>\n"); return 1; } int sockets[2]; socketpair (AF_UNIX, SOCK_STREAM, 0, sockets); if (fcntl (sockets[0], F_SETFL, O_ASYNC | O_NONBLOCK) == -1) errMsg("fcntl-F_SETFL"); if (fcntl (sockets[0], F_SETOWN, atoi (argv[1])) == -1) errMsg("fcntl-F_SETOWN"); // fcntl (sockets[0], F_SETOWN, getpid()); if (fcntl (sockets[0], F_SETSIG, SIGKILL) == -1) errMsg("fcntl-_FSETSIG"); write (sockets[1], "good bye", 9); }
2005-05-20 12:11:25 +00:00
In Linux 2.4 and earlier, there is bug that can occur
when an unprivileged process uses
.B F_SETOWN
to specify the owner
of a socket file descriptor
Noted F_SETOWN bug for socket file descriptor in Linux 2.4 and earlier. Added text on permissions required to send signal to owner. ==== Hello Johannes, > Betreff: Inaccuracy of fcntl man page > Datum: Mon, 2 May 2005 20:07:12 +0200 Thanks for yor note. Sorry for the delay in getting back to you. I needed to find time to set aside to look at the details. Now I've finally got there. > I have attached a simple program Thanks -- a little program is always helpful. > that uses the fcntl system call in order > to kill an arbitrary process of the same user. > According to the fcntl man page, fcntl(fd,F_SETOWN,pid) returns zero if > it has success. Yes. > If you strace the program while killing for exampe man running in another > terminal, you will see that man is killed, but fcntl(fd,F_SETOWN,pid) > will return EPERM, I confirm that I see this problem in 2.4, with both Unix domain and Internet domain sockets. > where you can only find a very confusing explanation > in the fcntl man page. I'm not sure what explanation you mean here. As far as I can tell, the manual page just doesn't cover this point. > I have looked into the kernel source of 2.4.30 and found out, that > net/core/socket::sock_no_fcntl is the culprit if you use fcntl on Unix > sockets. Yes, looks that way to me, as well, And the 2.2 code looks similar. > If pid is not your own pid or not your own process group, > the system call will return EPERM but will also set the pid > as you wanted to. Yes. > In the 2.6 kernel line, fcntl will react according the specification in > the manual page. Yes. > If you also think, that one should clarify the return specification of > fcntl(fd,F_SETOWN,pid) or 2.4.x kernels, please tell me and I will > provide you with a patch for the manual page. In fact I've written some new text under BUGS, which describes the problem: In Linux 2.4 and earlier, there is bug that can occur when an unprivileged process uses F_SETOWN to specify the owner of a socket file descriptor as a process (group) other than the caller. In this case, fcntl() can return -1 with errno set to EPERM, even when the owner process (group) is one that the caller has permission to send signals to. Despite this error return, the file descriptor owner is set, and signals will be sent to the owner. Does that seem okay to you? > Furthermore, it would be interseting to write there, what permissions > one need in order to send signals to processes via fcntl Good idea. I added the following new text: Sending a signal to the owner process (group) specified by F_SETOWN is subject to the same permissions checks as are described for kill(2), where the sending process is the one that employs F_SETOWN (but see BUGS below). ==== #define _GNU_SOURCE /* needed to get the defines */ #include <fcntl.h> /* in glibc 2.2 this has the needed values defined */ #include <signal.h> #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> /** * Funnykill kills a program with fcntl **/ int main (int argc, char **argv) { if (argc != 2) { fprintf (stderr, "Usage: funnykill <pid>\n"); return 1; } int sockets[2]; socketpair (AF_UNIX, SOCK_STREAM, 0, sockets); if (fcntl (sockets[0], F_SETFL, O_ASYNC | O_NONBLOCK) == -1) errMsg("fcntl-F_SETFL"); if (fcntl (sockets[0], F_SETOWN, atoi (argv[1])) == -1) errMsg("fcntl-F_SETOWN"); // fcntl (sockets[0], F_SETOWN, getpid()); if (fcntl (sockets[0], F_SETSIG, SIGKILL) == -1) errMsg("fcntl-_FSETSIG"); write (sockets[1], "good bye", 9); }
2005-05-20 12:11:25 +00:00
as a process (group) other than the caller.
In this case,
.BR fcntl ()
can return \-1 with
.I errno
set to
.BR EPERM ,
even when the owner process (group) is one that the caller
has permission to send signals to.
Despite this error return, the file descriptor owner is set,
and signals will be sent to the owner.
.\"
.SS Deadlock detection
The deadlock-detection algorithm employed by the kernel when dealing with
.BR F_SETLKW
requests can yield both
false negatives (failures to detect deadlocks,
leaving a set of deadlocked processes blocked indefinitely)
and false positives
.RB ( EDEADLK
errors when there is no deadlock).
For example,
the kernel limits the lock depth of its dependency search to 10 steps,
meaning that circular deadlock chains that exceed
that size will not be detected.
In addition, the kernel may falsely indicate a deadlock
when two or more processes created using the
.BR clone (2)
.B CLONE_FILES
flag place locks that appear (to the kernel) to conflict.
.\"
.SS Mandatory locking
The Linux implementation of mandatory locking
2007-12-23 17:30:21 +00:00
is subject to race conditions which render it unreliable:
.\" http://marc.info/?l=linux-kernel&m=119013491707153&w=2
.\"
.\" Reconfirmed by Jeff Layton
.\" From: Jeff Layton <jlayton <at> redhat.com>
.\" Subject: Re: Status of fcntl() mandatory locking
.\" Newsgroups: gmane.linux.file-systems
.\" Date: 2014-04-28 10:07:57 GMT
.\" http://thread.gmane.org/gmane.linux.file-systems/84481/focus=84518
a
.BR write (2)
call that overlaps with a lock may modify data after the mandatory lock is
acquired;
a
.BR read (2)
call that overlaps with a lock may detect changes to data that were made
only after a write lock was acquired.
Similar races exist between mandatory locks and
.BR mmap (2).
It is therefore inadvisable to rely on mandatory locking.
getent.1, intro.1, time.1, _exit.2, _syscall.2, accept.2, access.2, acct.2, adjtimex.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bdflush.2, bind.2, brk.2, cacheflush.2, capget.2, chdir.2, chmod.2, chown.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, exit_group.2, faccessat.2, fchmodat.2, fchownat.2, fcntl.2, flock.2, fork.2, fstatat.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_robust_list.2, get_thread_area.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpid.2, getpriority.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, getxattr.2, idle.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl.2, ioctl_list.2, ioperm.2, iopl.2, ioprio_set.2, ipc.2, kcmp.2, kill.2, killpg.2, link.2, linkat.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, migrate_pages.2, mincore.2, mkdir.2, mkdirat.2, mknod.2, mknodat.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, mount.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open.2, openat.2, outb.2, pause.2, pciconfig_read.2, perf_event_open.2, perfmonctl.2, personality.2, pipe.2, pivot_root.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readlink.2, readlinkat.2, readv.2, reboot.2, recv.2, remap_file_pages.2, removexattr.2, rename.2, renameat.2, rmdir.2, rt_sigqueueinfo.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, setup.2, setxattr.2, shmctl.2, shmget.2, shmop.2, shutdown.2, sigaction.2, sigaltstack.2, signal.2, signalfd.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, stat.2, statfs.2, stime.2, swapon.2, symlink.2, symlinkat.2, sync.2, sync_file_range.2, sysctl.2, sysfs.2, sysinfo.2, syslog.2, tee.2, time.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, uname.2, unimplemented.2, unlink.2, unlinkat.2, uselib.2, ustat.2, utime.2, utimensat.2, vfork.2, vhangup.2, vm86.2, vmsplice.2, wait.2, wait4.2, write.2, CPU_SET.3, INFINITY.3, MB_CUR_MAX.3, MB_LEN_MAX.3, __setfpucw.3, a64l.3, abort.3, abs.3, acos.3, acosh.3, addseverity.3, adjtime.3, aio_cancel.3, aio_error.3, aio_fsync.3, aio_read.3, aio_return.3, aio_suspend.3, aio_write.3, alloca.3, argz_add.3, asin.3, asinh.3, asprintf.3, assert.3, assert_perror.3, atan.3, atan2.3, atanh.3, atexit.3, atof.3, atoi.3, backtrace.3, basename.3, bcmp.3, bcopy.3, bindresvport.3, bsd_signal.3, bsearch.3, bstring.3, btowc.3, btree.3, byteorder.3, bzero.3, cabs.3, cacos.3, cacosh.3, canonicalize_file_name.3, carg.3, casin.3, casinh.3, catan.3, catanh.3, catgets.3, catopen.3, cbrt.3, ccos.3, ccosh.3, ceil.3, cerf.3, cexp.3, cexp2.3, cfree.3, cimag.3, clearenv.3, clock.3, clock_getcpuclockid.3, clog.3, clog10.3, clog2.3, closedir.3, cmsg.3, confstr.3, conj.3, copysign.3, cos.3, cosh.3, cpow.3, cproj.3, creal.3, crypt.3, csin.3, csinh.3, csqrt.3, ctan.3, ctanh.3, ctermid.3, ctime.3, daemon.3, dbopen.3, des_crypt.3, difftime.3, dirfd.3, div.3, dl_iterate_phdr.3, dlopen.3, dprintf.3, drand48.3, drand48_r.3, dysize.3, ecvt.3, ecvt_r.3, encrypt.3, end.3, endian.3, envz_add.3, erf.3, erfc.3, err.3, errno.3, error.3, ether_aton.3, euidaccess.3, exec.3, exit.3, exp.3, exp10.3, exp2.3, expm1.3, fabs.3, fclose.3, fcloseall.3, fdim.3, fenv.3, ferror.3, fexecve.3, fflush.3, ffs.3, fgetgrent.3, fgetpwent.3, fgetwc.3, fgetws.3, finite.3, flockfile.3, floor.3, fma.3, fmax.3, fmemopen.3, fmin.3, fmod.3, fmtmsg.3, fnmatch.3, fopen.3, fpathconf.3, fpclassify.3, fpurge.3, fputwc.3, fputws.3, fread.3, frexp.3, fseek.3, fseeko.3, ftime.3, ftok.3, fts.3, ftw.3, futimes.3, fwide.3, gamma.3, gcvt.3, getaddrinfo.3, getaddrinfo_a.3, getauxval.3, getcontext.3, getcwd.3, getdate.3, getdirentries.3, getdtablesize.3, getenv.3, getfsent.3, getgrent.3, getgrent_r.3, getgrnam.3, getgrouplist.3, gethostbyname.3, gethostid.3, getipnodebyname.3, getline.3, getloadavg.3, getlogin.3, getmntent.3, getnameinfo.3, getnetent.3, getnetent_r.3, getopt.3, getpass.3, getprotoent.3, getprotoent_r.3, getpt.3, getpw.3, getpwent.3, getpwent_r.3, getpwnam.3, getrpcent.3, getrpcent_r.3, getrpcport.3, gets.3, getservent.3, getservent_r.3, getspnam.3, getttyent.3, getumask.3, getusershell.3, getutent.3, getw.3, getwchar.3, glob.3, grantpt.3, gsignal.3, hash.3, hsearch.3, hypot.3, iconv.3, iconv_close.3, iconv_open.3, ilogb.3, index.3, inet.3, inet_ntop.3, inet_pton.3, infnan.3, initgroups.3, insque.3, intro.3, isalpha.3, isatty.3, isgreater.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, j0.3, key_setsecret.3, ldexp.3, lgamma.3, lio_listio.3, localeconv.3, lockf.3, log.3, log10.3, log1p.3, log2.3, logb.3, login.3, longjmp.3, lrint.3, lround.3, lsearch.3, lseek64.3, makecontext.3, makedev.3, malloc.3, malloc_hook.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, memccpy.3, memchr.3, memcmp.3, memcpy.3, memfrob.3, memmem.3, memmove.3, mempcpy.3, memset.3, mkdtemp.3, mkfifo.3, mkfifoat.3, mkstemp.3, mktemp.3, modf.3, mpool.3, mq_close.3, mq_getattr.3, mq_notify.3, mq_open.3, mq_receive.3, mq_send.3, mq_unlink.3, mtrace.3, nan.3, netlink.3, nextafter.3, nl_langinfo.3, offsetof.3, on_exit.3, opendir.3, openpty.3, perror.3, popen.3, posix_fallocate.3, posix_memalign.3, posix_openpt.3, pow.3, pow10.3, printf.3, profil.3, program_invocation_name.3, psignal.3, pthread_kill_other_threads_np.3, ptsname.3, putenv.3, putgrent.3, putpwent.3, puts.3, putwchar.3, qecvt.3, qsort.3, queue.3, raise.3, rand.3, random.3, random_r.3, rcmd.3, re_comp.3, readdir.3, realpath.3, recno.3, regex.3, remainder.3, remove.3, remquo.3, resolver.3, rewinddir.3, rexec.3, rint.3, round.3, rpc.3, rpmatch.3, rtime.3, rtnetlink.3, scalb.3, scalbln.3, scandir.3, scandirat.3, scanf.3, seekdir.3, sem_close.3, sem_destroy.3, sem_getvalue.3, sem_init.3, sem_open.3, sem_post.3, sem_unlink.3, sem_wait.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, setlocale.3, setlogmask.3, setnetgrent.3, shm_open.3, siginterrupt.3, signbit.3, significand.3, sigpause.3, sigqueue.3, sigset.3, sigsetops.3, sigvec.3, sin.3, sincos.3, sinh.3, sleep.3, sockatmark.3, sqrt.3, statvfs.3, stdarg.3, stdin.3, stdio.3, stdio_ext.3, stpcpy.3, stpncpy.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strdup.3, strerror.3, strfmon.3, strfry.3, strftime.3, string.3, strlen.3, strnlen.3, strpbrk.3, strptime.3, strsep.3, strsignal.3, strspn.3, strstr.3, strtod.3, strtoimax.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, swab.3, sysconf.3, syslog.3, system.3, sysv_signal.3, tan.3, tanh.3, tcgetpgrp.3, tcgetsid.3, telldir.3, tempnam.3, termios.3, tgamma.3, timegm.3, timeradd.3, tmpfile.3, tmpnam.3, toascii.3, toupper.3, towctrans.3, towlower.3, towupper.3, trunc.3, tsearch.3, ttyname.3, ttyslot.3, tzset.3, ualarm.3, ulimit.3, ungetwc.3, unlocked_stdio.3, unlockpt.3, updwtmp.3, usleep.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstoimax.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wordexp.3, wprintf.3, xcrypt.3, xdr.3, y0.3, cciss.4, console.4, console_codes.4, console_ioctl.4, dsp56k.4, fd.4, full.4, hd.4, hpsa.4, initrd.4, intro.4, lp.4, mem.4, mouse.4, null.4, pts.4, ram.4, random.4, rtc.4, sk98lin.4, st.4, tty.4, ttyS.4, tty_ioctl.4, vcs.4, wavelan.4, acct.5, charmap.5, dir_colors.5, filesystems.5, ftpusers.5, group.5, host.conf.5, hosts.5, hosts.equiv.5, intro.5, issue.5, locale.5, motd.5, networks.5, nologin.5, nscd.conf.5, passwd.5, proc.5, protocols.5, resolv.conf.5, rpc.5, securetty.5, services.5, shells.5, termcap.5, ttytype.5, utmp.5, armscii-8.7, arp.7, ascii.7, bootparam.7, capabilities.7, charsets.7, complex.7, cp1251.7, credentials.7, ddp.7, environ.7, epoll.7, fifo.7, futex.7, glob.7, hier.7, icmp.7, inotify.7, intro.7, ip.7, ipv6.7, iso_8859-1.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-15.7, iso_8859-16.7, iso_8859-2.7, iso_8859-3.7, iso_8859-4.7, iso_8859-5.7, iso_8859-6.7, iso_8859-7.7, iso_8859-8.7, iso_8859-9.7, koi8-r.7, koi8-u.7, locale.7, mailaddr.7, man.7, mq_overview.7, netdevice.7, netlink.7, numa.7, packet.7, path_resolution.7, pipe.7, posixoptions.7, pthreads.7, pty.7, raw.7, regex.7, rtld-audit.7, rtnetlink.7, sem_overview.7, shm_overview.7, sigevent.7, signal.7, socket.7, standards.7, suffixes.7, svipc.7, tcp.7, termio.7, time.7, udp.7, udplite.7, unicode.7, unix.7, uri.7, utf-8.7, x25.7, nscd.8, sync.8, tzselect.8, zdump.8, zic.8: Global fix: remove unneeded double quotes in .SH headings Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-02-24 18:01:36 +00:00
.SH SEE ALSO
2004-11-03 13:51:07 +00:00
.BR dup2 (2),
.BR flock (2),
.BR open (2),
.BR socket (2),
.BR lockf (3),
2006-04-21 06:49:34 +00:00
.BR capabilities (7),
2006-05-15 09:13:10 +00:00
.BR feature_test_macros (7)
.IR locks.txt ,
.IR mandatory-locking.txt ,
2007-06-21 22:55:04 +00:00
and
.I dnotify.txt
in the Linux kernel source directory
.IR Documentation/filesystems/
(on older kernels, these files are directly under the
.I Documentation/
directory, and
.I mandatory-locking.txt
is called
.IR mandatory.txt )