1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker /*
21*49cdfc7eSAndroid Build Coastguard Worker * NAME
22*49cdfc7eSAndroid Build Coastguard Worker * fcntl20.c
23*49cdfc7eSAndroid Build Coastguard Worker *
24*49cdfc7eSAndroid Build Coastguard Worker * DESCRIPTION
25*49cdfc7eSAndroid Build Coastguard Worker * Check locking of regions of a file
26*49cdfc7eSAndroid Build Coastguard Worker *
27*49cdfc7eSAndroid Build Coastguard Worker * ALGORITHM
28*49cdfc7eSAndroid Build Coastguard Worker * Test unlocking sections around a read lock
29*49cdfc7eSAndroid Build Coastguard Worker *
30*49cdfc7eSAndroid Build Coastguard Worker * USAGE
31*49cdfc7eSAndroid Build Coastguard Worker * fcntl20
32*49cdfc7eSAndroid Build Coastguard Worker *
33*49cdfc7eSAndroid Build Coastguard Worker * HISTORY
34*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 Ported by Wayne Boyer
35*49cdfc7eSAndroid Build Coastguard Worker *
36*49cdfc7eSAndroid Build Coastguard Worker * RESTRICTIONS
37*49cdfc7eSAndroid Build Coastguard Worker * None
38*49cdfc7eSAndroid Build Coastguard Worker */
39*49cdfc7eSAndroid Build Coastguard Worker
40*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
45*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
46*49cdfc7eSAndroid Build Coastguard Worker #include <inttypes.h>
47*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
48*49cdfc7eSAndroid Build Coastguard Worker #include "safe_macros.h"
49*49cdfc7eSAndroid Build Coastguard Worker
50*49cdfc7eSAndroid Build Coastguard Worker #define STRINGSIZE 27
51*49cdfc7eSAndroid Build Coastguard Worker #define STRING "abcdefghijklmnopqrstuvwxyz\n"
52*49cdfc7eSAndroid Build Coastguard Worker #define STOP 0xFFF0
53*49cdfc7eSAndroid Build Coastguard Worker
54*49cdfc7eSAndroid Build Coastguard Worker int parent_pipe[2];
55*49cdfc7eSAndroid Build Coastguard Worker int child_pipe[2];
56*49cdfc7eSAndroid Build Coastguard Worker int fd;
57*49cdfc7eSAndroid Build Coastguard Worker pid_t parent_pid, child_pid;
58*49cdfc7eSAndroid Build Coastguard Worker
59*49cdfc7eSAndroid Build Coastguard Worker void parent_put();
60*49cdfc7eSAndroid Build Coastguard Worker void parent_get();
61*49cdfc7eSAndroid Build Coastguard Worker void child_put();
62*49cdfc7eSAndroid Build Coastguard Worker void child_get();
63*49cdfc7eSAndroid Build Coastguard Worker void stop_child();
64*49cdfc7eSAndroid Build Coastguard Worker void compare_lock(struct flock *, short, short, int, int, pid_t);
65*49cdfc7eSAndroid Build Coastguard Worker void unlock_file();
66*49cdfc7eSAndroid Build Coastguard Worker void do_test(struct flock *, short, short, int, int);
67*49cdfc7eSAndroid Build Coastguard Worker void catch_child();
68*49cdfc7eSAndroid Build Coastguard Worker char *str_type();
69*49cdfc7eSAndroid Build Coastguard Worker int do_lock(int, short, short, int, int);
70*49cdfc7eSAndroid Build Coastguard Worker
71*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "fcntl20";
72*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
73*49cdfc7eSAndroid Build Coastguard Worker
74*49cdfc7eSAndroid Build Coastguard Worker void setup(void);
75*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void);
76*49cdfc7eSAndroid Build Coastguard Worker
77*49cdfc7eSAndroid Build Coastguard Worker int fail = 0;
78*49cdfc7eSAndroid Build Coastguard Worker
79*49cdfc7eSAndroid Build Coastguard Worker /*
80*49cdfc7eSAndroid Build Coastguard Worker * setup
81*49cdfc7eSAndroid Build Coastguard Worker * performs all ONE TIME setup for this test
82*49cdfc7eSAndroid Build Coastguard Worker */
setup(void)83*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
84*49cdfc7eSAndroid Build Coastguard Worker {
85*49cdfc7eSAndroid Build Coastguard Worker char *buf = STRING;
86*49cdfc7eSAndroid Build Coastguard Worker char template[PATH_MAX];
87*49cdfc7eSAndroid Build Coastguard Worker struct sigaction act;
88*49cdfc7eSAndroid Build Coastguard Worker
89*49cdfc7eSAndroid Build Coastguard Worker tst_sig(FORK, DEF_HANDLER, cleanup);
90*49cdfc7eSAndroid Build Coastguard Worker
91*49cdfc7eSAndroid Build Coastguard Worker umask(0);
92*49cdfc7eSAndroid Build Coastguard Worker
93*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
94*49cdfc7eSAndroid Build Coastguard Worker
95*49cdfc7eSAndroid Build Coastguard Worker parent_pid = getpid();
96*49cdfc7eSAndroid Build Coastguard Worker
97*49cdfc7eSAndroid Build Coastguard Worker SAFE_PIPE(NULL, parent_pipe);
98*49cdfc7eSAndroid Build Coastguard Worker SAFE_PIPE(NULL, child_pipe);
99*49cdfc7eSAndroid Build Coastguard Worker
100*49cdfc7eSAndroid Build Coastguard Worker tst_tmpdir();
101*49cdfc7eSAndroid Build Coastguard Worker
102*49cdfc7eSAndroid Build Coastguard Worker snprintf(template, PATH_MAX, "fcntl20XXXXXX");
103*49cdfc7eSAndroid Build Coastguard Worker
104*49cdfc7eSAndroid Build Coastguard Worker if ((fd = mkstemp(template)) == -1)
105*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL | TERRNO, "mkstemp failed");
106*49cdfc7eSAndroid Build Coastguard Worker
107*49cdfc7eSAndroid Build Coastguard Worker SAFE_WRITE(cleanup, SAFE_WRITE_ANY, fd, buf, STRINGSIZE);
108*49cdfc7eSAndroid Build Coastguard Worker
109*49cdfc7eSAndroid Build Coastguard Worker memset(&act, 0, sizeof(act));
110*49cdfc7eSAndroid Build Coastguard Worker act.sa_handler = catch_child;
111*49cdfc7eSAndroid Build Coastguard Worker sigemptyset(&act.sa_mask);
112*49cdfc7eSAndroid Build Coastguard Worker sigaddset(&act.sa_mask, SIGCHLD);
113*49cdfc7eSAndroid Build Coastguard Worker if (sigaction(SIGCHLD, &act, NULL) == -1)
114*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TFAIL | TERRNO, cleanup, "SIGCHLD signal setup failed");
115*49cdfc7eSAndroid Build Coastguard Worker }
116*49cdfc7eSAndroid Build Coastguard Worker
cleanup(void)117*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
118*49cdfc7eSAndroid Build Coastguard Worker {
119*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(NULL, fd);
120*49cdfc7eSAndroid Build Coastguard Worker
121*49cdfc7eSAndroid Build Coastguard Worker tst_rmdir();
122*49cdfc7eSAndroid Build Coastguard Worker
123*49cdfc7eSAndroid Build Coastguard Worker }
124*49cdfc7eSAndroid Build Coastguard Worker
do_child(void)125*49cdfc7eSAndroid Build Coastguard Worker void do_child(void)
126*49cdfc7eSAndroid Build Coastguard Worker {
127*49cdfc7eSAndroid Build Coastguard Worker struct flock fl;
128*49cdfc7eSAndroid Build Coastguard Worker
129*49cdfc7eSAndroid Build Coastguard Worker close(parent_pipe[1]);
130*49cdfc7eSAndroid Build Coastguard Worker close(child_pipe[0]);
131*49cdfc7eSAndroid Build Coastguard Worker while (1) {
132*49cdfc7eSAndroid Build Coastguard Worker child_get(&fl);
133*49cdfc7eSAndroid Build Coastguard Worker if (fcntl(fd, F_GETLK, &fl) < 0) {
134*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL | TERRNO, "fcntl on file failed");
135*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
136*49cdfc7eSAndroid Build Coastguard Worker }
137*49cdfc7eSAndroid Build Coastguard Worker child_put(&fl);
138*49cdfc7eSAndroid Build Coastguard Worker }
139*49cdfc7eSAndroid Build Coastguard Worker }
140*49cdfc7eSAndroid Build Coastguard Worker
do_lock(int cmd,short type,short whence,int start,int len)141*49cdfc7eSAndroid Build Coastguard Worker int do_lock(int cmd, short type, short whence, int start, int len)
142*49cdfc7eSAndroid Build Coastguard Worker {
143*49cdfc7eSAndroid Build Coastguard Worker struct flock fl;
144*49cdfc7eSAndroid Build Coastguard Worker
145*49cdfc7eSAndroid Build Coastguard Worker fl.l_type = type;
146*49cdfc7eSAndroid Build Coastguard Worker fl.l_whence = whence;
147*49cdfc7eSAndroid Build Coastguard Worker fl.l_start = start;
148*49cdfc7eSAndroid Build Coastguard Worker fl.l_len = len;
149*49cdfc7eSAndroid Build Coastguard Worker return (fcntl(fd, cmd, &fl));
150*49cdfc7eSAndroid Build Coastguard Worker }
151*49cdfc7eSAndroid Build Coastguard Worker
do_test(struct flock * fl,short type,short whence,int start,int len)152*49cdfc7eSAndroid Build Coastguard Worker void do_test(struct flock *fl, short type, short whence, int start, int len)
153*49cdfc7eSAndroid Build Coastguard Worker {
154*49cdfc7eSAndroid Build Coastguard Worker fl->l_type = type;
155*49cdfc7eSAndroid Build Coastguard Worker fl->l_whence = whence;
156*49cdfc7eSAndroid Build Coastguard Worker fl->l_start = start;
157*49cdfc7eSAndroid Build Coastguard Worker fl->l_len = len;
158*49cdfc7eSAndroid Build Coastguard Worker fl->l_pid = (short)0;
159*49cdfc7eSAndroid Build Coastguard Worker
160*49cdfc7eSAndroid Build Coastguard Worker parent_put(fl);
161*49cdfc7eSAndroid Build Coastguard Worker parent_get(fl);
162*49cdfc7eSAndroid Build Coastguard Worker }
163*49cdfc7eSAndroid Build Coastguard Worker
164*49cdfc7eSAndroid Build Coastguard Worker void
compare_lock(struct flock * fl,short type,short whence,int start,int len,pid_t pid)165*49cdfc7eSAndroid Build Coastguard Worker compare_lock(struct flock *fl, short type, short whence, int start, int len,
166*49cdfc7eSAndroid Build Coastguard Worker pid_t pid)
167*49cdfc7eSAndroid Build Coastguard Worker {
168*49cdfc7eSAndroid Build Coastguard Worker if (fl->l_type != type) {
169*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "lock type is wrong should be %s is %s",
170*49cdfc7eSAndroid Build Coastguard Worker str_type(type), str_type(fl->l_type));
171*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
172*49cdfc7eSAndroid Build Coastguard Worker }
173*49cdfc7eSAndroid Build Coastguard Worker
174*49cdfc7eSAndroid Build Coastguard Worker if (fl->l_whence != whence) {
175*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "lock whence is wrong should be %d is %d",
176*49cdfc7eSAndroid Build Coastguard Worker whence, fl->l_whence);
177*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
178*49cdfc7eSAndroid Build Coastguard Worker }
179*49cdfc7eSAndroid Build Coastguard Worker
180*49cdfc7eSAndroid Build Coastguard Worker if (fl->l_start != start) {
181*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "region starts in wrong place, should be"
182*49cdfc7eSAndroid Build Coastguard Worker "%d is %" PRId64, start, (int64_t) fl->l_start);
183*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
184*49cdfc7eSAndroid Build Coastguard Worker }
185*49cdfc7eSAndroid Build Coastguard Worker
186*49cdfc7eSAndroid Build Coastguard Worker if (fl->l_len != len) {
187*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL,
188*49cdfc7eSAndroid Build Coastguard Worker "region length is wrong, should be %d is %" PRId64,
189*49cdfc7eSAndroid Build Coastguard Worker len, (int64_t) fl->l_len);
190*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
191*49cdfc7eSAndroid Build Coastguard Worker }
192*49cdfc7eSAndroid Build Coastguard Worker
193*49cdfc7eSAndroid Build Coastguard Worker if (fl->l_pid != pid) {
194*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "locking pid is wrong, should be %d is %d",
195*49cdfc7eSAndroid Build Coastguard Worker pid, fl->l_pid);
196*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
197*49cdfc7eSAndroid Build Coastguard Worker }
198*49cdfc7eSAndroid Build Coastguard Worker }
199*49cdfc7eSAndroid Build Coastguard Worker
unlock_file(void)200*49cdfc7eSAndroid Build Coastguard Worker void unlock_file(void)
201*49cdfc7eSAndroid Build Coastguard Worker {
202*49cdfc7eSAndroid Build Coastguard Worker struct flock fl;
203*49cdfc7eSAndroid Build Coastguard Worker
204*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 0, 0) < 0) {
205*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d", errno);
206*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
207*49cdfc7eSAndroid Build Coastguard Worker }
208*49cdfc7eSAndroid Build Coastguard Worker do_test(&fl, F_WRLCK, 0, 0, 0);
209*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&fl, (short)F_UNLCK, (short)0, 0, 0, (pid_t) 0);
210*49cdfc7eSAndroid Build Coastguard Worker }
211*49cdfc7eSAndroid Build Coastguard Worker
str_type(int type)212*49cdfc7eSAndroid Build Coastguard Worker char *str_type(int type)
213*49cdfc7eSAndroid Build Coastguard Worker {
214*49cdfc7eSAndroid Build Coastguard Worker static char buf[20];
215*49cdfc7eSAndroid Build Coastguard Worker
216*49cdfc7eSAndroid Build Coastguard Worker switch (type) {
217*49cdfc7eSAndroid Build Coastguard Worker case F_RDLCK:
218*49cdfc7eSAndroid Build Coastguard Worker return ("F_RDLCK");
219*49cdfc7eSAndroid Build Coastguard Worker case F_WRLCK:
220*49cdfc7eSAndroid Build Coastguard Worker return ("F_WRLCK");
221*49cdfc7eSAndroid Build Coastguard Worker case F_UNLCK:
222*49cdfc7eSAndroid Build Coastguard Worker return ("F_UNLCK");
223*49cdfc7eSAndroid Build Coastguard Worker default:
224*49cdfc7eSAndroid Build Coastguard Worker sprintf(buf, "BAD VALUE: %d", type);
225*49cdfc7eSAndroid Build Coastguard Worker return (buf);
226*49cdfc7eSAndroid Build Coastguard Worker }
227*49cdfc7eSAndroid Build Coastguard Worker }
228*49cdfc7eSAndroid Build Coastguard Worker
parent_put(struct flock * l)229*49cdfc7eSAndroid Build Coastguard Worker void parent_put(struct flock *l)
230*49cdfc7eSAndroid Build Coastguard Worker {
231*49cdfc7eSAndroid Build Coastguard Worker if (write(parent_pipe[1], l, sizeof(*l)) != sizeof(*l)) {
232*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "couldn't send message to child");
233*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
234*49cdfc7eSAndroid Build Coastguard Worker }
235*49cdfc7eSAndroid Build Coastguard Worker }
236*49cdfc7eSAndroid Build Coastguard Worker
parent_get(struct flock * l)237*49cdfc7eSAndroid Build Coastguard Worker void parent_get(struct flock *l)
238*49cdfc7eSAndroid Build Coastguard Worker {
239*49cdfc7eSAndroid Build Coastguard Worker if (read(child_pipe[0], l, sizeof(*l)) != sizeof(*l)) {
240*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "couldn't get message from child");
241*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
242*49cdfc7eSAndroid Build Coastguard Worker }
243*49cdfc7eSAndroid Build Coastguard Worker }
244*49cdfc7eSAndroid Build Coastguard Worker
child_put(struct flock * l)245*49cdfc7eSAndroid Build Coastguard Worker void child_put(struct flock *l)
246*49cdfc7eSAndroid Build Coastguard Worker {
247*49cdfc7eSAndroid Build Coastguard Worker if (write(child_pipe[1], l, sizeof(*l)) != sizeof(*l)) {
248*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "couldn't send message to parent");
249*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
250*49cdfc7eSAndroid Build Coastguard Worker }
251*49cdfc7eSAndroid Build Coastguard Worker }
252*49cdfc7eSAndroid Build Coastguard Worker
child_get(struct flock * l)253*49cdfc7eSAndroid Build Coastguard Worker void child_get(struct flock *l)
254*49cdfc7eSAndroid Build Coastguard Worker {
255*49cdfc7eSAndroid Build Coastguard Worker if (read(parent_pipe[0], l, sizeof(*l)) != sizeof(*l)) {
256*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "couldn't get message from parent");
257*49cdfc7eSAndroid Build Coastguard Worker cleanup();
258*49cdfc7eSAndroid Build Coastguard Worker } else if (l->l_type == (short)STOP) {
259*49cdfc7eSAndroid Build Coastguard Worker exit(0);
260*49cdfc7eSAndroid Build Coastguard Worker }
261*49cdfc7eSAndroid Build Coastguard Worker }
262*49cdfc7eSAndroid Build Coastguard Worker
stop_child(void)263*49cdfc7eSAndroid Build Coastguard Worker void stop_child(void)
264*49cdfc7eSAndroid Build Coastguard Worker {
265*49cdfc7eSAndroid Build Coastguard Worker struct flock fl;
266*49cdfc7eSAndroid Build Coastguard Worker
267*49cdfc7eSAndroid Build Coastguard Worker signal(SIGCHLD, SIG_DFL);
268*49cdfc7eSAndroid Build Coastguard Worker fl.l_type = STOP;
269*49cdfc7eSAndroid Build Coastguard Worker parent_put(&fl);
270*49cdfc7eSAndroid Build Coastguard Worker wait(0);
271*49cdfc7eSAndroid Build Coastguard Worker }
272*49cdfc7eSAndroid Build Coastguard Worker
catch_child(void)273*49cdfc7eSAndroid Build Coastguard Worker void catch_child(void)
274*49cdfc7eSAndroid Build Coastguard Worker {
275*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "Unexpected death of child process");
276*49cdfc7eSAndroid Build Coastguard Worker cleanup();
277*49cdfc7eSAndroid Build Coastguard Worker }
278*49cdfc7eSAndroid Build Coastguard Worker
main(int ac,char ** av)279*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
280*49cdfc7eSAndroid Build Coastguard Worker {
281*49cdfc7eSAndroid Build Coastguard Worker struct flock tl;
282*49cdfc7eSAndroid Build Coastguard Worker
283*49cdfc7eSAndroid Build Coastguard Worker int lc;
284*49cdfc7eSAndroid Build Coastguard Worker
285*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(ac, av, NULL, NULL);
286*49cdfc7eSAndroid Build Coastguard Worker
287*49cdfc7eSAndroid Build Coastguard Worker setup(); /* global setup */
288*49cdfc7eSAndroid Build Coastguard Worker
289*49cdfc7eSAndroid Build Coastguard Worker /* Check for looping state if -i option is given */
290*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); lc++) {
291*49cdfc7eSAndroid Build Coastguard Worker /* reset tst_count in case we are looping */
292*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
293*49cdfc7eSAndroid Build Coastguard Worker
294*49cdfc7eSAndroid Build Coastguard Worker if ((child_pid = tst_fork()) == 0) /* child */
295*49cdfc7eSAndroid Build Coastguard Worker do_child();
296*49cdfc7eSAndroid Build Coastguard Worker
297*49cdfc7eSAndroid Build Coastguard Worker if (child_pid < 0) {
298*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "Fork failed");
299*49cdfc7eSAndroid Build Coastguard Worker cleanup();
300*49cdfc7eSAndroid Build Coastguard Worker }
301*49cdfc7eSAndroid Build Coastguard Worker
302*49cdfc7eSAndroid Build Coastguard Worker (void)close(parent_pipe[0]);
303*49cdfc7eSAndroid Build Coastguard Worker (void)close(child_pipe[1]);
304*49cdfc7eSAndroid Build Coastguard Worker
305*49cdfc7eSAndroid Build Coastguard Worker /* //block1: */
306*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Enter block 1");
307*49cdfc7eSAndroid Build Coastguard Worker /*
308*49cdfc7eSAndroid Build Coastguard Worker * Add a read lock to the middle of the file and unlock a
309*49cdfc7eSAndroid Build Coastguard Worker * section just before the lock
310*49cdfc7eSAndroid Build Coastguard Worker */
311*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) {
312*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
313*49cdfc7eSAndroid Build Coastguard Worker errno);
314*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
315*49cdfc7eSAndroid Build Coastguard Worker }
316*49cdfc7eSAndroid Build Coastguard Worker
317*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 5, 5) < 0) {
318*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
319*49cdfc7eSAndroid Build Coastguard Worker errno);
320*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
321*49cdfc7eSAndroid Build Coastguard Worker }
322*49cdfc7eSAndroid Build Coastguard Worker
323*49cdfc7eSAndroid Build Coastguard Worker /*
324*49cdfc7eSAndroid Build Coastguard Worker * Test read lock
325*49cdfc7eSAndroid Build Coastguard Worker */
326*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
327*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 5, parent_pid);
328*49cdfc7eSAndroid Build Coastguard Worker
329*49cdfc7eSAndroid Build Coastguard Worker /*
330*49cdfc7eSAndroid Build Coastguard Worker * Test that the rest of the file is unlocked
331*49cdfc7eSAndroid Build Coastguard Worker */
332*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 15, 0);
333*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, (pid_t) 0);
334*49cdfc7eSAndroid Build Coastguard Worker
335*49cdfc7eSAndroid Build Coastguard Worker /*
336*49cdfc7eSAndroid Build Coastguard Worker * remove all the locks set above
337*49cdfc7eSAndroid Build Coastguard Worker */
338*49cdfc7eSAndroid Build Coastguard Worker unlock_file();
339*49cdfc7eSAndroid Build Coastguard Worker
340*49cdfc7eSAndroid Build Coastguard Worker if (fail) {
341*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 1: FAILED");
342*49cdfc7eSAndroid Build Coastguard Worker } else {
343*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 1: PASSED");
344*49cdfc7eSAndroid Build Coastguard Worker }
345*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Exit block 1");
346*49cdfc7eSAndroid Build Coastguard Worker
347*49cdfc7eSAndroid Build Coastguard Worker /* //block2: */
348*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Enter block 2");
349*49cdfc7eSAndroid Build Coastguard Worker fail = 0;
350*49cdfc7eSAndroid Build Coastguard Worker /*
351*49cdfc7eSAndroid Build Coastguard Worker * Set a read lock in the middle and do an unlock that
352*49cdfc7eSAndroid Build Coastguard Worker * ends at the first byte of the read lock.
353*49cdfc7eSAndroid Build Coastguard Worker */
354*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) {
355*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
356*49cdfc7eSAndroid Build Coastguard Worker errno);
357*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
358*49cdfc7eSAndroid Build Coastguard Worker }
359*49cdfc7eSAndroid Build Coastguard Worker
360*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 5, 6) < 0) {
361*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
362*49cdfc7eSAndroid Build Coastguard Worker errno);
363*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
364*49cdfc7eSAndroid Build Coastguard Worker }
365*49cdfc7eSAndroid Build Coastguard Worker
366*49cdfc7eSAndroid Build Coastguard Worker /*
367*49cdfc7eSAndroid Build Coastguard Worker * Test read lock
368*49cdfc7eSAndroid Build Coastguard Worker */
369*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
370*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_RDLCK, (short)0, 11, 4, parent_pid);
371*49cdfc7eSAndroid Build Coastguard Worker
372*49cdfc7eSAndroid Build Coastguard Worker /*
373*49cdfc7eSAndroid Build Coastguard Worker * Test to make sure the rest of the file is unlocked
374*49cdfc7eSAndroid Build Coastguard Worker */
375*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 15, 0);
376*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, (pid_t) 0);
377*49cdfc7eSAndroid Build Coastguard Worker
378*49cdfc7eSAndroid Build Coastguard Worker /*
379*49cdfc7eSAndroid Build Coastguard Worker * remove all the locks set above
380*49cdfc7eSAndroid Build Coastguard Worker */
381*49cdfc7eSAndroid Build Coastguard Worker unlock_file();
382*49cdfc7eSAndroid Build Coastguard Worker
383*49cdfc7eSAndroid Build Coastguard Worker if (fail)
384*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 2: FAILED");
385*49cdfc7eSAndroid Build Coastguard Worker else
386*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 2: PASSED");
387*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Exit block 2");
388*49cdfc7eSAndroid Build Coastguard Worker
389*49cdfc7eSAndroid Build Coastguard Worker /* //block3: */
390*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Enter block 3");
391*49cdfc7eSAndroid Build Coastguard Worker fail = 0;
392*49cdfc7eSAndroid Build Coastguard Worker
393*49cdfc7eSAndroid Build Coastguard Worker /*
394*49cdfc7eSAndroid Build Coastguard Worker * Set a read lock on the middle of the file and do an
395*49cdfc7eSAndroid Build Coastguard Worker * unlock that overlaps the front of the read
396*49cdfc7eSAndroid Build Coastguard Worker */
397*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) {
398*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
399*49cdfc7eSAndroid Build Coastguard Worker errno);
400*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
401*49cdfc7eSAndroid Build Coastguard Worker }
402*49cdfc7eSAndroid Build Coastguard Worker
403*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 5, 8) < 0) {
404*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
405*49cdfc7eSAndroid Build Coastguard Worker errno);
406*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
407*49cdfc7eSAndroid Build Coastguard Worker }
408*49cdfc7eSAndroid Build Coastguard Worker
409*49cdfc7eSAndroid Build Coastguard Worker /*
410*49cdfc7eSAndroid Build Coastguard Worker * Test the read lock
411*49cdfc7eSAndroid Build Coastguard Worker */
412*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
413*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_RDLCK, (short)0, 13, 2, parent_pid);
414*49cdfc7eSAndroid Build Coastguard Worker
415*49cdfc7eSAndroid Build Coastguard Worker /*
416*49cdfc7eSAndroid Build Coastguard Worker * Test to make sure the rest of the file is unlocked
417*49cdfc7eSAndroid Build Coastguard Worker */
418*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 15, 0);
419*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, (pid_t) 0);
420*49cdfc7eSAndroid Build Coastguard Worker
421*49cdfc7eSAndroid Build Coastguard Worker /*
422*49cdfc7eSAndroid Build Coastguard Worker * remove all the locks set above
423*49cdfc7eSAndroid Build Coastguard Worker */
424*49cdfc7eSAndroid Build Coastguard Worker unlock_file();
425*49cdfc7eSAndroid Build Coastguard Worker
426*49cdfc7eSAndroid Build Coastguard Worker if (fail)
427*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 3: FAILED");
428*49cdfc7eSAndroid Build Coastguard Worker else
429*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 3: PASSED");
430*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Exit block 3");
431*49cdfc7eSAndroid Build Coastguard Worker
432*49cdfc7eSAndroid Build Coastguard Worker /* //block4: */
433*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Enter blcok 4");
434*49cdfc7eSAndroid Build Coastguard Worker fail = 0;
435*49cdfc7eSAndroid Build Coastguard Worker
436*49cdfc7eSAndroid Build Coastguard Worker /*
437*49cdfc7eSAndroid Build Coastguard Worker * Set a read lock in the middle of a file and unlock a
438*49cdfc7eSAndroid Build Coastguard Worker * section in the middle of it
439*49cdfc7eSAndroid Build Coastguard Worker */
440*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 10) < 0) {
441*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
442*49cdfc7eSAndroid Build Coastguard Worker errno);
443*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
444*49cdfc7eSAndroid Build Coastguard Worker }
445*49cdfc7eSAndroid Build Coastguard Worker
446*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 13, 5) < 0) {
447*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
448*49cdfc7eSAndroid Build Coastguard Worker errno);
449*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
450*49cdfc7eSAndroid Build Coastguard Worker }
451*49cdfc7eSAndroid Build Coastguard Worker
452*49cdfc7eSAndroid Build Coastguard Worker /*
453*49cdfc7eSAndroid Build Coastguard Worker * Test the first read lock
454*49cdfc7eSAndroid Build Coastguard Worker */
455*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
456*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 3, parent_pid);
457*49cdfc7eSAndroid Build Coastguard Worker
458*49cdfc7eSAndroid Build Coastguard Worker /*
459*49cdfc7eSAndroid Build Coastguard Worker * Test the second read lock
460*49cdfc7eSAndroid Build Coastguard Worker */
461*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 13, 0);
462*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_RDLCK, (short)0, 18, 2, parent_pid);
463*49cdfc7eSAndroid Build Coastguard Worker
464*49cdfc7eSAndroid Build Coastguard Worker /*
465*49cdfc7eSAndroid Build Coastguard Worker * Test to make sure the rest of the file is unlocked
466*49cdfc7eSAndroid Build Coastguard Worker */
467*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 20, 0);
468*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_UNLCK, (short)0, 20, 0, (pid_t) 0);
469*49cdfc7eSAndroid Build Coastguard Worker
470*49cdfc7eSAndroid Build Coastguard Worker /*
471*49cdfc7eSAndroid Build Coastguard Worker * remove all the locks set above
472*49cdfc7eSAndroid Build Coastguard Worker */
473*49cdfc7eSAndroid Build Coastguard Worker unlock_file();
474*49cdfc7eSAndroid Build Coastguard Worker
475*49cdfc7eSAndroid Build Coastguard Worker if (fail)
476*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 4: FAILED");
477*49cdfc7eSAndroid Build Coastguard Worker else
478*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 4: PASSED");
479*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Exit block 4");
480*49cdfc7eSAndroid Build Coastguard Worker
481*49cdfc7eSAndroid Build Coastguard Worker /* //block5: */
482*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Enter block 5");
483*49cdfc7eSAndroid Build Coastguard Worker fail = 0;
484*49cdfc7eSAndroid Build Coastguard Worker
485*49cdfc7eSAndroid Build Coastguard Worker /*
486*49cdfc7eSAndroid Build Coastguard Worker * Set a read lock in the middle of the file and do a
487*49cdfc7eSAndroid Build Coastguard Worker * unlock that overlaps the end
488*49cdfc7eSAndroid Build Coastguard Worker */
489*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) {
490*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
491*49cdfc7eSAndroid Build Coastguard Worker errno);
492*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
493*49cdfc7eSAndroid Build Coastguard Worker }
494*49cdfc7eSAndroid Build Coastguard Worker
495*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 13, 5) < 0) {
496*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
497*49cdfc7eSAndroid Build Coastguard Worker errno);
498*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
499*49cdfc7eSAndroid Build Coastguard Worker }
500*49cdfc7eSAndroid Build Coastguard Worker
501*49cdfc7eSAndroid Build Coastguard Worker /*
502*49cdfc7eSAndroid Build Coastguard Worker * Test the read lock
503*49cdfc7eSAndroid Build Coastguard Worker */
504*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
505*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 3, parent_pid);
506*49cdfc7eSAndroid Build Coastguard Worker
507*49cdfc7eSAndroid Build Coastguard Worker /*
508*49cdfc7eSAndroid Build Coastguard Worker * Test to make sure the rest of the file is unlocked
509*49cdfc7eSAndroid Build Coastguard Worker */
510*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 13, 0);
511*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_UNLCK, (short)0, 13, 0, (pid_t) 0);
512*49cdfc7eSAndroid Build Coastguard Worker
513*49cdfc7eSAndroid Build Coastguard Worker /*
514*49cdfc7eSAndroid Build Coastguard Worker * remove all the locks set above
515*49cdfc7eSAndroid Build Coastguard Worker */
516*49cdfc7eSAndroid Build Coastguard Worker unlock_file();
517*49cdfc7eSAndroid Build Coastguard Worker
518*49cdfc7eSAndroid Build Coastguard Worker if (fail)
519*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 5: FAILED");
520*49cdfc7eSAndroid Build Coastguard Worker else
521*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 5: PASSED");
522*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Exit block 5");
523*49cdfc7eSAndroid Build Coastguard Worker
524*49cdfc7eSAndroid Build Coastguard Worker /* //block6: */
525*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Enter block 6");
526*49cdfc7eSAndroid Build Coastguard Worker fail = 0;
527*49cdfc7eSAndroid Build Coastguard Worker
528*49cdfc7eSAndroid Build Coastguard Worker /*
529*49cdfc7eSAndroid Build Coastguard Worker * Set read lock in the middle of the file and do an unlock
530*49cdfc7eSAndroid Build Coastguard Worker * starting at the last byte of the read lock
531*49cdfc7eSAndroid Build Coastguard Worker */
532*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) {
533*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
534*49cdfc7eSAndroid Build Coastguard Worker errno);
535*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
536*49cdfc7eSAndroid Build Coastguard Worker }
537*49cdfc7eSAndroid Build Coastguard Worker
538*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 14, 5) < 0) {
539*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
540*49cdfc7eSAndroid Build Coastguard Worker errno);
541*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
542*49cdfc7eSAndroid Build Coastguard Worker }
543*49cdfc7eSAndroid Build Coastguard Worker
544*49cdfc7eSAndroid Build Coastguard Worker /*
545*49cdfc7eSAndroid Build Coastguard Worker * Test read lock
546*49cdfc7eSAndroid Build Coastguard Worker */
547*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 10, 0);
548*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 4, parent_pid);
549*49cdfc7eSAndroid Build Coastguard Worker
550*49cdfc7eSAndroid Build Coastguard Worker /*
551*49cdfc7eSAndroid Build Coastguard Worker * Test to make sure the end of the file is unlocked
552*49cdfc7eSAndroid Build Coastguard Worker */
553*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 14, 0);
554*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_UNLCK, (short)0, 14, 0, (pid_t) 0);
555*49cdfc7eSAndroid Build Coastguard Worker
556*49cdfc7eSAndroid Build Coastguard Worker /*
557*49cdfc7eSAndroid Build Coastguard Worker * remove all the locks set above
558*49cdfc7eSAndroid Build Coastguard Worker */
559*49cdfc7eSAndroid Build Coastguard Worker unlock_file();
560*49cdfc7eSAndroid Build Coastguard Worker
561*49cdfc7eSAndroid Build Coastguard Worker if (fail)
562*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 6: FAILED");
563*49cdfc7eSAndroid Build Coastguard Worker else
564*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 6: PASSED");
565*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Exit block 6");
566*49cdfc7eSAndroid Build Coastguard Worker
567*49cdfc7eSAndroid Build Coastguard Worker /* //block7: */
568*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Enter block 7");
569*49cdfc7eSAndroid Build Coastguard Worker fail = 0;
570*49cdfc7eSAndroid Build Coastguard Worker
571*49cdfc7eSAndroid Build Coastguard Worker /*
572*49cdfc7eSAndroid Build Coastguard Worker * Set a read lock at the middle of the file and do an
573*49cdfc7eSAndroid Build Coastguard Worker * unlock that starts at the byte past the end of the read
574*49cdfc7eSAndroid Build Coastguard Worker * lock
575*49cdfc7eSAndroid Build Coastguard Worker */
576*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 10, 5) < 0) {
577*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
578*49cdfc7eSAndroid Build Coastguard Worker errno);
579*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
580*49cdfc7eSAndroid Build Coastguard Worker }
581*49cdfc7eSAndroid Build Coastguard Worker
582*49cdfc7eSAndroid Build Coastguard Worker if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 16, 0) < 0) {
583*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "fcntl on file failed, errno =%d",
584*49cdfc7eSAndroid Build Coastguard Worker errno);
585*49cdfc7eSAndroid Build Coastguard Worker fail = 1;
586*49cdfc7eSAndroid Build Coastguard Worker }
587*49cdfc7eSAndroid Build Coastguard Worker
588*49cdfc7eSAndroid Build Coastguard Worker /*
589*49cdfc7eSAndroid Build Coastguard Worker * Test the read lock
590*49cdfc7eSAndroid Build Coastguard Worker */
591*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
592*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_RDLCK, (short)0, 10, 5, parent_pid);
593*49cdfc7eSAndroid Build Coastguard Worker
594*49cdfc7eSAndroid Build Coastguard Worker /*
595*49cdfc7eSAndroid Build Coastguard Worker * Test to make sure the rest of the file is unlocked
596*49cdfc7eSAndroid Build Coastguard Worker */
597*49cdfc7eSAndroid Build Coastguard Worker do_test(&tl, (short)F_WRLCK, (short)0, 16, 0);
598*49cdfc7eSAndroid Build Coastguard Worker compare_lock(&tl, (short)F_UNLCK, (short)0, 16, 0, (pid_t) 0);
599*49cdfc7eSAndroid Build Coastguard Worker
600*49cdfc7eSAndroid Build Coastguard Worker /*
601*49cdfc7eSAndroid Build Coastguard Worker * remove all the locks set above
602*49cdfc7eSAndroid Build Coastguard Worker */
603*49cdfc7eSAndroid Build Coastguard Worker unlock_file();
604*49cdfc7eSAndroid Build Coastguard Worker
605*49cdfc7eSAndroid Build Coastguard Worker if (fail)
606*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 7: FAILED");
607*49cdfc7eSAndroid Build Coastguard Worker else
608*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Test block 7: PASSED");
609*49cdfc7eSAndroid Build Coastguard Worker
610*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "Exit block 7");
611*49cdfc7eSAndroid Build Coastguard Worker
612*49cdfc7eSAndroid Build Coastguard Worker stop_child();
613*49cdfc7eSAndroid Build Coastguard Worker }
614*49cdfc7eSAndroid Build Coastguard Worker cleanup();
615*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
616*49cdfc7eSAndroid Build Coastguard Worker }
617