1*0a6a1f1dSLionel Sambuc.\" $NetBSD: fcntl.2,v 1.41 2013/12/28 20:03:22 dholland Exp $ 22fe8fb19SBen Gras.\" 32fe8fb19SBen Gras.\" Copyright (c) 1983, 1993 42fe8fb19SBen Gras.\" The Regents of the University of California. All rights reserved. 52fe8fb19SBen Gras.\" 62fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 72fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 82fe8fb19SBen Gras.\" are met: 92fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 102fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 112fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 122fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 132fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 142fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 152fe8fb19SBen Gras.\" may be used to endorse or promote products derived from this software 162fe8fb19SBen Gras.\" without specific prior written permission. 172fe8fb19SBen Gras.\" 182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 192fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 202fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212fe8fb19SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 222fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 232fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 242fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 252fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 262fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 272fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 282fe8fb19SBen Gras.\" SUCH DAMAGE. 292fe8fb19SBen Gras.\" 302fe8fb19SBen Gras.\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 312fe8fb19SBen Gras.\" 32f14fb602SLionel Sambuc.Dd January 23, 2012 332fe8fb19SBen Gras.Dt FCNTL 2 342fe8fb19SBen Gras.Os 352fe8fb19SBen Gras.Sh NAME 362fe8fb19SBen Gras.Nm fcntl 372fe8fb19SBen Gras.Nd file descriptor control 382fe8fb19SBen Gras.Sh LIBRARY 392fe8fb19SBen Gras.Lb libc 402fe8fb19SBen Gras.Sh SYNOPSIS 412fe8fb19SBen Gras.In fcntl.h 422fe8fb19SBen Gras.Ft int 432fe8fb19SBen Gras.Fn fcntl "int fd" "int cmd" "..." 442fe8fb19SBen Gras.Sh DESCRIPTION 452fe8fb19SBen Gras.Fn fcntl 462fe8fb19SBen Grasprovides for control over descriptors. 472fe8fb19SBen GrasThe argument 482fe8fb19SBen Gras.Fa fd 492fe8fb19SBen Grasis a descriptor to be operated on by 502fe8fb19SBen Gras.Fa cmd 512fe8fb19SBen Grasas described below. 522fe8fb19SBen GrasThe third parameter is called 532fe8fb19SBen Gras.Fa arg 542fe8fb19SBen Grasand is technically a pointer to void, but it is 552fe8fb19SBen Grasinterpreted as an int by some commands and ignored by others. 562fe8fb19SBen Gras.Pp 572fe8fb19SBen GrasCommands are: 58f14fb602SLionel Sambuc.Bl -tag -width F_DUPFD_CLOEXEC 592fe8fb19SBen Gras.It Dv F_DUPFD 602fe8fb19SBen GrasReturn a new descriptor as follows: 612fe8fb19SBen Gras.Pp 622fe8fb19SBen Gras.Bl -bullet -compact -offset 4n 632fe8fb19SBen Gras.It 642fe8fb19SBen GrasLowest numbered available descriptor greater than or equal to 652fe8fb19SBen Gras.Fa arg , 662fe8fb19SBen Graswhich is interpreted as an int. 672fe8fb19SBen Gras.It 682fe8fb19SBen GrasSame object references as the original descriptor. 692fe8fb19SBen Gras.It 702fe8fb19SBen GrasNew descriptor shares the same file offset if the object 712fe8fb19SBen Graswas a file. 722fe8fb19SBen Gras.It 732fe8fb19SBen GrasSame access mode (read, write or read/write). 742fe8fb19SBen Gras.It 752fe8fb19SBen GrasSame file status flags (i.e., both file descriptors 762fe8fb19SBen Grasshare the same file status flags). 772fe8fb19SBen Gras.It 782fe8fb19SBen GrasThe close-on-exec flag associated with the new file descriptor 792fe8fb19SBen Grasis cleared to remain open across 802fe8fb19SBen Gras.Xr execve 2 812fe8fb19SBen Grassystem calls. 822fe8fb19SBen Gras.El 83f14fb602SLionel Sambuc.It Dv F_DUPFD_CLOEXEC 84f14fb602SLionel SambucSame as 85f14fb602SLionel Sambuc.Dv F_DUPFD , 86f14fb602SLionel Sambucbut sets the close-on-exec property on the file descriptor created. 872fe8fb19SBen Gras.It Dv F_GETFD 882fe8fb19SBen GrasGet the close-on-exec flag associated with the file descriptor 892fe8fb19SBen Gras.Fa fd 902fe8fb19SBen Grasas 912fe8fb19SBen Gras.Dv FD_CLOEXEC . 922fe8fb19SBen GrasIf the returned value ANDed with 932fe8fb19SBen Gras.Dv FD_CLOEXEC 942fe8fb19SBen Grasis 0, 952fe8fb19SBen Grasthe file will remain open across 962fe8fb19SBen Gras.Fn exec , 972fe8fb19SBen Grasotherwise the file will be closed upon execution of 982fe8fb19SBen Gras.Fn exec 992fe8fb19SBen Gras.Fa ( arg 1002fe8fb19SBen Grasis ignored). 1012fe8fb19SBen Gras.It Dv F_SETFD 1022fe8fb19SBen GrasSet the close-on-exec flag associated with 1032fe8fb19SBen Gras.Fa fd 1042fe8fb19SBen Grasto 1052fe8fb19SBen Gras.Fa arg , 1062fe8fb19SBen Graswhere 1072fe8fb19SBen Gras.Fa arg 1082fe8fb19SBen Grasis either 0 or 1092fe8fb19SBen Gras.Dv FD_CLOEXEC , 1102fe8fb19SBen Grasas described above. 1112fe8fb19SBen Gras.It Dv F_GETFL 1122fe8fb19SBen GrasGet descriptor status flags, as described below 1132fe8fb19SBen Gras.Fa ( arg 1142fe8fb19SBen Grasis ignored). 1152fe8fb19SBen Gras.It Dv F_SETFL 1162fe8fb19SBen GrasSet descriptor status flags to 1172fe8fb19SBen Gras.Fa arg , 1182fe8fb19SBen Graswhich is interpreted as an int. 1192fe8fb19SBen Gras.It Dv F_GETOWN 1202fe8fb19SBen GrasGet the process ID or process group 1212fe8fb19SBen Grascurrently receiving 1222fe8fb19SBen Gras.Dv SIGIO 1232fe8fb19SBen Grasand 1242fe8fb19SBen Gras.Dv SIGURG 1252fe8fb19SBen Grassignals; process groups are returned 1262fe8fb19SBen Grasas negative values 1272fe8fb19SBen Gras.Fa ( arg 1282fe8fb19SBen Grasis ignored). 1292fe8fb19SBen Gras.It Dv F_SETOWN 1302fe8fb19SBen GrasSet the process or process group 1312fe8fb19SBen Grasto receive 1322fe8fb19SBen Gras.Dv SIGIO 1332fe8fb19SBen Grasand 1342fe8fb19SBen Gras.Dv SIGURG 1352fe8fb19SBen Grassignals; 1362fe8fb19SBen Grasprocess groups are specified by supplying 1372fe8fb19SBen Gras.Fa arg 1382fe8fb19SBen Grasas negative, otherwise 1392fe8fb19SBen Gras.Fa arg 1402fe8fb19SBen Grasis interpreted as a process ID. 1412fe8fb19SBen GrasThe argument 1422fe8fb19SBen Gras.Fa arg 1432fe8fb19SBen Grasis interpreted as an int. 1442fe8fb19SBen Gras.It Dv F_CLOSEM 1452fe8fb19SBen GrasClose all file descriptors greater than or equal to 1462fe8fb19SBen Gras.Ar fd . 1472fe8fb19SBen Gras.It Dv F_MAXFD 1482fe8fb19SBen GrasReturn the maximum file descriptor number currently open by the process. 149f14fb602SLionel Sambuc.It Dv F_GETNOSIGPIPE 150f14fb602SLionel SambucReturn if the 151f14fb602SLionel Sambuc.Dv O_NOSIGPIPE 152f14fb602SLionel Sambucflag is set in the file descriptor. 153f14fb602SLionel Sambuc.It Dv F_SETNOSIGPIPE 154f14fb602SLionel SambucSet or clear the 155f14fb602SLionel Sambuc.Dv O_NOSIGPIPE 156f14fb602SLionel Sambucin the file descriptor. 1572fe8fb19SBen Gras.El 1582fe8fb19SBen Gras.Pp 159f14fb602SLionel SambucThe set of valid flags for the 1602fe8fb19SBen Gras.Dv F_GETFL 1612fe8fb19SBen Grasand 1622fe8fb19SBen Gras.Dv F_SETFL 1632fe8fb19SBen Grasflags are as follows: 164f14fb602SLionel Sambuc.Dv O_APPEND , 165f14fb602SLionel Sambuc.Dv O_ASYNC , 166*0a6a1f1dSLionel Sambuc.Dv O_SYNC , 167f14fb602SLionel Sambuc.Dv O_NONBLOCK , 168f14fb602SLionel Sambuc.Dv O_DSYNC , 169f14fb602SLionel Sambuc.Dv O_RSYNC , 170f14fb602SLionel Sambuc.Dv O_ALT_IO , 171f14fb602SLionel Sambuc.Dv O_DIRECT , 172f14fb602SLionel Sambuc.Dv O_NOSIGPIPE . 173f14fb602SLionel SambucThese flags are described in 1742fe8fb19SBen Gras.Xr open 2 . 1752fe8fb19SBen Gras.Pp 1762fe8fb19SBen GrasSeveral commands are available for doing advisory file locking; 1772fe8fb19SBen Grasthey all operate on the following structure: 1782fe8fb19SBen Gras.Bd -literal 1792fe8fb19SBen Grasstruct flock { 1802fe8fb19SBen Gras off_t l_start; /* starting offset */ 1812fe8fb19SBen Gras off_t l_len; /* len = 0 means until end of file */ 1822fe8fb19SBen Gras pid_t l_pid; /* lock owner */ 1832fe8fb19SBen Gras short l_type; /* lock type: read/write, etc. */ 1842fe8fb19SBen Gras short l_whence; /* type of l_start */ 1852fe8fb19SBen Gras}; 1862fe8fb19SBen Gras.Ed 1872fe8fb19SBen Gras.Pp 1882fe8fb19SBen GrasThe commands available for advisory record locking are as follows: 1892fe8fb19SBen Gras.Bl -tag -width F_SETLKWX 1902fe8fb19SBen Gras.It Dv F_GETLK 1912fe8fb19SBen GrasGet the first lock that blocks the lock description pointed to by the 1922fe8fb19SBen Grasthird argument, 1932fe8fb19SBen Gras.Fa arg , 1942fe8fb19SBen Grastaken as a pointer to a 1952fe8fb19SBen Gras.Fa "struct flock" 1962fe8fb19SBen Gras(see above). 1972fe8fb19SBen GrasThe information retrieved overwrites the information passed to 1982fe8fb19SBen Gras.Nm 1992fe8fb19SBen Grasin the 2002fe8fb19SBen Gras.Fa flock 2012fe8fb19SBen Grasstructure. 2022fe8fb19SBen GrasIf no lock is found that would prevent this lock from being created, 2032fe8fb19SBen Grasthe structure is left unchanged by this function call except for the 2042fe8fb19SBen Graslock type 2052fe8fb19SBen Gras.Fa l_type , 2062fe8fb19SBen Graswhich is set to 2072fe8fb19SBen Gras.Dv F_UNLCK . 2082fe8fb19SBen Gras.It Dv F_SETLK 2092fe8fb19SBen GrasSet or clear a file segment lock according to the lock description 2102fe8fb19SBen Graspointed to by the third argument, 2112fe8fb19SBen Gras.Fa arg , 2122fe8fb19SBen Grastaken as a pointer to a 2132fe8fb19SBen Gras.Fa "struct flock" 2142fe8fb19SBen Gras(see above). 2152fe8fb19SBen GrasAs specified by the value of 2162fe8fb19SBen Gras.Fa l_type , 2172fe8fb19SBen Gras.Dv F_SETLK 2182fe8fb19SBen Grasis used to establish shared (or read) locks 2192fe8fb19SBen Gras.Pq Dv F_RDLCK 2202fe8fb19SBen Grasor exclusive (or write) locks, 2212fe8fb19SBen Gras.Pq Dv F_WRLCK , 2222fe8fb19SBen Grasas well as remove either type of lock 2232fe8fb19SBen Gras.Pq Dv F_UNLCK . 2242fe8fb19SBen GrasIf a shared or exclusive lock cannot be set, 2252fe8fb19SBen Gras.Nm 2262fe8fb19SBen Grasreturns immediately with 2272fe8fb19SBen Gras.Er EAGAIN . 2282fe8fb19SBen Gras.It Dv F_SETLKW 2292fe8fb19SBen GrasThis command is the same as 2302fe8fb19SBen Gras.Dv F_SETLK 2312fe8fb19SBen Grasexcept that if a shared or exclusive lock is blocked by other locks, 2322fe8fb19SBen Grasthe process waits until the request can be satisfied. 2332fe8fb19SBen GrasIf a signal that is to be caught is received while 2342fe8fb19SBen Gras.Nm 2352fe8fb19SBen Grasis waiting for a region, the 2362fe8fb19SBen Gras.Nm 2372fe8fb19SBen Graswill be interrupted if the signal handler has not specified the 2382fe8fb19SBen Gras.Dv SA_RESTART 2392fe8fb19SBen Gras(see 2402fe8fb19SBen Gras.Xr sigaction 2 ) . 2412fe8fb19SBen Gras.El 2422fe8fb19SBen Gras.Pp 2432fe8fb19SBen GrasWhen a shared lock has been set on a segment of a file, 2442fe8fb19SBen Grasother processes can set shared locks on that segment 2452fe8fb19SBen Grasor a portion of it. 2462fe8fb19SBen GrasA shared lock prevents any other process from setting an exclusive 2472fe8fb19SBen Graslock on any portion of the protected area. 2482fe8fb19SBen GrasA request for a shared lock fails if the file descriptor was not 2492fe8fb19SBen Grasopened with read access. 2502fe8fb19SBen Gras.Pp 2512fe8fb19SBen GrasAn exclusive lock prevents any other process from setting a shared lock or 2522fe8fb19SBen Grasan exclusive lock on any portion of the protected area. 2532fe8fb19SBen GrasA request for an exclusive lock fails if the file was not 2542fe8fb19SBen Grasopened with write access. 2552fe8fb19SBen Gras.Pp 2562fe8fb19SBen GrasThe value of 2572fe8fb19SBen Gras.Fa l_whence 2582fe8fb19SBen Grasis 2592fe8fb19SBen Gras.Dv SEEK_SET , 2602fe8fb19SBen Gras.Dv SEEK_CUR , 2612fe8fb19SBen Grasor 2622fe8fb19SBen Gras.Dv SEEK_END 2632fe8fb19SBen Grasto indicate that the relative offset, 2642fe8fb19SBen Gras.Fa l_start 2652fe8fb19SBen Grasbytes, will be measured from the start of the file, 2662fe8fb19SBen Grascurrent position, or end of the file, respectively. 2672fe8fb19SBen GrasThe value of 2682fe8fb19SBen Gras.Fa l_len 2692fe8fb19SBen Grasis the number of consecutive bytes to be locked. 2702fe8fb19SBen GrasIf 2712fe8fb19SBen Gras.Fa l_len 2722fe8fb19SBen Grasis negative, the result is undefined. 2732fe8fb19SBen GrasThe 2742fe8fb19SBen Gras.Fa l_pid 2752fe8fb19SBen Grasfield is only used with 2762fe8fb19SBen Gras.Dv F_GETLK 2772fe8fb19SBen Grasto return the process ID of the process holding a blocking lock. 2782fe8fb19SBen GrasAfter a successful 2792fe8fb19SBen Gras.Dv F_GETLK 2802fe8fb19SBen Grasrequest, the value of 2812fe8fb19SBen Gras.Fa l_whence 2822fe8fb19SBen Grasis 2832fe8fb19SBen Gras.Dv SEEK_SET . 2842fe8fb19SBen Gras.Pp 2852fe8fb19SBen GrasLocks may start and extend beyond the current end of a file, 2862fe8fb19SBen Grasbut may not start or extend before the beginning of the file. 2872fe8fb19SBen GrasA lock is set to extend to the largest possible value of the 2882fe8fb19SBen Grasfile offset for that file if 2892fe8fb19SBen Gras.Fa l_len 2902fe8fb19SBen Grasis set to zero. 2912fe8fb19SBen GrasIf 2922fe8fb19SBen Gras.Fa l_whence 2932fe8fb19SBen Grasand 2942fe8fb19SBen Gras.Fa l_start 2952fe8fb19SBen Graspoint to the beginning of the file, and 2962fe8fb19SBen Gras.Fa l_len 2972fe8fb19SBen Grasis zero, the entire file is locked. 2982fe8fb19SBen GrasIf an application wishes only to do entire file locking, the 2992fe8fb19SBen Gras.Xr flock 2 3002fe8fb19SBen Grassystem call is much more efficient. 3012fe8fb19SBen Gras.Pp 3022fe8fb19SBen GrasThere is at most one type of lock set for each byte in the file. 3032fe8fb19SBen GrasBefore a successful return from an 3042fe8fb19SBen Gras.Dv F_SETLK 3052fe8fb19SBen Grasor an 3062fe8fb19SBen Gras.Dv F_SETLKW 3072fe8fb19SBen Grasrequest when the calling process has previously existing locks 3082fe8fb19SBen Grason bytes in the region specified by the request, 3092fe8fb19SBen Grasthe previous lock type for each byte in the specified 3102fe8fb19SBen Grasregion is replaced by the new lock type. 3112fe8fb19SBen GrasAs specified above under the descriptions 3122fe8fb19SBen Grasof shared locks and exclusive locks, an 3132fe8fb19SBen Gras.Dv F_SETLK 3142fe8fb19SBen Grasor an 3152fe8fb19SBen Gras.Dv F_SETLKW 3162fe8fb19SBen Grasrequest fails or blocks respectively when another process has existing 3172fe8fb19SBen Graslocks on bytes in the specified region and the type of any of those 3182fe8fb19SBen Graslocks conflicts with the type specified in the request. 319f14fb602SLionel Sambuc.Sh RETURN VALUES 320f14fb602SLionel SambucUpon successful completion, the value returned depends on 321f14fb602SLionel Sambuc.Fa cmd 322f14fb602SLionel Sambucas follows: 323f14fb602SLionel Sambuc.Bl -tag -width F_GETOWNX -offset indent 324f14fb602SLionel Sambuc.It Dv F_DUPFD 325f14fb602SLionel SambucA new file descriptor. 326f14fb602SLionel Sambuc.It Dv F_GETFD 327f14fb602SLionel SambucValue of flag (only the low-order bit is defined). 328f14fb602SLionel Sambuc.It Dv F_GETFL 329f14fb602SLionel SambucValue of flags. 330f14fb602SLionel Sambuc.It Dv F_GETOWN 331f14fb602SLionel SambucValue of file descriptor owner. 332f14fb602SLionel Sambuc.It Dv F_MAXFD 333f14fb602SLionel SambucValue of the highest file descriptor open by the process. 334f14fb602SLionel Sambuc.It other 335f14fb602SLionel SambucValue other than \-1. 336f14fb602SLionel Sambuc.El 337f14fb602SLionel Sambuc.Pp 338f14fb602SLionel SambucOtherwise, a value of \-1 is returned and 339f14fb602SLionel Sambuc.Va errno 340f14fb602SLionel Sambucis set to indicate the error. 3412fe8fb19SBen Gras.Sh COMPATIBILITY 3422fe8fb19SBen GrasThis interface follows the completely stupid semantics of 3432fe8fb19SBen Gras.At V 3442fe8fb19SBen Grasand 3452fe8fb19SBen Gras.St -p1003.1-88 3462fe8fb19SBen Grasthat require that all locks associated with a file for a given process are 3472fe8fb19SBen Grasremoved when \fIany\fP file descriptor for that file is closed by that process. 3482fe8fb19SBen GrasThis semantic means that applications must be aware of any files that 3492fe8fb19SBen Grasa subroutine library may access. 3502fe8fb19SBen GrasFor example if an application for updating the password file locks the 3512fe8fb19SBen Graspassword file database while making the update, and then calls 3522fe8fb19SBen Gras.Xr getpwnam 3 3532fe8fb19SBen Grasto retrieve a record, 3542fe8fb19SBen Grasthe lock will be lost because 3552fe8fb19SBen Gras.Xr getpwnam 3 3562fe8fb19SBen Grasopens, reads, and closes the password database. 3572fe8fb19SBen GrasThe database close will release all locks that the process has 3582fe8fb19SBen Grasassociated with the database, even if the library routine never 3592fe8fb19SBen Grasrequested a lock on the database. 3602fe8fb19SBen Gras.Pp 3612fe8fb19SBen GrasAnother minor semantic problem with this interface is that 3622fe8fb19SBen Graslocks are not inherited by a child process created using the 3632fe8fb19SBen Gras.Xr fork 2 3642fe8fb19SBen Grasfunction. 3652fe8fb19SBen GrasThe 3662fe8fb19SBen Gras.Xr flock 2 3672fe8fb19SBen Grasinterface has much more rational last close semantics and 3682fe8fb19SBen Grasallows locks to be inherited by child processes. 3692fe8fb19SBen GrasCalling 3702fe8fb19SBen Gras.Xr flock 2 3712fe8fb19SBen Grasis recommended for applications that want to ensure the integrity 3722fe8fb19SBen Grasof their locks when using library routines or wish to pass locks 3732fe8fb19SBen Grasto their children. 3742fe8fb19SBen GrasNote that 3752fe8fb19SBen Gras.Xr flock 2 3762fe8fb19SBen Grasand 3772fe8fb19SBen Gras.Nm 3782fe8fb19SBen Graslocks may be safely used concurrently. 3792fe8fb19SBen Gras.Pp 3802fe8fb19SBen GrasAll locks associated with a file for a given process are 3812fe8fb19SBen Grasremoved when the process terminates. 3822fe8fb19SBen Gras.Pp 3832fe8fb19SBen GrasA potential for deadlock occurs if a process controlling a locked region 3842fe8fb19SBen Grasis put to sleep by attempting to lock the locked region of another process. 3852fe8fb19SBen GrasThis implementation detects that sleeping until a locked region is unlocked 3862fe8fb19SBen Graswould cause a deadlock and fails with an 3872fe8fb19SBen Gras.Er EDEADLK 3882fe8fb19SBen Graserror. 3892fe8fb19SBen Gras.Sh ERRORS 3902fe8fb19SBen Gras.Fn fcntl 3912fe8fb19SBen Graswill fail if: 3922fe8fb19SBen Gras.Bl -tag -width Er 3932fe8fb19SBen Gras.It Bq Er EAGAIN 3942fe8fb19SBen GrasThe argument 3952fe8fb19SBen Gras.Fa arg 3962fe8fb19SBen Grasis 3972fe8fb19SBen Gras.Dv F_SETLK , 3982fe8fb19SBen Grasthe type of lock 3992fe8fb19SBen Gras.Pq Fa l_type 4002fe8fb19SBen Grasis a shared lock 4012fe8fb19SBen Gras.Pq Dv F_RDLCK 4022fe8fb19SBen Grasor exclusive lock 4032fe8fb19SBen Gras.Pq Dv F_WRLCK , 4042fe8fb19SBen Grasand the segment of a file to be locked is already 4052fe8fb19SBen Grasexclusive-locked by another process; 4062fe8fb19SBen Grasor the type is an exclusive lock and some portion of the 4072fe8fb19SBen Grassegment of a file to be locked is already shared-locked or 4082fe8fb19SBen Grasexclusive-locked by another process. 4092fe8fb19SBen Gras.It Bq Er EBADF 4102fe8fb19SBen Gras.Fa fildes 4112fe8fb19SBen Grasis not a valid open file descriptor. 4122fe8fb19SBen Gras.Pp 4132fe8fb19SBen GrasThe argument 4142fe8fb19SBen Gras.Fa cmd 4152fe8fb19SBen Grasis 4162fe8fb19SBen Gras.Dv F_SETLK 4172fe8fb19SBen Grasor 4182fe8fb19SBen Gras.Dv F_SETLKW , 4192fe8fb19SBen Grasthe type of lock 4202fe8fb19SBen Gras.Pq Fa l_type 4212fe8fb19SBen Grasis a shared lock 4222fe8fb19SBen Gras.Pq Dv F_RDLCK , 4232fe8fb19SBen Grasand 4242fe8fb19SBen Gras.Fa fildes 4252fe8fb19SBen Grasis not a valid file descriptor open for reading. 4262fe8fb19SBen Gras.Pp 4272fe8fb19SBen GrasThe argument 4282fe8fb19SBen Gras.Fa cmd 4292fe8fb19SBen Grasis 4302fe8fb19SBen Gras.Dv F_SETLK 4312fe8fb19SBen Grasor 4322fe8fb19SBen Gras.Dv F_SETLKW , 4332fe8fb19SBen Grasthe type of lock 4342fe8fb19SBen Gras.Pq Fa l_type 4352fe8fb19SBen Grasis an exclusive lock 4362fe8fb19SBen Gras.Pq Dv F_WRLCK , 4372fe8fb19SBen Grasand 4382fe8fb19SBen Gras.Fa fildes 4392fe8fb19SBen Grasis not a valid file descriptor open for writing. 4402fe8fb19SBen Gras.It Bq Er EDEADLK 4412fe8fb19SBen GrasThe argument 4422fe8fb19SBen Gras.Fa cmd 4432fe8fb19SBen Grasis 4442fe8fb19SBen Gras.Dv F_SETLKW , 4452fe8fb19SBen Grasand a deadlock condition was detected. 4462fe8fb19SBen Gras.It Bq Er EINTR 4472fe8fb19SBen GrasThe argument 4482fe8fb19SBen Gras.Fa cmd 4492fe8fb19SBen Grasis 4502fe8fb19SBen Gras.Dv F_SETLKW , 4512fe8fb19SBen Grasand the function was interrupted by a signal. 4522fe8fb19SBen Gras.It Bq Er EINVAL 4532fe8fb19SBen GrasThe argument 4542fe8fb19SBen Gras.Fa cmd 4552fe8fb19SBen Grasis invalid. 4562fe8fb19SBen Gras.Pp 4572fe8fb19SBen GrasThe argument 4582fe8fb19SBen Gras.Fa cmd 4592fe8fb19SBen Grasis 4602fe8fb19SBen Gras.Dv F_DUPFD 4612fe8fb19SBen Grasand 4622fe8fb19SBen Gras.Fa arg 4632fe8fb19SBen Grasis negative or greater than the maximum allowable number 4642fe8fb19SBen Gras(see 4652fe8fb19SBen Gras.Xr getdtablesize 3 ) . 4662fe8fb19SBen Gras.Pp 4672fe8fb19SBen GrasThe argument 4682fe8fb19SBen Gras.Fa cmd 4692fe8fb19SBen Grasis 4702fe8fb19SBen Gras.Dv F_GETLK , 4712fe8fb19SBen Gras.Dv F_SETLK , 4722fe8fb19SBen Grasor 4732fe8fb19SBen Gras.Dv F_SETLKW 4742fe8fb19SBen Grasand the data to which 4752fe8fb19SBen Gras.Fa arg 4762fe8fb19SBen Graspoints is not valid, or 4772fe8fb19SBen Gras.Fa fildes 4782fe8fb19SBen Grasrefers to a file that does not support locking. 4792fe8fb19SBen Gras.It Bq Er EMFILE 4802fe8fb19SBen GrasThe argument 4812fe8fb19SBen Gras.Fa cmd 4822fe8fb19SBen Grasis 4832fe8fb19SBen Gras.Dv F_DUPFD 4842fe8fb19SBen Grasand the maximum number of file descriptors permitted for the 4852fe8fb19SBen Grasprocess are already in use, 4862fe8fb19SBen Grasor no file descriptors greater than or equal to 4872fe8fb19SBen Gras.Fa arg 4882fe8fb19SBen Grasare available. 4892fe8fb19SBen Gras.It Bq Er ENFILE 4902fe8fb19SBen Gras.Fa cmd 4912fe8fb19SBen Grasis 4922fe8fb19SBen Gras.Dv F_DUPFD 4932fe8fb19SBen Grasand system-wide the maximum allowed number of file descriptors are 4942fe8fb19SBen Grascurrently open. 4952fe8fb19SBen Gras.It Bq Er ENOLCK 4962fe8fb19SBen GrasThe argument 4972fe8fb19SBen Gras.Fa cmd 4982fe8fb19SBen Grasis 4992fe8fb19SBen Gras.Dv F_SETLK 5002fe8fb19SBen Grasor 5012fe8fb19SBen Gras.Dv F_SETLKW , 5022fe8fb19SBen Grasand satisfying the lock or unlock request would result in the 5032fe8fb19SBen Grasnumber of locked regions in the system exceeding a system-imposed limit. 5042fe8fb19SBen Gras.It Bq Er ESRCH 5052fe8fb19SBen Gras.Fa cmd 5062fe8fb19SBen Grasis 5072fe8fb19SBen Gras.Dv F_SETOWN 5082fe8fb19SBen Grasand 5092fe8fb19SBen Grasthe process ID given as argument is not in use. 5102fe8fb19SBen Gras.El 5112fe8fb19SBen Gras.Sh SEE ALSO 5122fe8fb19SBen Gras.Xr close 2 , 5132fe8fb19SBen Gras.Xr execve 2 , 5142fe8fb19SBen Gras.Xr flock 2 , 5152fe8fb19SBen Gras.Xr open 2 , 5162fe8fb19SBen Gras.Xr sigaction 2 , 5172fe8fb19SBen Gras.Xr getdtablesize 3 5182fe8fb19SBen Gras.Sh STANDARDS 5192fe8fb19SBen GrasThe 5202fe8fb19SBen Gras.Fn fcntl 5212fe8fb19SBen Grasfunction conforms to 5222fe8fb19SBen Gras.St -p1003.1-90 . 5232fe8fb19SBen Gras.Sh HISTORY 5242fe8fb19SBen GrasThe 5252fe8fb19SBen Gras.Fn fcntl 5262fe8fb19SBen Grasfunction call appeared in 5272fe8fb19SBen Gras.Bx 4.2 . 528