1 /* Test for advisory record locking.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <https://www.gnu.org/licenses/>.
22 /* This is essentially the POSIX lockf. */
25 fcntl_lockf (int fd
, int cmd
, off_t len
)
37 if (fcntl (fd
, F_GETLK
, &fl
) < 0)
39 if (fl
.l_type
== F_UNLCK
|| fl
.l_pid
== getpid ())
46 return fcntl (fd
, F_SETLK
, &fl
);
49 return fcntl (fd
, F_SETLKW
, &fl
);
52 return fcntl (fd
, F_SETLK
, &fl
);
60 fcntl64_lockf (int fd
, int cmd
, off64_t len64
)
62 struct flock64 fl64
= {
71 fl64
.l_type
= F_RDLCK
;
72 if (fcntl64 (fd
, F_GETLK64
, &fl64
) < 0)
74 if (fl64
.l_type
== F_UNLCK
|| fl64
.l_pid
== getpid ())
80 fl64
.l_type
= F_UNLCK
;
81 return fcntl64 (fd
, F_SETLK64
, &fl64
);
84 return fcntl64 (fd
, F_SETLKW64
, &fl64
);
87 return fcntl64 (fd
, F_SETLK64
, &fl64
);
94 #define TST_LOCKFD "tst-fcntl-lock."
95 #define LOCKF fcntl_lockf
96 #define LOCKF64 fcntl64_lockf
97 #include "tst-lockf.c"